Motorcycle Gear Position Indicator

duke12

New Member
I have posted this on the VSM forum but I hope I may get some help here.
I am trying to construct and simulate a Motorcycle Gear Position indicator.
It was a project with gear pedal input using Hall effect trs and magnets but I find that too unreliable and want to build a project using RPM and Road speed both of which are available to me.

I am able to read revs and I am able to read speed
I have a chart of revs vs road speed in each gear

If I input my Bike "Triumph Sprint GT" into this spreadsheet in the link below I get a neat chart of expected readings that the Pic should process

http://www.gearingcommander.com/

What I don't get now that I have VSM how I can simulate a frequency reading (a pulse or spike?) and how to handle that in my code.

The original cct with pedal inputs

GearIndicator Pedal.jpg

The code for that
Code:
'2013 fifth version of m/c gear shift indicator
'Set Editor Program to Options Picaxe 28x
'Leverup is switch going low to high on Pin Analog 0 Pin 2 of chip
'Leverdown is switch high going low on Pin Analog 1 pin 2 of chip use striped wire
'work to do !!!!!!!!!!!!!!!!!!!!!
'need to take neutral out of loop out and have it switch by Analog 3 from neutral light or neutral switch
'assign variables b1 (byte1 =8 bits) to b4
'pins = $BA 'show NEUTRAL N later when switch by neutral light later
symbol gearposn = b1:symbol geardisplay = b2
symbol leverdown = b3:symbol leverup = b4: symbol neutral = b5
'----------------------------------------------------------------------------
gearposn = 2 : gosub showgear 'start in gearposn 0 gear neutral? = $BA = N
'---------------=================00000000 MAIN 0000000==================------------------------

Start:
'debug
readadc 0,leverup
if leverup > 150 then upshift 'if low to high volts they pushed the up switch or lever
readadc 1,leverdown
if leverdown < 150 then downshift 'if high to low volts they pushed the down switch or lever
goto Start
end '----------------------------------------------------------------------------------------------
' SUBS
'---------------=================0000000000 UP COUNTER 000000000000==================--------------
upshift:
gearposn = gearposn + 1 max 6 ' move up a gear unless at 6
'if gearposn > 6 then
' gearposn = 6
'endif
gosub showgear
wait_up_lever: 'in case they are resting on the switch or lever
readadc 0,leverup: pause 20
if leverup > 150 then wait_up_lever
goto start
'---------------=================00000000000 DOWN COUNTER 00000000000==================-------------
downshift:
gearposn = gearposn Min 2 - 1' move down a gear unless at 1
'if gearposn < 1 then
' gearposn = 1
'endif
gosub showgear
wait_down_lever: 'in case they are resting on the switch or lever'
readadc 1,leverdown: pause 20
if leverdown < 150 then wait_down_lever
goto start
'---------------=================00000000000 SHOW GEAR 00000000000==================-------------
showgear:
'___________________ display the gear selected!_________________________________________ ___
' gearposn 0 1 2 3 4 5 6
'showgear: '0 1 2 3 4 5 6
lookup gearposn, ($BA, $82, $DC, $D6, $E2, $76, $7E), geardisplay
pins = geardisplay
return

New project using rpm / road speed -- So far

[ATTACH=CONFIG]16971.vB[/ATTACH]

The code so far

Start:
main:
count 1, 1000, w1
'pulsin 1,1,w1
If w1 < 150 then gosub show
goto main
end

show:
pins = $82

'wait 5 'seconds
'debug
'w1 = 252
end
return
As you can see I am a bit stuck now!
Should I be posting this in another forum or am I in the right place?
 
Last edited by a moderator:

AllyCat

Senior Member
Hi,

Sorry, I can't help with VSM, but as far as the hardware/programming is concerned, you first need to connect the Speedo signal (resistor divider chain) to a separate pin, say IN1.

Generally, PICaxe can't count both at the same time, but you could count one signal for (say) 200ms and then the other immediately afterwards. Or often it's better (faster) to use PULSIN and measure the time between two pulse edges and calculate the "frequency" by division. There are many threads on this, or we can go into more detail later.

