I finally finished the electronic cruise control that I designed for the Golden Motor brushless controller.
The system is based on a PIC16F684 microcontroller from Microchip Inc. It interfaces the controller’s existing throttle and inhibit circuits. In operation, it reads the 0 to 5 volt output of the throttle assembly and emulates it back to the controller, thus allowing control of the signal.
Theory of operationUsing its onboard analog to digital converter, and pulse width modulation block, the PIC monitors and emulates throttle settings.
The PIC16F684 constantly polls the throttle in and throttle offset pins for analog voltage levels. These two analog values are converted to digital and added together. This combined throttle value is then tested against the current cruise setpoint. If the value is lower then the setpoint, the setpoint value is sent out a to digital output pin via pulse width modulation. If the combined throttle value is greater than the setpoint, the throttle value is used. The PWM output is smoothed through a first order low pass filter, where it is then presented to the controller's throttle input line.
The PIC also constantly monitors two button inputs, the set and resume controls. If the set button is pushed, the current combined throttle value is saved to memory as the setpoint. If the resume button is pushed, the PIC16F684 enters a loop, in which it tests the current PWM duty cycle (the value output to the motor controller) to a delayed ramp value, which starts at the current throttle position (in most cases zero). The loop increments the ramp value until it reaches the current setpoint. Each time the ramp value increments, it is sent out to the motor controller. When the ramp and setpoint values are equal, the loop is exited and the program continues scanning the main loop.
The throttle trim input (offset) serves to add back in the output filter losses. If it were not present, the throttle would not respond normally. Acceleration would occur further down in the throttle’s stroke, and the full throttle position would not provide full motor power.
An interrupt handler is incorporated into the program to monitor the state on the inhibit in/out pin. When the PIC16F684 see a falling edge on the inhibit pin, it executes the interrupt and shuts off the cruise control by setting the cruise setpoint to zero. Before doing so, it saves a copy of the value to memory so that operation can be resumed via the resume button.
Wiring instructionsTap into the +5VDC and ground lines bound for the throttle, and wire into the appropriate power line inputs of the PIC circuit. Be sure power is still being feed to the throttle assembly.
Cut the throttle signal line and wire the end coming from the throttle assembly into the Throttle IN line. Wire the other end (going to the controller), to the Throttle OUT line.
Tap into the controller's positive inhibit signal, and wire it to the Inhibit IN line. Make sure you are using the positive line. The inhibit in pin must be biased high from the controller. Use a volt meter between the two inhibit connections to find the positive wire. One of them is at ground potential, the other is around +5 volts. My positive inhibit line happened to be blue in color.
Adjusting the throttle trimWith the system turned on, hold the throttle full open and slowly turn the trim potentiometer until you hear, or see via speedometer, that the maximum speed has been reached. Do not turn the potentiometer any more than necessary to achieve full speed using this method.
Using the cruise controlWhile traveling at the desired speed, press the set button. The system will lock on to the current speed and allow the throttle to be relaxed. The throttle will work as normal above this set speed, allowing higher cruise speeds to be easily set. To deactivate, grab a handful of brakes to close the controller inhibit circuit (which also shuts down the cruise control) or simple press the set button with the throttle in the off, or relaxed position.
To resume cruise to the last setting, press the resume button. If the throttle position is lower than the cruise setpoint when resume is pressed, the system will gradually ramp up the output to the setpoint. If the throttle is higher than the setpoint, the setpoint will be activated but immediately overridden by the current throttle position. If the throttle is reduced below the resumed setpoint, cruise speed will be held to the setpoint.
The last setpoint value is saved to non-volatile memory, so anytime you power the system back up, the last cruise setpoint value is available and may be resumed.
Bill of materials(1) PICF16F684 Microcontroller
(1) 0.1µf ceramic capacitor
(1) 1µf ceramic capacitor
(3) 47kOhm 1/4 watt resistor
(1) 33kOhm 1/4 watt resistor
(2) Normally open, momentary push buttons
(1) 1kOhm linear trimming potentiometer
Project source codecruise.asmP16F684.INCCircuit schematicUgly, but operational . . .