I need some help with one section of my code. It works perfectly; however, it is probably time sensitive when checking to see if the Signal Line is toggling (CheckForFlasherToggling). I used hippy's idea to watch that line and it works, but when/if the battery voltage changes it may not because the flasher module will change its rate. This is the same type unit in your car ... on the motorcycle and just a bi-metal switch inside.
I tried to use the COUNT command but could not get it to work. I may not know how to write the line ... LOL. I tried this thinking it would be simple and verified that the signal was pulsing at the Picaxe. I changed the time variable from 250 to 3000 with no success.
Counter = 0
Count 4, 750, Counter
If Counter <2 then Ready
Any help will be appreciated so that the code is not dependent on my one flasher module at a set working voltage. The only other issue is that I have to be able to watch the brake line to reset the timer, so as a practical matter I can't tie up the Picaxe for more than 1 second maximum.
I also made a prototype PCB and installed it on the motorcycle for testing ... it works great.
Thanks.
I tried to use the COUNT command but could not get it to work. I may not know how to write the line ... LOL. I tried this thinking it would be simple and verified that the signal was pulsing at the Picaxe. I changed the time variable from 250 to 3000 with no success.
Counter = 0
Count 4, 750, Counter
If Counter <2 then Ready
Any help will be appreciated so that the code is not dependent on my one flasher module at a set working voltage. The only other issue is that I have to be able to watch the brake line to reset the timer, so as a practical matter I can't tie up the Picaxe for more than 1 second maximum.
I also made a prototype PCB and installed it on the motorcycle for testing ... it works great.
Thanks.
Code:
#picaxe 08M
#rem
####################################################
# Automatic Turn Signal Cancellation Code: #
# #
# Code Version :1C #
# Date :August 2010 #
# PICAXE Type :8M #
# Firmware :> 9.2 #
# Editor Software :5.2.0 #
####################################################
#endrem
'############################################################################
'# MAIN ROUTINE #
'############################################################################
Symbol Signal = Pin3 '(pin4)
Symbol Brake = Pin4 '(pin3)
Symbol FlashEnable = 0 '(pin7)
Symbol Warning = 2 '(pin5)
Symbol Flash_ON_Timer = 25 'number of ~1/2 second cycles until indicator is auto cancelled
Symbol Debounce = 25 '20 ms @ 4MHz. This is the time to allow switch contacts to settle.
Symbol Last_Flashing_Signal = bit0
Symbol Counter = b1
Symbol Flash_Time = b2
SYMBOL Turn_Active = 1
SYMBOL TurnOff = 0
SYMBOL Brake_Applied = 0
Ready:
Do 'Wait for turn signal activation
Last_Flashing_Signal = 0
Flash_Time = 0
High FlashEnable 'Enable the flasher module
If Signal = Turn_Active then Start 'Signal switch has been activated
Pause Debounce
Loop UNTIL Signal = Turn_Active 'Loop until the Turn Signal has been activated.
Start:
CheckForFlasherToggling:
DO
Pause 350
If Brake = Brake_Applied then 'User has applied the brakes
Pause Debounce
Flash_Time=0
Endif
If Signal <> Last_Flashing_Signal Then ' Check to see if the Signal line is toggling
Last_Flashing_Signal = Last_Flashing_Signal ^ 1
End If
Inc Flash_Time 'Increment the Flash ON time counter
LOOP UNTIL Flash_Time = Flash_ON_Timer 'Continue to flash until the timer expires
Pause 100
Turn_Off:
Do
Low FlashEnable 'Turn off the signal module
For Counter = 0 to 5'15
If Signal = Turn_Active then 'Wait 20 seconds then send a warning signal
Pause 1000
Next
Tune 0, 4,($1A,$50,$1A,$50,$1A,$50) 'Sound warning
Else Goto ready ' User has reset the manual switch
Endif
Loop while Signal = Turn_Active 'Wait until switch is reset by user
Goto Ready