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: AustraliaPosts: 5078 |
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: AustraliaPosts: 2135 |
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: AustraliaPosts: 5078 |
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 KingdomPosts: 6783 |
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: AustraliaPosts: 2135 |
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 KingdomPosts: 6783 |
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: AustraliaPosts: 5078 |
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: AustraliaPosts: 6098 |
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: AustraliaPosts: 2135 |
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: NetherlandsPosts: 4223 |
> 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: AustraliaPosts: 5078 |
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: NetherlandsPosts: 4223 |
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: AustraliaPosts: 2135 |
@Gizmo, from the perspective of someone new to PicoMite PWM would the suggested changes below be helpful? Edited 2024-05-15 11:48 by phil99 |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3800 |
Just a note: "coma" should be "comma". John |
||||
electricat Senior Member Joined: 30/11/2020 Location: LithuaniaPosts: 161 |
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 |