DIY Electronic Cruise Control

ahend

1 mW
Joined
Apr 17, 2008
Messages
17
Location
Grand Rapids, Michigan USA
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 operation
Using 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 instructions
Tap 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 trim
With 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 control
While 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 simply 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 code
cruise.asm
P16F684.INC

Circuit schematic
CruiseSchematic[1].jpg

Ugly, but operational . . .
CCG[1].jpg CCF[1].jpg
Andy
 
WOW! , talk about one hell of an introduction posting :D

I have no background in micro's, or programming. Is there any way to adjust the ramp rate of the throttle output ? Especially when set to re-engage you could get a WOT if you speed is significantly different. This is from a perspective of ignorance on accelleration response to throttle position as I am yet to finish my build. Somebody please correct me if I am asking for a solution to a problem that does not exist.

On a similar train of thought, is it possible or worthwhile for that matter to require the bike to be up to X percentage of the previous captured speed before it will allow re-engagement of the cruise control ? Could be kind of interesting if somebody 'accidentally' presses the resume button whilst at a stand still.

I do have a friend who IS uController litterate, so this amazingly useful piece of kit will be finding a home on my Greenspeed once I get all the bits together to do my build.

I wonder if there is scope to port this code into a Cycle Analyzer ? I understand it already can be interfaced with the throttle to limmit speed / amps.
 
With the Golden Motor controller, the only effect I have witnessed when resuming is a small delay in the throttle up, as the speed is ramped to meet the motor RPM's. There is no stalling or deceleration during the event.
I messed around with the ramp delay until I got a reasonable acceleration with minimal current draw from a full stop. The ramp speed cannot be adjusted externally, as it is a static variable in the code, but an external adjustment could be added without too much trouble I should think. Since I can take the PIC out and re-program it easily, I did not think about making the ramp speed variable.

This system is totally open loop operation. Your ground speed will vary with terrain and human input. I know next to nothing about the Cycle Analyzer, but it would be very cool to get some feedback and step closer to a closed loop operation.

I find that I use this mostly to hold the throttle wide open. I don't know how much value a closed loop system would have. I believe most riders operate their bikes at two speeds, zero and wide open.

Andy
 
Oops, I had not picked up on the cruise being a throttle hold rather than a closed loop cruise control. I have not had a chance to actually ride an eBike yet.. :/ On BLDC controllers, does the throttle have a reasonably direct relationship to RPM ?

My anticipated usage is to set for a particular speed, subject to a max amps limmit. Then pedal assist based on heart rate. My trike is primarily for fitness, but I need to be able to maintain a time line in the mornings regardless of weather if the trike is to become my daily driver.

Check out the Cycle Analyist here ; http://www.ebike.ca/drainbrain.shtml .
 
On my brushless control, the throttle is fairly linear in relationship to the RPM output, as it well should be.

I find that during my commute, I set max throttle and pedal briskly to minimize output amperage, as read from my Watt's Up meter. This is done partly for fitness and partly for reducing the commute time. It's somewhat addictive to watch the current draw and work to maintain it below a certain value, as well as racing the clock
 
great!!
 
Impressive. I'm gonna try to adapt this to the Kelly Controller, I've been missing cruise control on that bike.

-JD
 
Ypedal said:
Hey oat.. you should really consider putting your bike picture from your sig to your avatar, i pitty the poor bastards on dialup ! lol..

That, and some of the foreign members have to pay for bandwidth by the byte ... getting the internet through a metered hypodermic.
 
Hi

Ten year later...

I look for code files . Asm and. Hex the site is kit à available...

I Want try on ride by wire motorcycle...

Thanks
 
Back
Top