I'm sure most of you know about my project already, if not here's a brief summary:
I'm using a 28X1 to create a controller for automotive LED tail lights that use sequentially flashing signal lights and PWM controlled marker lights that go to full brightness when brakes are pressed.
Here's the code:
If you look at my schematic seen here:
http://www.picaxeforum.co.uk/showthread.php?t=8189
You'll see that the PWM is send to switching voltage regulators.. when brakes are applied this is completely separate of the picaxe.. the signal just goes straight to the switch on the regulators and overrides the PWM signal switching them on full and giving the LEDs 100% duty.
What I would like to do is be able to also control the brightness of the brakes by PWM so I can perfectly match them to stock brightness.. unfortunately I don't know of a way I can code this.
Using an interrupt command doesn't work because if the signals are flashing and the brakes are applied the signals would stop flashing... but obviously the brakes coming on needs to be instantaneous.. so I can't wait for execution of code...
...hmm Funny how sometimes writing something out sometimes give you your own solution.. I just thought about using a PWMout command under an init: header for the brakes using the other PWM pin and then use a opto isolator or a transistor to switch on the PWM signal to the switching pin of the regulator...
That may work well.. maybe not an opto isolator though.. because then I would need to wait for the LED in there to light up.. I want the fastest switching possible.. that's one advantage of LEDs.. the fast on time can save you 20m stopping distance at highway speeds compared to incandescent.. I don't want to negate that advantage.
So maybe that's the way I'll do it.. suggestions?
I'm using a 28X1 to create a controller for automotive LED tail lights that use sequentially flashing signal lights and PWM controlled marker lights that go to full brightness when brakes are pressed.
Here's the code:
Code:
main:
readadc 0,b0 'signal fade in time
readadc 1,b1 'signal fade out time
readadc 2,b2 'PWM duty cycle for marker lights
b3 = 4
w1 = b2 * b3
If pin4 = b4 Then 'No change in pin 4 (marker lights off)
If b4 = 1 Then 'Pin 4 is high
PwmDuty 1, w1 'Update duty only (adjust duty cycle if marker lights are on)
End If
Else 'Pin 4 changed
b4 = b4 ^ 1 'Update b4 to reflect pin 4
If b4 = 1 Then 'Pin 4 went high ...
PwmOut 1, 255, w1 'Start PWM
Else 'Pin 4 went low ...
PwmOut 1 off 'Turn off PWM
low portc 1
End If
End If
if pin0 = 1 and pin3 = 1 then flashhazard
if pin0 = 1 then flashleft
if pin3 = 1 then flashright
if pin0 = 0 and pin3 = 0 then main
goto main
flashleft:
high portc 7 'turn v.regs on for left side
high 0 'first bank of LEDs high
pause b0 'pause for fade in time
high 1
pause b0
high 2
pause b0
high 3
pause b0
high 4
pause b0
high 5
pause b0
high 6
pause b0
high 7
pause b1 'keep last bank high for fade out time
low 7 'last bank to turn on now goes off
pause b1 'pause for fade out time
low 6
pause b1
low 5
pause b1
low 4
pause b1
low 3
pause b1
low 2
pause b1
low 1
pause b1
low 0
pause b1
low portc 7 'turn left side regs off
goto main
flashright:
high portc 6 'turn v.regs on for right side
high 0 'first bank of LEDs high
pause b0 'pause for fade in time
high 1
pause b0
high 2
pause b0
high 3
pause b0
high 4
pause b0
high 5
pause b0
high 6
pause b0
high 7
pause b1 'keep last bank high for fade out time
low 7 'last bank to turn on now goes off
pause b1 'pause for fade out time
low 6
pause b1
low 5
pause b1
low 4
pause b1
low 3
pause b1
low 2
pause b1
low 1
pause b1
low 0
pause b1
low portc 6 'turn right side regs off
goto main
flashhazard:
high portc 7 'turn v.regs on for left side
high portc 6 'turn v.regs on for right side
high 0 'first bank of LEDs high
pause b0 'pause for fade in time
high 1
pause b0
high 2
pause b0
high 3
pause b0
high 4
pause b0
high 5
pause b0
high 6
pause b0
high 7
pause b1 'keep last bank high for fade out time
low 7 'last bank to turn on now goes off
pause b1 'pause for fade out time
low 6
pause b1
low 5
pause b1
low 4
pause b1
low 3
pause b1
low 2
pause b1
low 1
pause b1
low 0
pause b1
low portc 7 'turn left side regs off
low portc 6 'tuen right side regs off
goto main
http://www.picaxeforum.co.uk/showthread.php?t=8189
You'll see that the PWM is send to switching voltage regulators.. when brakes are applied this is completely separate of the picaxe.. the signal just goes straight to the switch on the regulators and overrides the PWM signal switching them on full and giving the LEDs 100% duty.
What I would like to do is be able to also control the brightness of the brakes by PWM so I can perfectly match them to stock brightness.. unfortunately I don't know of a way I can code this.
Using an interrupt command doesn't work because if the signals are flashing and the brakes are applied the signals would stop flashing... but obviously the brakes coming on needs to be instantaneous.. so I can't wait for execution of code...
...hmm Funny how sometimes writing something out sometimes give you your own solution.. I just thought about using a PWMout command under an init: header for the brakes using the other PWM pin and then use a opto isolator or a transistor to switch on the PWM signal to the switching pin of the regulator...
That may work well.. maybe not an opto isolator though.. because then I would need to wait for the LED in there to light up.. I want the fastest switching possible.. that's one advantage of LEDs.. the fast on time can save you 20m stopping distance at highway speeds compared to incandescent.. I don't want to negate that advantage.
So maybe that's the way I'll do it.. suggestions?