Shop OBEX P1 Docs P2 Docs Learn Events
Pwmpal — Parallax Forums

Pwmpal

vzhzjtvzhzjt Posts: 5
edited 2006-01-04 14:16 in BASIC Stamp
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.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-12-22 19:38
    Hello,

    ·· 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 WilliamsJon Williams Posts: 6,491
    edited 2005-12-22 21:31
    You do indeed have control over duty cycle as you specify the high and low portions of the waveform. What I'm thinking happens (I didn't write the PWMPAL code, and most of our engineering staff is on vacation) is that the new times get loaded into the counters at the start of the next cycle -- does this appear to be happening? And it is always helpful to provide your code in these situations; we might see something that we can point to as a possible cause.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • vzhzjtvzhzjt Posts: 5
    edited 2006-01-03 17:12
    Joe,

    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-01-03 20:33
    What happens when you use a higher baud rate?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Mike GreenMike Green Posts: 23,101
    edited 2006-01-03 20:37
    Did you mean to say "00010000" or "%00010000" in the second SEROUT?
  • aekloaeklo Posts: 20
    edited 2006-01-03 22:06
    I have the very same problem trying to fade a LED on/off. The LED seems to flash bright each time the new timings are sent to the PWMPAL.
    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
  • vzhzjtvzhzjt Posts: 5
    edited 2006-01-04 14:16
    Chris,

    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.
Sign In or Register to comment.