Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:50 25 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PWM out, need some examples, not working for me.

Author Message
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5078
Posted: 08:00am 14 May 2024
Copy link to clipboard 
Print this post

Hi.

Tryin to use pins GP3 and GP5 for PWM outputs, getting some errors.


setpin GP3, PWM


PWM GP3,1000,50


Gives a "Pin not set for PWM" error.
I tried PWM 5,1000,50 ( the actual pin ) and get the same error.

I'm sure I'm missing the obvious, but I pretty sure its right according to the manual. Maybe a example code would get me sorted?

Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 08:18am 14 May 2024
Copy link to clipboard 
Print this post

  Quote  GP3 and GP5 for PWM outputs, getting some errors

GP3 is PWM channel 1B so a placeholder needs to be left for 1A with a coma.
setpin GP3, PWM
PWM 1,1000,, 50

And for GP5, channel 2B
setpin GP5, PWM
PWM 2,1000,, 50

The "PicoMite Hardware" chapter shows which channels are on each pin
Edited 2024-05-14 18:27 by phil99
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5078
Posted: 08:25am 14 May 2024
Copy link to clipboard 
Print this post

OK?

In the manual its got "PWM channel, frequency, [dutyA]" with an example of "PWM 1, 50,(position as a percentage...."

I added the extra comma anyway, but got the same error message.

Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6783
Posted: 08:26am 14 May 2024
Copy link to clipboard 
Print this post

You need to specify the PWM number and channel for a pin. e,g,
SETPIN GP3, PWM1B
and
SETPIN GP5, PWM2B

You can then use them as

PWM 1, 1000,,50
and
PWM 2, 1000,,25

Note that you have to specify a position for the A channel even if you aren't using it.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 08:30am 14 May 2024
Copy link to clipboard 
Print this post

Just tested this:-
> setpin GP3, PWM
> PWM 1,1000,, 50
> setpin GP5, PWM
> PWM 2,1000,, 50
>

With no errors and it delivers 1kHz @ 50% on each.

PS Use the channel number not pin number or GP number in the PWM command.
Edited 2024-05-14 18:42 by phil99
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6783
Posted: 08:38am 14 May 2024
Copy link to clipboard 
Print this post

Yeah - I just checked my Aquarium Controller listing.
SETPIN GP3, PWM
is valid, you don't need to specify the PWM port now. However, you do need to use a placeholder if you are using Port B without Port A.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5078
Posted: 08:56am 14 May 2024
Copy link to clipboard 
Print this post

So am I correct is saying the manual is wrong?

"PWM channel, frequency, [dutyA]"

I think I'm getting somewhere. I was using

> setpin GP3, PWM
> PWM GP3,1000,, 50
> setpin GP5, PWM
> PWM GP5,1000,, 50



Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 09:46am 14 May 2024
Copy link to clipboard 
Print this post

I think the placement of the comma within the suqare brackets is misleading.

PWM channel, frequency,[dutyA] , [dutyB][,phase][,defer]


Jim
VK7JH
MMedit   MMBasic Help
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 09:47am 14 May 2024
Copy link to clipboard 
Print this post

The manual is correct yet difficult to understand. Many have trouble with this.

"PWM channel, frequency, [dutyA] [, dutyB]"

Channel number is not GP number. The "PicoMite Hardware" chapter shows which channels are on each pin. GP3 is channel 1B so you need:-
PWM 1,1000,, 50 not PWM GP3,1000,, 50

Both the coma after frequency and before dutyB are mandatory if using a B channel.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4223
Posted: 10:21am 14 May 2024
Copy link to clipboard 
Print this post

  Gizmo said  So am I correct is saying the manual is wrong?

"PWM channel, frequency, [dutyA]"

I think I'm getting somewhere. I was using

> setpin GP3, PWM
> PWM GP3,1000,, 50
> setpin GP5, PWM
> PWM GP5,1000,, 50



Glenn



> setpin GP3, PWM       'this assigns GP3 to PWM1. PWM1A=GP2, PWM1B=GP3
> PWM 1,1000,, 50       'start PWM1 at 1000Hz, with no setting for PWM1A (GP2)
                       'and 50% for PWM1B (GP3)
