Shop OBEX P1 Docs P2 Docs Learn Events
16khz PWM — Parallax Forums

16khz PWM

LightfootLightfoot Posts: 228
edited 2007-06-19 03:32 in General Discussion
Will this work for a 16khz PWM circuit (not sure if I have the math right).

62.5

'50% duty cycle: code is not accurate either

here:

ra.0 = 1
pauseus 31
ra.0 = 0
pauseus 31

goto here:

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Comments

  • JonnyMacJonnyMac Posts: 8,942
    edited 2007-06-19 01:56
    If you just want this to run in a loop you might try:

    Main:
      DO
        TOGGLE RA.0
        PAUSEUS 31.2
      LOOP
    



    When using PAUSEUS inline as above you can have fractional values -- that might get you a bit closer. And by using toggle the duty cycle should be dead-on 50% (your program will have a slightly longer off-time due to the jump after the second PAUSEUS).
  • BeanBean Posts: 8,129
    edited 2007-06-19 02:07
    Actually "RA.0 = ~RA.0" will execute much faster than "TOGGLE RA.0" since it doesn't set the pin to output everytime.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • JonnyMacJonnyMac Posts: 8,942
    edited 2007-06-19 03:32
    Good point -- let me modify the [noparse][[/noparse]simple] listing:

    Main:
      OUTPUT RA.0
      DO
        RA.0 = ~RA.0
        PAUSEUS 31.2        ' <-- fine tune to adjust frequency
      LOOP
    
Sign In or Register to comment.