PWMPAL erratic frequency.
Vitor
Posts: 13
I'm using PWMPAL to try to generate a frequency from 10 to 600 Hz.
Using this code. It may have to do with supplying the variable with a two byte value? (this was mentioned in one of my previous posts). If so, how is that done?
PpPin·········· PIN···· 0······················ ' PWM Pal Serial I/O
timeon······· VAR···· Word
Main:
timeon = 333
GOSUB Speed
END
Speed:
SEROUT 0, 6, [noparse][[/noparse]"!PWMM1", timeon, 0, timeon, 0]
SEROUT 0, 6, [noparse][[/noparse]"!PWMSS", %00010000]
RETURN
I get this type of results out of my scope.
When I go past timeon=>250 units, the results get very unpredictable. At the value shown above, 333, I should get a 60 Hz wave. The only way I get a 60 Hz wave is by using the example in the documentation.
SEROUT 0, 6, [noparse][[/noparse]"!PWMM1", $4D, $01, $4D, $01]
·
Using this code. It may have to do with supplying the variable with a two byte value? (this was mentioned in one of my previous posts). If so, how is that done?
PpPin·········· PIN···· 0······················ ' PWM Pal Serial I/O
timeon······· VAR···· Word
Main:
timeon = 333
GOSUB Speed
END
Speed:
SEROUT 0, 6, [noparse][[/noparse]"!PWMM1", timeon, 0, timeon, 0]
SEROUT 0, 6, [noparse][[/noparse]"!PWMSS", %00010000]
RETURN
I get this type of results out of my scope.
When I go past timeon=>250 units, the results get very unpredictable. At the value shown above, 333, I should get a 60 Hz wave. The only way I get a 60 Hz wave is by using the example in the documentation.
SEROUT 0, 6, [noparse][[/noparse]"!PWMM1", $4D, $01, $4D, $01]
·
Comments
Please note the following from the specifications...I didn't check in detail to see if that's where you're hitting problems, but you should be aware just in case.
Generate frequencies from 0.3 Hz to 20 kHz; duty cycle independent * * Duty cycle independence is not available for the entire range of output frequencies.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Your data is actually predictable, and to some degree you answered your own question. The example that uses ($4D, $01, $4D, $01) is actually correct... If you look at HIGH byte and LOW byte HEX numbers $14D is equal to 333 Decimal.· Since you are only sending a single byte value (Serial data is only sent in BYTES.)· A BYTE can only hold·a value ranging from 0 to 255.· In your data table, the value of 275 would overflow since it is greater than 255 and effectively be the same as·sending a value of 20 (275-255)· ... judging by your lookup table that should be about 1000 Hz.· Looking at some other numbers I suspect that one of the entries for 300 and 350 was incorrect.· I'm going to guess 350 is not correct, since 300-255 = 45 which is giving you a frequency "close" to your data table entry of "40".· 350 should be giving you a frequency close to 200Hz
What you really need to do is send both bytes in the form....
SEROUT 0, 6, [noparse][[/noparse]"!PWMM1", Timeon.LOWBYTE, Timeon.HIGHBYTE, Timeon.LOWBYTE, Timeon.HIGHBYTE]
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 1/16/2007 5:05:52 AM GMT
Can you point me somewhere to learn how the highbyte and lowbyte are used in the serial communication?
·
Maybe this will help somebody else.
In my original code I had this:·· SEROUT 0, 6, [noparse][[/noparse]"!PWMM1", timeon, 0, timeon, 0]
It should be this:··· SEROUT 0, 6, [noparse][[/noparse]"!PWMM1", timeon.BYTE0, timeon.BYTE1, timeon.BYTE0, timeon.BYTE1]
I use the same variable for time ON as time OFF because I need a 50% duty all the time. If you need different duty, create a variable for timeoff.
Thank you.