Once you have the two "frequencies" measured (rpm and speed) they need to be scaled in some way and then divide rpm by speed. You may need to choose scaling (multiplier) factors quite carefully to get useful values with PICaxe's integer division, perhaps results in a range of from 10 to 100.

Now choose "threshold" values about half-way between the known gear ratios (scaled to correspond with the rpm/speed calculation) and then use a sequence of IF value > thresh1 then ..... ELSE IF value > thresh2 ..... etc. ... ENDIF.

Or there are other code structures such as CASE , LOOKUP / LOOKDOWN or even a TABLE which may be preferred.

Cheers, Alan.
 

hippy

Technical Support
Staff member
What I don't get now that I have VSM how I can simulate a frequency reading (a pulse or spike?)
VSM provides a set of Virtual Instruments including a Signal Generator - Right-click over circuit, Place, Virtual Instruments.

There is a provided 'count' sample which will show such a signal generator connected -

(Registered PICAXE VSM Samples) \ Commands \ count command.dsn

You could create a sub-circuit, your own virtual instrument, which takes some 'throttle' and 'gear shift' inputs and generates the desired RPM and speed signals which can be fed into the PICAXE part of the circuit but that would be additional work.
 

duke12

New Member
I now have a pretty good working Simulation and some code to drive it.
Picture of sim working >
GPI v1.jpg

Working code that need a bit of help >

Code:
symbol rpm = w1 : symbol speed = w2 : symbol RpmRange = w3 : symbol ratio = w4
symbol Gear = w5 : symbol geardisplay = w6 : symbol neutral = pinC.0 

