![]() |
Forum Index : Microcontroller and PC projects : PWM command
Author | Message | ||||
Lee3 Regular Member ![]() Joined: 17/09/2014 Location: AustraliaPosts: 57 |
I've been experimenting/fiddling with my micromite now I have a working serial terminal.... I could use the PWM command at the command line without a prob. ie PWM 1,250,50 would run an LED at pin 4 at 50% if I entered the same in the editor and saved/run - nothing would happen. I'm not really sure what is happening there, I assume I'm missing something.... Lee |
||||
cosmic frog Senior Member ![]() Joined: 09/02/2012 Location: United KingdomPosts: 300 |
Setpin 4,dout |
||||
hitsware Guru ![]() Joined: 23/11/2012 Location: United StatesPosts: 535 |
Not needed. PWM command does that automatically. @ Lee I've found that sometimes a PWM STOP is needed before a PWM command will take effect. |
||||
cosmic frog Senior Member ![]() Joined: 09/02/2012 Location: United KingdomPosts: 300 |
Well it won't work on mine without it! ![]() Dave. |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3272 |
Something else must be going on here. The PWM output keeps running when a program ends and it does not need a SETPIN or a PWM STOP command. I tried entering PWM 1,250,50 in the editor, saved it, then entered RUN and the output kept running. Geoff Geoff Graham - http://geoffg.net |
||||
hitsware Guru ![]() Joined: 23/11/2012 Location: United StatesPosts: 535 |
> The PWM output keeps running when a program ends It quits when you switch to edit ... > and it does not need a SETPIN Right > or a PWM STOP command. If you try to change frequency while running then AT TIMES ! It will stutter or not output UNLESS ! A PWM STOP is issued before the change ... What would be nice is if the MicroMite PWMs would run as smooth as the TONEs on the MaxiMite ...... I.E. capable of a smooth sweep without extraneous noise Not bad though ! |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3272 |
> It quits when you switch to edit ... Yes, that is because the editor needs all the memory in the chip. AT TIMES ! It will stutter or not output UNLESS ! A PWM STOP is issued before the change ... That should not happen and it works fine for me. A change in frequency will never be as smooth as the TONE command which uses a frequency synthesiser in software whereas the PWM uses the MX150's hardware. Geoff Geoff Graham - http://geoffg.net |
||||
hitsware Guru ![]() Joined: 23/11/2012 Location: United StatesPosts: 535 |
@ bottom add : DATA 8,6,9,6, 2,4,3,4 If you take the PWM 1, STOP out of the 5th line down you'll hear what I mean ( I think ) It is an intermittent thing and the PWMs are pretty busy ... |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6224 |
Try putting a pause instead of the PWM stop. It is easier for others to test your code if you paste it as text instead of the image. With TeraTerm, you use ALT-C instead of the usual ctrl_C to copy. Jim VK7JH MMedit |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2927 |
Wow, I never ever knew that. Thanks Jim for that useful bit of info! ![]() |
||||
cosmic frog Senior Member ![]() Joined: 09/02/2012 Location: United KingdomPosts: 300 |
Ok, just tried this again to make sure. In the editor I have- PWM 1,950,50 I get nothing from the speaker and nothing on my multimeter. If I have this in the editor- Setpin 4,dout PWM 1,950,50 I can hear a beeeep sound and the multimeter shows around 1.5volts Even if I type in PWM 1,950,50 directly and not in the editor I get nothing. I am using a Pic32mx170 and the latest firmware. Dave. |
||||
Lee3 Regular Member ![]() Joined: 17/09/2014 Location: AustraliaPosts: 57 |
I just tested a small program: for t=100 to 1 step -1 PWM 1,250,t pause 500 next t does nothing - except flash a cursor on screen for 50s if I prefix that code with setpin 4,dout it works, giving a gradually fading LED over 50s.... This is with Pic32MX170, 4.5D firmware. |
||||
cosmic frog Senior Member ![]() Joined: 09/02/2012 Location: United KingdomPosts: 300 |
Ok, I've just tried again with a Pic32mx150 and it works as it should. So this maybe a bug in the mx170 firmware. Dave. |
||||
hitsware Guru ![]() Joined: 23/11/2012 Location: United StatesPosts: 535 |
> Try putting a pause instead of the PWM stop. That would be musically awkward . > It is easier for others to test your code > if you paste it as text instead of the image. Yea. I forgot I was on XP ![]() |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9502 |
Houston, we have a bug. (agreeing with Dave, in that there is a bug with PWM in the 170 firmware perhaps?) Smoke makes things work. When the smoke gets out, it stops! |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6224 |
That would be musically awkward . > It is easier for others to test your code > if you paste it as text instead of the image. Yea. I forgot I was on XP ![]() The PWM STOP command (like all commands) takes time to execute. I suggest that a short PAUSE will be worth trying. Start with a few milliseconds and gradually reduce the time between tests. The PWM will continue in the background during the pause so the only effect of the pause will be to slow the rate of change down. I could try it myself but it is your ears that need to hear the changes, my ears are not worth using when it comes to "music" Jim VK7JH MMedit |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6224 |
I have found time to test the code but only on a MX170 chip. Because of the apparent but with the PWM on the MX170, I have had to run the code with the PWM STOP commands rem'ed out. So far I have not seen any problems on the CRO but this is something that probably needs audio to listen to. There are plenty of PAUSE statements already so I think the problem may be elsewhere. I know you gave the circuit you are using but I cannot find the post. This is the code as I used it. I changed mid: to middle: because MID is too close to a keyword for my liking. OPEN "com1:3000" AS #1
DIM c(29), m(3) FOR x = 0 TO 29 : READ c(x) : NEXT x FOR x = 0 TO 3 : READ m(x) : NEXT x SETPIN 4, DOUT SETPIN 26, DOUT DO FOR x = 0 TO 29 'PWM 1, STOP PWM 1, 44*c(x), 1, 1 FOR y = 0 TO 3 r = INT(RND*3)+1 : f = c(x)*m(y)*5.5 IF y = 2 THEN PRINT #1, CHR$(85); ON r GOSUB bass, middle, high NEXT y NEXT x LOOP bass: PWM 2, f, 33,76 PAUSE 200 'PWM 2, STOP PAUSE 50 RETURN middle: PWM 2, 2*f, 10,20 PAUSE 125 'PWM 2, STOP PAUSE 125 RETURN high: PWM 2, 4*f, 5,30 PAUSE 50 'PWM 2, STOP PAUSE 200 RETURN DATA 5,6,9,5, 5,6,9,9, 5,6,9,5, 4,9,5,5 DATA 4,5,9,9, 4,5,9,9, 4,5,9,9, 4,9 DATA 8,6,9,6, 2,4,3,4 I will try it on a MX150 chip later. Jim VK7JH MMedit |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3272 |
In the editor I have- PWM 1,950,50 I get nothing from the speaker and nothing on my multimeter. If I have this in the editor- Setpin 4,dout PWM 1,950,50 I can hear a beeeep sound and the multimeter shows around 1.5volts Even if I type in PWM 1,950,50 directly and not in the editor I get nothing. I am using a Pic32mx170 and the latest firmware. Dave. Thanks Dave, While the MX150 and MX170 chips should be the same (except for memory) it appears that this is not so. It seems that the MX170 PWM hardware on the chip requires that the PWM output pin be specifically set to an output. Until I get out another version the workaround (on the MX170 chips only) is to add a SETPIN for each PWM output. Geoff Geoff Graham - http://geoffg.net |
||||
hitsware Guru ![]() Joined: 23/11/2012 Location: United StatesPosts: 535 |
> So far I have not seen any problems on the CRO but this > is something that probably needs audio to listen to. For sure. Listening to these things is infinitely more reveiling than a scope . Here's a simpler snippet that shows the problem nicely. ( Listen with the 'PWM 1, stop' reminded vs active ) Do PWM 1, stop n=Int(Rnd*400)+100 PWM 1,n,50,50 Pause 400 Loop > I know you gave the circuit you are using but I cannot > find the post. All PWM pins tied to a common point ( audio out ) through 15 k Ohm COM pin tied to the same point through 3.3 k Ohm The values are not important at all. Just the ratios. ( The COM pin gives only a short burst that needs amplitude to be perceptably loud enough ) > I changed mid: to middle: because MID is too close to a > keyword for my liking. Good idea .... I'll follow suit . |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |