Is a timer delay accomplished with an interupt?
I'm a hobbyist trying to teach myself PBP by experimenting. My current project is replacing the lights in my 1973 Honda motorcycle with LEDs. When the brake light is activated, I'd like for the LEDs to pulse several times, with progressively longer intervals (100ms, 200ms, 300ms, etc) and then stay on until the brake is released. Many modern bikes do this as a deceleration warning to help avoid getting rear-ended.
In PBP, I basically run a continuous loop until a pin is high and then do a GOSUB to execute the flash loop, which takes about 2.5 seconds to complete. What I'd like to do is add some sort of timer to prevent the flash routine from executing more than once every 5-10 seconds. If I'm slowing down for a turn, I might depress and release the brake a few times. The flash loop should be executed only the first time I depressed the brake; subsequent activations should just keep the pin high until the brake is released. After x seconds, the next activation causes the flash sequence again.
From my readings, it looks like I'll need to use an interrupt to time how longer it's been since the brake was last activated. But I can't wrap my head around how to use them. Could someone please provide me with an example? Thank you!
The fair ( and simple ) solution ...
Hi ShortBus,
I Hope your bike is not a CB 250/350 ... no emergency brake signal needed ... cause no break at all !!! LOL ...
But ... I'd bet for a CB 750 ...
Being serious ... no interrupt needed :
a fair solution could be to use a 32.768 Khz Xtal for clock ... and let TMR 1 ( 16 Bits ) run quietly ...
that permits to use 12F683 and 16F628 as "simple" Pics.
How to ???
By polling the TMR 1 Overflow bit !!! (TMR1IF)
Let's have TMR 1 running freely : an overflow will occur after the delay you want "not to re-arm the flashing sequence" ... let it run ...
Let's use the brakes :
Overflow bit is set : engage the flashing sequence, and when releasing brakes... quit the flashing sequence and reset TMR 1 and it's Overflow bit ...
re use the brakes :
- before "Timeout" : overflow bit is clear ... continuous lighting !
- after "Timeout" : overflow Bit is set ... engage the flashing sequence !!!
32.768 Khz Xtal ??? just will need you to correct the programmed times by x 122 if using the Std "DEFINE Osc 4"
( Programmed PAUSE 10 will give 1220 ms instead of 10 ms ... so, if needed, use Pauseus :
Pauseus 1000 will give 122 ms instead of 1 ms ... )
This is just not to twist your brain on how to create " 1 - 10 seconds" delays ...
Alain ... Genuine Kawasaki H1 rider ... ha,ha,ha !!!