PDA

View Full Version : LED fade without PWM command



Nick
- 9th March 2005, 00:22
I’m trying to get a LED to fade in and out with variable speed

and without using PWM command.

I intend to use a 8 pin PIC (12F629)

Where can I find some code sample to accomplice a smooth,

100 % fade in and out with variable speed set by a variable?

Any help will be appreciated.

mister_e
- 9th March 2005, 13:10
dowload this code i do many weeks ago based on TIMER1 (http://www.picbasic.co.uk/forum/attachment.php?attachmentid=179)

PWM, SERIN/SEROUT are really often ask here. If u do a search, you'll probably found a bit less hits than the quantity of thread ;)

Nick
- 9th March 2005, 23:34
Thanks Steve.

I'm using PBP 2.45a to compile your code
and I'm getting an error:
"59: [235] Opcode Expected Instead of '_config'
Does the code compile for you?

Nick
- 11th March 2005, 01:38
I tried the suggested PWM built in PBP and it works pretty good.
Here is the code I used to get a nice ramp up and down even with
high brightness LEDs which are harder to control linearly.


led VAR PORTB.5
steps VAR WORD
cycles CON 2

' Change limits for steps to play around 0 or 100% brightness
' Change steps for different duration of ramps
' Works good even with high brightness LEDs, harder to control linearly


fade:

up:
For steps=0 TO 255
PWM led,steps,cycles
Next
High led

Pause 2500

down:
For steps=255 TO 1 STEP -1
PWM led,steps,cycles
Next
Low led

Pause 2500


GoTo fade

End

mister_e
- 11th March 2005, 18:49
Thanks Steve.

I'm using PBP 2.45a to compile your code
and I'm getting an error:
"59: [235] Opcode Expected Instead of '_config'
Does the code compile for you?

Nick this is caused by the @config line... simply remark this line.. This line set the configuration fuses for your PIC. If you're using PM instead of MPASM this will gives you this error message. See the FAQ about configuration fuses. Really handy stuff.

Nick
- 12th March 2005, 04:07
I made the changes and everything works fine
Thanks again Steve.

ollim13
- 29th June 2005, 19:19
Hallo I´m new in programming, is it possible to get the circuit for the programm from Nick.
Thank you.
Olli

Dwayne
- 29th June 2005, 20:56
Hello Olli,



is it possible to get the circuit for the programm from Nick.


All you have to do , is connect a diode to the pin in which you are working with... connect up your +/- voltage, and presto. No circuitry per se is required...

Dwayne