Thanks for responding Art, the program that I am running goes into several long pauses, PAUSE 20000 for example. You have a simple solution that normally would work, I can insert a button on MCLR instead of having it permanently tied to 5v, but this is an automotive application and I need a reduced signal from the brake switch to restart the program. Here is my program, it is an attempt at a simple cruise control for an automobile. Please forgive my old style way of programming, but the program works, at least on the bench, I just need a way of restarting the program even when it is in those long pauses. Portb.0 can be changed so that it can be an interrupt, but I don't know how to code it. This simple program counts pulses from the Vehicle Speed Sensor, (VSS), stores it in B1, then counts again and stores the result in B2. Then it compares the two signals and makes adjustment to the throttle via a stepper motor. Any further help or ideals would very much be appreciated.
' Cruise Control Program
' Microcontroller used: 16F88
' 20 MHZ CRYSTAL fuse at hs
' Porta.0 - Porta.3 are stepper motor outputs
' Portb.0 is signal in from VSS (Vehicle Speed Sensor)
' Portb.1 is the signal to engage when 5v is applied. 10K tied to ground
' Portb.2 is tied to the brake switch. 10 k tied to ground
' Fine tuning may need to the "ti" and "ts" variables for vehicle,
' they also may need to be a "byte" instead of "word".
:START
clear
C var byte
ti var byte
ts var word
B1 var word
B2 VAR word
TRISa = %00000000
trisb = %00000111
portb = 0
porta = 0
c = 0
ti = 50 ' this is the pause between motor turns
ts = 2500 ' this changes how long of a count in milliseconds
INIT:
IF PORTb.1 = 1 THEN COUNTER1 'Press sw1 to engage
pause 100
GOTO INIT
COUNTER1:
if portb.0 = 1 then counter1 ' Wait till end of pulse
count portb.0 ,ts, B1 ' read pulses from vss for ? second
pause 500
CRUISE:
if portb.0 = 1 then Cruise ' Wait till end of pulse
count portb.0 ,ts, B2 ' get a second reading and store in B2
IF PORTb.2 = 1 THEN porta = 0:goto START ' BRAKE LIGHT SIGNAL, kill NOW
IF B2 > B1 THEN REVR
IF B2 < B1 THEN FORW
pause 20000 ' If B2 = B1 then pause
goto cruise
FORW:
PORTa = %00000011
PAUSe ti
PORTa = %00000110
PAUSE ti
PORTa = %00001100
PAUSE ti
PORTa = %00001001
PAUSE ti
C = C + 1
if c = 10 then portb = 0:goto start ' if no response after 10 sweeps then restart
pause 20000
GOTO cruise
REVR:
PORTa = %00001001
PAUSE ti
PORTa = %00001100
PAUSE ti
PORTa = %00000110
PAUSE ti
PORTa = %00000011
PAUSE ti
C = C - 1
pause 20000
GOTO cruise




Bookmarks