Shop OBEX P1 Docs P2 Docs Learn Events
led dimmering and PWM — Parallax Forums

led dimmering and PWM

labsmokelabsmoke Posts: 38
edited 2007-12-24 01:00 in Propeller 1
im trying to dimmer some leds, and i realise that the PWM is done with those internal counters FRQ, CRT and so on.

but im trying to find some "ready-to-go" code snippet for dimmering leds or just outputing PWM trains.

im not asking for someone to do my work but·you guys always seems to have something in you archives for rainy days.

i just need to dimmer a led with a code witch i can control setting a variable or something...


thanks anyway!

Comments

  • RaymanRayman Posts: 14,223
    edited 2007-12-23 13:37
    Try looking at the Counters Appnote:

    http://www.parallax.com/Portals/0/Downloads/appnt/prop/AN001-PropellerCountersv1.1.zip

    You can use the counter module to do this really nicely...
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-23 14:41
    I have menmtioned my PWM tutorial 4 times now in the last 24 hours... Maybe it will also be helpful to you.
    PWM is the most simple and trivial thing to do.
    You have to know SPIN of course, as with all other programming activities...
  • mosquito56mosquito56 Posts: 387
    edited 2007-12-23 15:09
    ··I am just about to start the servo motor control training. I realize the servos work the same as the leds in terms of·PWM codes but I just got to thinking.· If I hook an output thru the desilva current limiting resistor to a transistor to run a small d.c. motor. Does PWM work with a transistor? Will cutting the power on the motor on and off·harm the motor.· I can think of so many ways to control things analog if the transistor method will work.

    Days with the prop--7

    weeks reading the materials--3

    Completed leds, temperature probe, speaker, ir reciever(still trying to decipher remote codes)

    Mosquito

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mosquito: An animal which buzzes in your ear and never stops. He may byte you, he may nibble you, but you will know you were bit.

    ·A good engineer borrows from others, a great engineer steals everything outright!!
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-23 15:14
    I am just in the mood to elaborate on that...

    There are two possibilities:
    (A) You setup a timer in DUTY-mode to do it all itself. This is not in the tuturial, as it is not strict PWM, and is not useful for the servos smile.gif But it is very automatic, and will work with LEDs (I think..)
      CTRA := dutyMode + pinNumber
      FRQA := $7FFF_FFF/50*dutycycleInPercent 
    
    


    You change FRQA whenever appropriate..

    (B) You set-up a COG to supervise the PWM; lets call the routine PWM smile.gif
    (B1) PWM cycles in an endless loop synchronizing each 10 ms using WAITCNT
    (B2) It lights the LED
    (B3) It waits to the synctime + 10ms *dutyCycle
    (B4) it clears the LED

    6 lines of code, maybe 8
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-23 15:25
    @mosquito
    Don't confuse DC-motors and servos. Servos are connected to steady 5 to 6 Volts and CONTROLLED by a specific PWM signal I have explained this at least twice during the last days... o.k. I just can do it again:

    1 ms is left 1.5 ms is center 2 ms is right, all 10 ms (sorry: 20 ms , or course), over and over again.

    BTW - You can modify a servo by repacing its internal potentiometer by two constant 10k resistors and cutting away a small plastic nipple, so it can work as a motor. This is comprehensivly explained in the web, with pictures smile.gif

    You can also regulate the voltage to a DC motor through a transistor.
    However in that case you should use an integrating low pass filter at the transistor base.
    Your PWM (or even duty cycle signals) then will add up to a true analogue signal, using the trasistor as its inventors had anticipated smile.gif
    This is the poor man's DAC!

    Post Edited (deSilva) : 12/24/2007 3:54:25 PM GMT
  • mosquito56mosquito56 Posts: 387
    edited 2007-12-23 16:22
    Low pass filter thanks. Been so long since I was in school I have to re-read the electronics basics. When I was in school Nixon was president.

    Mosquito.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mosquito: An animal which buzzes in your ear and never stops. He may byte you, he may nibble you, but you will know you were bit.

    ·A good engineer borrows from others, a great engineer steals everything outright!!
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-23 16:29
    Funny that we use such kind of references for many thousend years...
    ".. And this taxing was first made when Cyrenius was governor of Syria..."

    ----
    Edit: Publius Sulpicius Quirinius was a brave soldier and able administrator BTW, someone like Eisenhower I should say, coming back to American presidents smile.gif

    Post Edited (deSilva) : 12/23/2007 10:52:12 PM GMT
  • Jason HicknerJason Hickner Posts: 21
    edited 2007-12-24 00:49
    the bs2 object on the object exchange contains pwm routines

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Jason
    www.pr0jects.com
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-24 01:00
    Yes...but as I said, there is really no need for routines.. It's 6 lines of code... or 3..
Sign In or Register to comment.