Pwmpal
vzhzjt
Posts: 5
Anyone,
I have been working with the Basic Stamp 2 for a little over 2 months, and found out the primative PWM command doesn't run in the "Background".
When one specifies a certain duty cycle for a given duration, the Stamp waits at the instruction for the entire duration and then some.
I purchased the PWMPAL, which has its own processor, and communicates with the Stamp serially.· One is lead to believe you can specify the duty cycle and duration, and have this signal run in the "Background", which it does.· But ...·I am updating the PWM duty cycle around every 80 ms, with a new duty cycle, and the signal goes "LOW" for up to 20 ms during every update.
Has anyone else experience this problem ... and is there a fix?
Thanks for the help.
I have been working with the Basic Stamp 2 for a little over 2 months, and found out the primative PWM command doesn't run in the "Background".
When one specifies a certain duty cycle for a given duration, the Stamp waits at the instruction for the entire duration and then some.
I purchased the PWMPAL, which has its own processor, and communicates with the Stamp serially.· One is lead to believe you can specify the duty cycle and duration, and have this signal run in the "Background", which it does.· But ...·I am updating the PWM duty cycle around every 80 ms, with a new duty cycle, and the signal goes "LOW" for up to 20 ms during every update.
Has anyone else experience this problem ... and is there a fix?
Thanks for the help.
Comments
·· What baud rate are you using to communicate with the PWMPAL?· Try using some different (faster) baud rates and see if the delay changes.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I have included the code of interest below.
'Drive PWMPAL with U_On_Time and U_Off_Time
······· HIGH 1
······· SEROUT· PpPin, PpBaud, [noparse][[/noparse]"!PWMM1", U_On_Time.BYTE0, U_On_Time.BYTE1,
······················ U_Off_Time.BYTE0, U_Off_Time.BYTE1]
······· SEROUT· PpPin, PpBaud, [noparse][[/noparse]"!PWMSS", 00010000]
······· LOW 1
······· RETURN
I toggled pin 1 to determine if it was during the update to the PWMPAL that the "Flat-Line" was happening, and it is.
The baud rate is PpBaud is set to 9600.
I have attached a copy of the scope trace from showing the "Flat-Line".
Any help would be greatly appreiciated.
Jim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Is it impossible to use the PWMPAL for "gliding" changes in duty cycle? Or is there a smart workaround for this?
My code is:
MotorNum = 4
SEROUT PpPin, PpBaud, [noparse][[/noparse]"!PWMSP", %00000000]
SEROUT PpPin, PpBaud, [noparse][[/noparse]"!PWMSS", %10000000]
FOR brtness = 1 TO 899
tOn = brtness
tOff = 900 - brtness
SEROUT PpPin, PpBaud, [noparse][[/noparse]"!PWMM", (48 + MotorNum),
tOn.BYTE0, tOn.BYTE1,
tOff.BYTE0, tOff.BYTE1]
PAUSE 100
NEXT
Edit:
By setting the phase to high, I got rid of the "flash" - seems the cycle starts all over when setting new times, therefore the flash.
But... By adding a "pause 2000" to study the result, I noticed that every other timing makes the LED flicker more than others - thus appearing dimmer. Any ideas to this? Maybe I should select a frequency that divides perfectly with the PWMPALs timings?
Edit:
And, by lowering the pause to 10, the fade is smooth up to almost bright, then the LED starts to flash on/off a couple of times, whereafter it "jumps" up about 10% in brightness to settle there.
This is weird...
Post Edited (aeklo) : 1/3/2006 10:46:50 PM GMT
I did increase the baud rate to the maximum of 38.4K, and this reduced the duration of the "Flat-Line" by the same factor (4).·So, the duration of the "Flat-Line" went from 20ms to 5ms.
I am levitating an object driving a FET with the PWM signal, and think this "Flat-Line" will cause the object to fall.
I need to check and see if I should have used the % symbol as well.
Thanks.