Shop OBEX P1 Docs P2 Docs Learn Events
PWMPAL erratic frequency. — Parallax Forums

PWMPAL erratic frequency.

VitorVitor Posts: 13
edited 2007-01-17 17:25 in BASIC Stamp
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.
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, [noparse][[/noparse]"!PWMM1", $4D, $01, $4D, $01]
·
131 x 446 - 3K

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-01-16 03:20
    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 SchwabeBeau Schwabe Posts: 6,560
    edited 2007-01-16 04:53
    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, [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
  • VitorVitor Posts: 13
    edited 2007-01-16 06:00
    Thank you Beau.
    Can you point me somewhere to learn how the highbyte and lowbyte are used in the serial communication?
    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-16 06:04
    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.
  • VitorVitor Posts: 13
    edited 2007-01-17 17:25
    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, [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.
Sign In or Register to comment.