Shop OBEX P1 Docs P2 Docs Learn Events
PWM sounds simple in theory, but... — Parallax Forums

PWM sounds simple in theory, but...

MarkSMarkS Posts: 342
edited 2008-01-01 11:47 in Propeller 1
I was trying to dim an LED. It sounds simple. You keep it on, I'm assuming in a loop where you keep outputing a '1', for a certain amount of time and then do the same thing, but turn it off for a certain amount of time and repeat ad nauseum. I couldn't get it to work though. I'm running the PLL at x16, so 80_000_000 = 1 second. That info really does not help too much. If I wanted to dim an LED by x%, what do I do?

Comments

  • MacGeek117MacGeek117 Posts: 747
    edited 2007-12-29 16:56
    There is a simple PWM object in the Obex (Object Exchange) Look for it in Motor Control.
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.jameco.com
    ·
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-29 17:39
    There is also a most comprehensive wiki article
    propeller.wikispaces.com/PWM
  • MarkSMarkS Posts: 342
    edited 2008-01-01 01:29
    deSilva said...
    There is also a most comprehensive wiki article
    propeller.wikispaces.com/PWM

    Thanks!
  • MarkSMarkS Posts: 342
    edited 2008-01-01 03:27
    OK, I finally got to try your code (dim_cycle3), but it doesn't work. Is there a trick to it?
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-01 09:53
    Perhaps a typo smile.gif
    I don't know, I'll check ..

    ----
    Edit: Yes TWO typos... generally happens when "improving" text without re-checking :-(
    Called "Vers 4.0" now
    I also added an example in the main routine: Ramp-Up/Ramp down
    PUB main | dutyCycle, someStack[noparse][[/noparse]20]
      COGNEW(dim_try3(30, @dutyCycle), @someStack)
       
      REPEAT
        REPEAT WHILE ++dutyCycle <100
          WAITCNT(CNT+CLKFREQ/100)
        REPEAT WHILE --dutyCycle >0
          WAITCNT(CNT+CLKFREQ/100)
    

    Post Edited (deSilva) : 1/1/2008 11:28:12 AM GMT
  • bulkheadbulkhead Posts: 405
    edited 2008-01-01 10:44
    Is it this line:

    onePercentTicks := CLKFREQ/100      ' 100µs = 1% '
    



    where the 100 should be a 10_000?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm new to the propeller!
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-01 11:28
    Yes smile.gif
    As you say bulkhead! Improvement to the worse ...
    Luckily the comment shows the issue.
    I also had a misspelled variable
  • DroneDrone Posts: 433
    edited 2008-01-01 11:42
    In the third line:
    onePercentTick > onePercentTicks
    


    right?

    BTW - Happy New Year - David
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-01 11:47
    :-( Sure! I wanted to improve the "readability" smile.gif
Sign In or Register to comment.