PDA

View Full Version : PWMPAL erratic frequency.



Vitor
01-16-2007, 09:38 AM
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, ["!PWMM1", timeon, 0, timeon, 0]
SEROUT 0, 6, ["!PWMSS", %00010000]
RETURN

I get this type of results out of my scope.
http://forums.parallax.com/attachment.php?attachmentid=74116
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, ["!PWMM1", $4D, $01, $4D, $01]
ˇ

Chris Savage
01-16-2007, 10:20 AM
Vitor,

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

Beau Schwabe (Parallax)
01-16-2007, 11:53 AM
Vitor,
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, ["!PWMM1", Timeon.LOWBYTE, Timeon.HIGHBYTE, Timeon.LOWBYTE, Timeon.HIGHBYTE]


ˇ

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Post Edited (Beau Schwabe (Parallax)) : 1/16/2007 5:05:52 AM GMT

Vitor
01-16-2007, 01:00 PM
Thank you Beau.
Can you point me somewhere to learn how the highbyte and lowbyte are used in the serial communication?
ˇ

Mike Green
01-16-2007, 01:04 PM
Look at the PBasic manual for the definition and the PWMPAL documentation for examples of its use. Most serial communication is 8 bits at a time. The highbyte and lowbyte "suffixes" allow you to easily take the two halves of a 16 bit value for (among other things) for transmission via a serial port one byte at a time.

Vitor
01-18-2007, 12:25 AM
Got it after a few times of reading the same info.

Maybe this will help somebody else.

In my original code I had this:ˇˇ SEROUT 0, 6, ["!PWMM1", timeon, 0, timeon, 0]

It should be this:ˇˇˇ SEROUT 0, 6, ["!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.