Motorcylce Gear Display
GEARPIC.JPGGINSIDE.JPG

Many motorcycles have even six gears and some models even reverse, but they do
not have a gear position display. At first this seems to be simple to arrange, a closer look makes it a quite complicated for using mechanical levers. For electronics and microprocessor logic this problem is easy to solve.

A problem and sensors

GEAR.JPG

My friend bought an old motorcycle, which has six gears and he wanted to know
which gear is on by a seven segment display. The motorcycle gearbox works with foot operated lever. Pushing it to down goes first gear on, pulling it up or pushing other end down, lever goes through free position to second gear. Pulling lever up again gear goes to the third, fourth, fifth and sixth position. Pushing level down gear goes to fifth, fourth, third and second gear. Then it goes through the free position to the first gear.
Pulling lever up gear goes finally to free position. For position sensors we decided to use three micro switches: a free, down and up micro switches. The gear lever operates these switches according to the sequence described above.

Microprocessor and display

A big, 25 mm height seven segment display is more than adequate for even almost blind motorcyclist in day and night. A Kingsbright SC10-21 display has seven segments with two leds in series and a dot has only one led. This display has common anode connection; a common cathode model requires a small modification for microprocessor program. The modification is explained later.
A flash PIC16F84A with 13 I/O pins is enough for 8 display outputs and three micro switch inputs. PORTB is connected to the display the through resistor network. PORTA is used for micro switch inputs. The processor and display use five volt power supply. A standard 7805 regulator drops 12 volt battery to 5V. A power supply wires should go through a HF-filter to ignition switch and ground.

A micro controller program

Although the logic seems simple the any real world interface includes non-perfect operations. The switches bounces, there is possible overlapping timing and a special conditions like starting or stopping with some gear on.
A program is a state machine, where only way to go next state is fulfil the right switch combination and the right amount of debouching time. After reset the program goes to the state zero and shows a zero digit at the display. Between each state there must be a 50 ms debouche time. Each switch has also hardware debouche timer by a RC-circuit. These prevent also external interferences from ignition. A seven segment display is decoded directly by seg-table, which puts a right combination of leds on. A CCS PIC C compiler is used for the software. The software size is about 300 compiled words.

===== A 7-seg display table + some test combinations =====

const byte seg[25]={0x3f,6, 0x5b,0x5b, 0x4f,0x66,0x6D ,0x7c};

====== a code snippet for using a table

#include <16F84A.h> // select the right PIC
#use delay(clock=4000000, restart_wdt) // select right oscillator
#fuses HS,NOPROTECT,WDT,PUT // use watchdog
#byte PORTA = 5 // define IO-port address
#byte PORTB = 6
#bit UP = PORTA.3 // and IO-bits
#bit DOWN = PORTA.2
#bit FREE = PORTA.1

char dat,state,pre_state; // declare some variables

void set_display( void) {
dat = seg[state];// fetch a display bits according state table
PORTB = ~dat; // Common anode display requires a inverted (~) bits,
// common cathode display only PORTB = dat;
}

==== a pseudo program for first state ===
void main (void) {
set_tris_a (0x3F); // set data direction register for PORTA, all in
set_tris_b (0x00); // set data direction register for PORTB, all out

test_display_digits( ); // go through each digit for testing
state=0; // set the initial state

while (1) { // forever loop
restart_wdt(); // keep watchdog alive
switch ( state) {
case 0: if( !DOWN ) // if DOWN switch on and state is 0
state =1; // goto to mode 1 i.e. gear one
pre_state =0;// previous state for direction operations
break;
state 1:
……
state 6: // each state has some combination
// of pre_state and inputs
} // end switch()
wait_debounce_delay(); // display the dot led during debounce wait time
set_display(); // set state to decoded display
} // end while ()
} // end main
==================== end of snippet ======

Because the program do not use any interrupts, timers or any special PIC peripheral, so it is easy to implement with any micro controller like Intel 80C51 compatible processor.
80C51 require although a driver for bright display, so the PIC is right selection for this application. A still better selection is PIC16F628. It has internal RC-oscillator, which removes one component, but it is not yet so easily available than 'F84 or 'F84A.

A mechanical construction

It is possible to make the whole unit into one double sided circuit board. Because this was a free time construction project for a friend, a two sided circuit board was too expensive. Two back to back connected one sided circuit boards can be easily made
by a hobby builder. Thanks to micro controller, there is so little parts, that hand wired unit is done in a half a hour. The boards can be connected together by 0.1" pins, but I used just a flat cable to easier testing. The switches and power supply is connected by a five pin audio DIN-connector. This connector type is easily obtained from keyboard
connector of old PC motherboard. The unit is then easy to take home at nights.
The led display could be a smaller one, but you need to modify a circuit board according the display wiring. The unit goes to almost any small case, but a brass front plate makes a final touch for your project. Use twisted wires for switches and power supply. Turn power supply wires around half an inch ferrite ring to reduce possible
interferences from ignition.

Testing

Before you attach a new gear display to you motorcycle, test the display logic with three push buttons switches and a 12V power supply. First all digits displayed in sequence for testing purpose. A zero digit is shown indicating a no gear position.
Push the down button and digit one comes on. Push free button and then up button, digit two is displayed. Push up again until display shows digit six. Push down until digit two is shown. Push free button and then down again, digit one is shown. Push free and display shows digit zero. If the free switch is pushed during states 2..6, the
program goes to zero state. This prevents any lockout of different start ups and stop conditions with gear on. If everything went well you can attach it to your motorcycle and show it to your friends especially in the evenings when it bights as Christmas three.

Parts list for motorcycle gear display
DESCRIPTION QUAN. COMPONENT NAME(S)

Capacitor 0.1uF 50V 2 C1,C2
Diode 1N4007 1 D1
Tantal capacitor 1uF 35V 3 E1,E2,E3
4MHz resonator,3 wire 1 Y1
Connector DIN5 180,female 1 DIN5
Straight pins 10-row 0.1" 1 X1
Resistor 10k 4 R2,R3,R5,R6
Regulator 7805 TO-220 1 IC2
PIC16F84A-04/P Microchip 1 IC3
Resistor network 8*220R 1 RN1
Common anode SC10-21 1 IC1
7-seg LED display Kingbright 25mm or Stanley NAR-1R3-B
—-
Here is hex-file for the PIC-programmers
http://remotesmart.wikidot.com/local--files/motorcylce-gear-display/GEAR.HEX
Here is PCB-file in Protel format
http://remotesmart.wikidot.com/local--files/motorcylce-gear-display/GEAR.PCB

GEAR.PDFGEAR.pdf
===
This is article which was published in Electronic World May 2002 pages 32 -36

PEkka OH3GDO

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License