main:
	gosub GetRpmRange
	sertxd ("RpmRange = ",#RpmRange,CR,LF) 'sertxd ("Tacho RPM is ",#rpm,CR,LF)
	gosub GetSpeed
	sertxd ("Speedo pulses = ",#speed,CR,LF) 'need to convert klm/hr to speedo pulses
	Gosub GetRatio
	sertxd ("ratio = ",#ratio,CR,LF)
	Gosub GetGear
	sertxd ("Gear = ",#Gear,CR,LF,CR,LF)
	gosub showgear
	if neutral < 1 then
		do
			Gear = 0
			gosub showgear
		loop while neutral < 1
	end if
goto main
end
'--------------------------------------------------------------------------------
GetRpmRange:
count 1, 50, rpm : rpm= rpm* 20 ' count pulses in ? secs (at 4MHz)
	
	select case rpm
		Case 0 To 1200 
			RpmRange = 1
        	Case 1201 To 2000 
			RpmRange = 2
        	Case 2001 To 2800 
			RpmRange = 3
       	 	Case 2801 To 3600
			RpmRange = 4
       		Case 3601 To 4400
			RpmRange = 5
      	 	Case 4401 To 5200
			RpmRange = 6
      	 	Case 5201 To 6000
			RpmRange = 7
      		Case 6001 To 6800
			RpmRange = 8
       		Case 6801 To 7600
			RpmRange = 9
       		Case 7601 To 8400
			RpmRange = 10
       		Case 8401 To 9200
			RpmRange = 11
	end select
Return	'-------------------------------------------------------------------->

GetSpeed:
	count 2,100,speed
	speed= speed* 10
Return '---------------------------------------------------------------------->

GetRatio:
ratio = rpm / speed
Return '--------------------------------------------------------------------->

GetGear:
	Select Case Ratio
		Case 0 to 32
			Gear = 6
		Case 33 to 37
			Gear = 5
		Case 38 to 42
			Gear = 4
		Case 43 to 50
			Gear = 3
		Case 51 to 63
			Gear = 2
		Case 64 to 88
			Gear = 1
	End Select
Return '--------------------------------------------------------------------->

showgear:
	'___________________ display the gear selected!____________________________________________
	'       gearposn    0    1   2    3    4    5    6		
	'showgear:         '0    1   2    3    4    5    6
	lookup Gear, ($BA, $82, $DC, $D6, $E2, $76, $7E), geardisplay
	pins = geardisplay
return
Bit of a problem with the code that someone may be able to help me with.
The display flashes from one gear to the next on crossing point and I need a way to soften the change.
Is it hysteresis that I am looking for?
Anyway I am after a fix for the code to soften the change.
Any ideas?
 

Attachments

hippy

Technical Support
Staff member
The display flashes from one gear to the next on crossing point and I need a way to soften the change.
Is it hysteresis that I am looking for?
Possibly. On the boundary of say 2nd and 3rd gears the software may be rapidly alternating between showing "2" and "3" which will light more segments than desired. Is that how you mean by "display flashes" ?
 

goom

Senior Member
Perhaps you need to put a short pause before changing the display on detecting a gear change threshold. You could store the current gear position, and check for a change in the "Gear" variable. If it has changed, insert a pause before displaying the new gear.
In the real situation, I would suppose that it would take some time for the road speed vs. tacho relationship to become steady at the new value, so a significant pause would be required.
Maybe it would also be worth extending your case statements to trap for impossible combinations, and skip updating the display in such cases.
 

AllyCat

Senior Member
Hi,

Maybe just blanking the display for a few hundred milliseconds is all that's needed, i.e. something like pins = 0 : pause 200 before looking up the new geardisplay value.

However, if you actually want a "fade" between the two digits, then that can be done quite easily using a (software-created) PWM technique. You'll need a few more variables, but there seem to be plenty spare and actually you only need byte (not word) variables for ratio (w4), Gear (w5) and geardisplay (w6). Try something like this (not tested) :

Code:
symbol oldbrightness = b0
symbol newbrightness = b1
symbol oldgeardisplay = w7
symbol PWMDELAY = 10					; Make larger for a slower fade
; BASIC CODE HERE, AS BEFORE, THEN:
showgear:
	oldgeardisplay = geardisplay
	lookup Gear, ($BA, $82, $DC, $D6, $E2, $76, $7E), geardisplay
	for newbrightness = 0 to PWMDELAY
		oldbrightness = PWMDELAY - newbrightness
		pins = oldgeardisplay
		pause oldbrightness
		pins = geardisplay
		pause newbrightness
	next newbrightness
	return
Cheers, Alan.
 

duke12

New Member
Hippy, yes you're right the problem is on the transition from ANY one range to the next, say 5th to 6th -3rd to 4th etc.
It will display 5 then 6 then 5 and finally settle down on 6. This may be a problem with the SIM and may not happen when I get it to the bike - we will see. I would love to have it working properly in the sim first, that's why I purchased it.

This problem occurs on the sim as I rotate the frequency knob on the signal generator which I am using as PRM in and the gear range is in transition.

Alan, I tried using the delay you said, I put it here>
sertxd ("Gear = ",#Gear,CR,LF,CR,LF)
pins = 0 : pause 20 '200 made it wait forever on the sim.
gosub showgear

That had the effect of blanking the display on each iteration through the main prog loop, not desirable eh?
I don't know where else to put a blanking delay that will hold the last gear still on the display, maybe just a delay with no blanking.

Thanks for the tip on variable sizes I have already downsized all that I can to bytes since my last post.

Fading across the transition I think would not fix the problem just mask it somewhat, I would know that there is still a problem.

You will notice there is a pull down momentary for the neutral switch, which displays "n".

The bike also has a switch attached to the clutch lever so it cannot be started with the clutch disengaged (safety feature). I wonder if I could use this switch as a blanking device as the gears are changed with the clutch used??

That would not make this project truly universal though as many riders do not clutch on the way up the box. I sometimes do sometimes don't depending on how fast I am riding and how busy I am looking ahead ect.

There seems to be another error - when the bike is stationary i,e, no speed input (actually the sim will not allow zero so I input it as 1hz or 1 klm/hr) and the bike is at any rpms. It displays 6th gear!

Thanks for your interest.
Duke
 
Last edited:

rossko57

Senior Member
There seems to be another error - when the bike is stationary i,e, no speed input (actually the sim will not allow zero so I input it as 1hz or 1 klm/hr) and the bike is at any rpms. It displays 6th gear!
This is an inherent difficulty with the RPM/roadspeed method. The actual gear selected cannot be determined while at rest.
You maybe need to think about what behaviour you'd like here - blank if indeterminate perhaps, or flash '1' or 'L' to remind they're in gear and it ought to be low.

You can code for the clutch switch, without relying on it - if its fitted to a bike without, it will still work in general.
 

AllyCat

Senior Member
Hi,
200 made it wait forever on the sim.
The Sim probably runs much slower than "real" code, so the effects may not be apparent in practice. But I commend you for attempting to get it all working properly before putting it on the bike (where debugging is likely to be much more difficult).

That had the effect of blanking the display on each iteration through the main prog loop, not desirable eh?
Ah yes, of course, the gear display is being "updated" even when it doesn't actually change. You'd need to use something like if oldgeardisplay <> geardisplay then : pause 200 .......

The bike also has a switch attached to the clutch lever so it cannot be started with the clutch disengaged (safety feature). I wonder if I could use this switch as a blanking device as the gears are changed with the clutch used??
Yes, I think that is the way I would proceed. If you are measuring engine rpm, then when the clutch is disengaged the gear ratio calculation is probably not valid. So blanking the display might be the best option, or certainly do not change the displayed value until the clutch is re-engaged (and a delay until it stops slipping?).

Cheers, Alan.
 
Position encoder.jpg

My present project also requires a rotational position encoder an image of which I demonstrate here purely for interest of others, not to criticise the choices made by the original poster as there are always compromises to be made in any design.
To use this idea as an alternative to Duke's choice, one would need for example, to be able to access to the inner workings of the gearbox selector mechanism and also be able to make the necessary extra parts.

In my application the purpose is slightly more complex in that I need to drive and control a rotation through nine possible positions these being read by two hall sensors and strategically placed miniature magnets. The magnets are coloured blue and red to indicate the different poles. Each 120 degree rotation of the smaller gear on the left which is driven by a gear motor, results in one position change of the larger gear. I use a hall sensor and the three magnets on the smaller gear to control the motor and ensure a finer resolution of the system and use the sensors on the larger gear to drive a digital indicator.

The indicator hall effects are monitored using ADC values so that it is possible to identify whether the magnet is absent, north or south. Using two sensors it is therefore possible to monitor nine possible combinations;

A sensor: X X X N N N S S S
B sensor: X N S X N S X N S where X is no magnet present.

I hope that is of some interest to some of you...

JG
 

duke12

New Member
John
Suzuki, Kawasaki and some Honda models have direct external access to a rotating plate that is on the same shaft as the gear selector drum. It outputs 5 to 6 outputs to earth on individual wires to the bike harness. I have seen many projects where this is easily read by a pic and transferred to a 7segment display. They all work very well.

A lot of other bikes, mine included do not have this facility without some pretty drastic re engineering to get at the end of the gear selector drum. In my Triumph there is no easy access to the drum from the outside. So most of these bike have to go down the "read from the pedal with magnets" - problematic if the rider taps and taps on 1st or 6th gear or the calculation from "speedo vs tach inputs" which is the way I am going.

There are commercial versions of both available but that sort of ruins the fun of playing with the Picaxe!

I have finally got a pretty good simulation running and a pic is attached.
GPI v2.jpg

V2 Simulation now has variable speedo and tacho inputs. should have went this way at first. all works very well and output to the display corresponds with the spreadsheet figures for my bike. I have added a input for the clutch lever switch that will show a "N" "n" while gear changing. That I hope will cure the transition flicker. If I change without the clutch there may be some display bouncing on gear transition but I can live with that for now.

I would like to know if I am able to use a smaller Picaxe and still have all of the features on this project?
Any ideas appreciated

Thanks for the interest.
Duke
 
Top