Shop OBEX P1 Docs P2 Docs Learn Events
led pwm cycle — Parallax Forums

led pwm cycle

Travis BestTravis Best Posts: 8
edited 2007-07-20 13:05 in General Discussion
could someone make me up a example for doing this pwm command using interrupt instead

PWM RB.0, 220, 1000

I know theirs some examples on the one pwm section but i just cant seem to get them to work

Thanks Again
Travis

Comments

  • JonnyMacJonnyMac Posts: 9,281
    edited 2007-07-20 00:15
    Here's a simple bit of code:

    ' =========================================================================
      INTERRUPT 10_000
    ' =========================================================================
    
      INC pwmTimer
      IF pwmTimer = 0 THEN                          ' time for new cycle?
        acc0 = level0                               ' reset accumulator(s)
        Led0 = 0                                    ' clear PWM output(s)
      ENDIF
    
      INC acc0                                      ' update accumulator?
      IF acc0 = 0 THEN                              ' on rollover
        led0 = 1                                    '   activate output
      ENDIF
    
      RETURNINT
    



    You need a pwm timer (for any number of outputs); when this rolls over then you start the new PWM cycle. At the start you'll transfer the level for the pin(s) to the accumulator(s) for that(those) pins; the outputs are cleared at the same time. Then you increment the accumulator(s); when there is a rollover detected then the output is activated. In use, the larger the value of "level", the sooner the output will be activated within the cycle and the brighter the LED will be.

    Keep in mind that when you're using an ISR, instructions like PAUSE, SEROUT, etc. (anything timing based) is affected.
  • Travis BestTravis Best Posts: 8
    edited 2007-07-20 13:05
    thanks I got it to work thanks for the help
Sign In or Register to comment.