PDA

View Full Version : Help with LED driver fade on/off



dfort
- 22nd July 2009, 19:27
** 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

thirsty
- 25th July 2009, 00:39
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.


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 - http://www.youtube.com/watch?v=qEjSHqqNrzI

Regards

Tony