> setpin GP5, PWM       'assign GP5 to PWM2. PWM2A=GP4, PWM2B=GP5
> PWM 2,1000,, 50       'start PWM2 at 1000Hz, with no setting for PWM2A (GP4)
                       'and 50% for PWM2B (GP5)

Edited 2024-05-14 20:21 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5078
Posted: 11:28am 14 May 2024
Copy link to clipboard 
Print this post

  phil99 said  The manual is correct yet difficult to understand. Many have trouble with this.


Yep, bet they do.

Another trap I discovered, I was starting to get random PWM Pin not set errors again. Scratched my head, then realised the command PWM 1, OFF command I was using to stop the PWM signal means you need to assign the PWM pin again. So instead using PWM 1,1000,,0
I guess thats the best approach.

This PWM is one area that could definitely benefit from example code.

Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4223
Posted: 12:19pm 14 May 2024
Copy link to clipboard 
Print this post

Hi Glenn,

I admit the user manual does not explain it in detail (I was surprized, since the manual is quite complete on other items).
2 weeks ago I heard a <sigh> from Peter that he was to update the manual (with Geoff ?). Maybe this suggestion from you comes in time for the 5.09.00 manual update.

I am glad ti works for you now,

Volhout
PicomiteVGA PETSCII ROBOTS
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 01:34am 15 May 2024
Copy link to clipboard 
Print this post

@Gizmo, from the perspective of someone new to PicoMite PWM would the suggested changes below be helpful?

  Quote  PWM channel, frequency,[dutyA][,dutyB][,phase][,defer]
There are 8 separate PWM frequencies available (channels 0 to 7) and up to 16
outputs with individually controlled duty cycle. See "PicoMite Hardware" p9.
You can output on either PWMnA or PWMnB or both for each channel -
no restriction though if using B only note the leading coma ",dutyB".
Eg. SETPIN GP15, PWM ' GP15 = PWM 7B
PWM 7, 1000, , 40 ' 1kHz @ 40%

Duty cycles are specified as a percentage and you can use a negative value to
invert the output (-100.0 <= duty <=100.0).
Minimum frequency = (cpuspeed + 1) / (2^24) Hz. Maximum speed is
OPTION CPUSPEED/4. At very fast speeds the duty cycles will be
increasingly limited.
Phase is a parameter that causes the waveforms to be centred such that a wave
form with a shorter duty cycle starts and ends equal times from a longer one.
Use 1 to enable this mode and 0 (or omit) to run as normal
The parameter "deferredstart" when set to 1 configures the PWM channels as
above but does not start the output running. They can the be
started uing the PWM SYNC command. This can be used to avoid any undesirable
startup artefacts.  
The PWM command is also capable of driving servos as follows:
PWM 1,50,(position_as_a_percentage * 0.05 + 5)

PWM SYNC s0[,s1][,s2][,s3][,s4][,s5][,s6][,s7]
This initiates the PWM on channels where a deferred start was defined or just
syncs existing running channels. However, the power comes in the ability to
offset the channels one to another (defined as a percentage of the time period
as per the duty cycle - can be a float)
You can use an offset of -1 to omit a channel from the synch

PWM channel, OFF
Stop output on 'channel'
To pause a channel set ',duty' to 0 

Edited 2024-05-15 11:48 by phil99
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3800
Posted: 06:46am 15 May 2024
Copy link to clipboard 
Print this post

Just a note: "coma" should be "comma".

John
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 09:22am 28 Jun 2024
Copy link to clipboard 
Print this post

Today I went into same troubles Gizmo had.
I needed only PWM5A but not B, so configured PIN GP10, but did not care to configure pin GP11 and got "Pin not set for PWM" error

So It might be other new users will fail too.

Best place for user manual improvement would be near PWM command I think. If it was noted it must be configured both pins, or not used channel`s duty cycle ommited with empty space, It would saved me some stupid half of an hour looking through manual :)
I just wrote 50 for both A and B channels and then went into cyclic retries to configure GP10 "good way" :D
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024