Help with LED driver fade on/off


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2007
    Posts
    6

    Default Help with LED driver fade on/off

    ** Sorry, I first posted in the PicBasic, but the post did not show up. Also, this forum has more activity.

    I am fading on/off a Luxeon LED driver using a 12F683.
    I need it to fade on, stay on for 1 second, then fade off and stay off for 1 second, and then repeats the cycle.

    I can't figure out how to use PWM, so I used HPWM. After it fades on, it will then shuts off and then fades on couple more times. It then fades off and then does some random things.

    Please point out what I am doing wrong and add/remove anything neccesary.
    I am not a programmer so I am learning as I go. I have looked at all the help and examples I could find, but still can't figure it out.

    Here's the code:

    @ DEVICE PIC12F683,MCLR_OFF ' Disable external MCLR
    TRISIO = %00000000
    'ansel = %0000001
    LED var gpio.2
    TurnOn var byte
    x var word
    Counter var word

    TurnOn=%0

    led=!turnon

    ProgramLoop:
    gosub dimon
    led=turnon
    pause 1000
    gosub dimoff
    led=!turnon
    pause 1000

    goto programloop:



    DimOff:
    led=!turnon
    For x = 0 to 1023
    Hpwm 0, x, 5000
    led=!turnon
    pause 50
    next x
    Hpwm 0, 0, 0
    led=!turnon
    return

    DimOn:
    for x = 1023 to 0 step -1
    Hpwm 0, x, 5000
    led=!turnon
    pause 50
    next x
    Hpwm 0, 0, 0
    led=turnon
    return

  2. #2
    Join Date
    Jun 2006
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Here is how I handled a fade in on my LED clock I did recently. You would just need to reverse it to fade out again and add a pause at the end to leave it on for 1 second. Pulse is just a variable that turns various bits of portb on or off.

    Code:
    x = 0
            y = 20
            for i = 1 to 10
                portb = pulse
                pause x     ' turn on LED
                portb = 0
                pause y     ' turn off LED
                y = y - 2 
                x = x + 2   
            next 
            portb = pulse   ' turn LED on for final time
    You can see I'm simply extending the time the LED stays on and reducing the time the LED goes off until it just stays on. You could change the starting values of x and y at the beggining and also change the increment/decrement values from 2 to something else.

    Here's a link to the clock on youtube so you can see how much fade there is -

    Regards

    Tony

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. Free Project - 245 LED Display
    By T.Jackson in forum Code Examples
    Replies: 221
    Last Post: - 16th August 2009, 04:59
  3. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  4. Alegro 6276 LED driver?
    By [email protected] in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd August 2007, 00:25
  5. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts