Hello All,
For those that are interested, I'm reporting my progress on a homemade Cruise for cars and motorcycles. After mounting a stepper motor and linking it mechanically to my throttle, I tapped into my vehicles VSS, (Vehicle Speed Sensor). I also tapped into the brake light switch which provides an emergency shut-off for the unit, as well as having a good ol' on/off switch mounted inside.
The theory of operation is fairly simple, the unit counts pulses continuously from the VSS. When a momentary switch is pushed it moves on a gets a second count from the VSS and from that point on it just continues to read pulses, comparing it to the first reading, and make adjustments to the throttle. People probably wonder why I don't just but an aftermarket cruise unit but I was just interested in creating a true feedback system that I could experiment with.
Well after playing with some of the timing elements in the program, I got the unit to work but, with a few problems. The first problem is that it is slow to respond to hills and overcompensates trying to climb them, often engaging passing gear. On flat open roads its performance is very good.
Another problem is that it apparently cannot read the VSS pulses past about 45 mph. I've tried increasing and decreasing the timing in my COUNT statements, but to no avail. I have also tried the divide reading by 2 and /10 method, but still no luck. It may be necessary to mount a magnetic pick-up unit to the axle or CV joint. I am just an amateur programmer with no knowledge of assembly, C or other languages, but I need a system that continuously reads the pulses, without the delay of a count statement, and continuously makes adjustments. I am not selfish with my code, (I'm not going to sell these units), so if you have an old vehicle to play with you can play with my code. Be warned that safety is the number one factor and any tests should be far from city traffic. Also, I am not responsible for any mishaps, THIS IS ALL JUST TEST CODE, USE AT YOUR OWN RISK. For those that wish to weigh in on better code, your input will be greatly valued. Thanks in advance.
' 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 needed to the "ti" and "ts" variables for vehicle,
' ts may need to be a "byte" instead of "word". Depending on pulses per second
START:
define osc 20
clear
C1 VAR word
I VAR WORD
ti var byte
ts var word
B1 var word
B2 VAR word
TRISa = %00000000
trisb = %00000111
portb = 0
porta = 0
C1 = 5000 ' var. controls pause if b2=b1 (0 - 65000)
ti = 200 ' stepper motor speed (20 - 200)
ts = 5000 ' this changes how long of a count in milliseconds (100-2500)
INIT:
IF PORTb.1 = 1 THEN COUNTER1 'Press sw1 to engage
pause 100
GOTO INIT
COUNTER1:
IF TS < 1000 THEN TS = 1000
count portb.0 ,ts, B1 ' read pulses from vss for ? second
PORTB.3 = 1
pause 100
CRUISE:
count portb.0 ,ts, B2 ' get a second reading and store in B2
PORTB.4 = 1
IF PORTb.2 = 1 THEN porta = 0:goto START ' BRAKE LIGHT SIGNAL, kill NOW
IF B2 < B1 - 3 THEN FORW
IF B2 > B1 + 3 THEN REVR
Lock:
FOR I = 1 TO c1
IF PORTb.2 = 1 THEN porta = 0:goto START
NEXT I
goto cruise
FORW:
PORTa = %00000011
PAUSe ti
PORTa = %00000110
PAUSE ti
PORTa = %00001100
PAUSE ti
PORTa = %00001001
PAUSE ti
GOTO cruise
REVR:
PORTa = %00001001
PAUSE ti
PORTa = %00001100
PAUSE ti
PORTa = %00000110
PAUSE ti
PORTa = %00000011
PAUSE ti
GOTO cruise