Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Speedometer

Status
Not open for further replies.

Kiko

New Member
I have built a speedometer and gear indicator for my Suzuki motorcycle using a pic 16F876. That's is a simple circuit using 20 mhz clock. The speedometer signal come from VSS (vehicle speed signal) and goes direct to the pic pin and the signal from GPI (gear position indicator), which is a voltage, goes to another pin through a voltage divider. It's working but not very well because when I start the engine the readings are not steady. Does anyone could help me with this issue?

Thanks
 
What is the power source to the chip?

Does it work sometimes but not all the time? Or is it not not doing what you want (unstable all the time)?

If it is not doing what you want, I would upload the schematic and code.

I did a tag flip project on unlawfulintentions.com (could not find the link).

The noise from the alternator and cell phones (Nextel) in the tail of the bike made the microcontroller do weird stuff some times.

A capacitor will fix that.

If you list more details someone here will help you.
 
Try inserting a few seconds delay at the beginning of the PIC code assuming the PIC is powered at moment of engine start.

Is the display erratic or just the actual speed values?
 
It's working well on the bench but it's unstable installed in the bike and it's getting worse when the engine start. I've tried to add a higher value capacitor before and after of the LM 7805 but did not fix it.
 
Try inserting a few seconds delay at the beginning of the PIC code assuming the PIC is powered at moment of engine start.

I'll try to do that tomorrow...

Is the display erratic or just the actual speed values?

The readings on display are unstable even with no speed the readings going crazy almost all the time (it's not accurated).
 
Is the VSS going to a normal input rather than a schmitt trigger input?

Mike.
 
Pommie said:
Is the VSS going to a normal input rather than a schmitt trigger input?

Mike.

What schmitt trigger circuit (IC) is the best for that application?
 
donniedj said:
Try inserting a few seconds delay at the beginning of the PIC code assuming the PIC is powered at moment of engine start.

Is the display erratic or just the actual speed values?

By the way, I have put a 2 sec. delay just before a program loop and didn't make any difference.

I'm using a Proton+ Basic Compiler.
 
Is the pic working OK, but the readings are wacked out?

Can you blink an LED and see if the pic is stable. That way you which direction to trouble shoot in.
 
mramos1 said:
Is the pic working OK, but the readings are wacked out?

Can you blink an LED and see if the pic is stable. That way you which direction to trouble shoot in.

Like I sad it works properly on the bench, I think the problem is in the bike itself because some times when I turn just the ignition on the reading is zero and when the engine start the readings going crazy and when the bike is running the reading is either crazy.
 
I will post the routine I've made to read the speed later on.

Thank you very much for the help
 
DEVICE 16F876A
DECLARE XTAL 20
DECLARE LCD_TYPE 0
DECLARE LCD_DTPIN PORTB.4
DECLARE LCD_ENPIN PORTB.2
DECLARE LCD_RSPIN PORTB.3
DECLARE LCD_INTERFACE 4
DECLARE LCD_LINES 2
DIM KMH AS word
DIM KMHT AS WORD
Delayms 2000
CLS
Start:
KMHT=COUNTER PORTA.5, 250
KMH=((0.002*3600)*(KMHT*4))/1000
ALL_DIGITAL=TRUE
PRINT AT 1, 1, " "
PRINT AT 1, 1, DEC KMH
PRINT AT 1, 5, "KM/H"
GOTO Start


Anyone can help? I think there is something wrong with this code because I have ran it on the computer and the problem I mentioned before still happening, the reading is not reliable (goes high and low).
 
Kiko said:
What schmitt trigger circuit (IC) is the best for that application?

What I meant was that some of the input pins on the pic are schmitt triggers. RA4, RB0 (int only) and all of port C are schmitt trigger inputs. Try changing your circuit so it uses one of these inputs.

Mike.
 
Pommie said:
What I meant was that some of the input pins on the pic are schmitt triggers. RA4, RB0 (int only) and all of port C are schmitt trigger inputs. Try changing your circuit so it uses one of these inputs.

Mike.

I was using RA5...
 
There were a couple of things that could have been improved in your program;

- many compilers cant handle cross variable type operations with floats
- you were not polling the info before it was displayed (PIC's work extremely fast, esp @ 20Mhz, and if the value has not changed, why re-write it too the display?
- There is no need to re-write "KM/Hr" over and over
- ALL_DIGITAL = True is a Compiler setting, no need to throw it in the main loop of the program

I modified it a little (you will have to change over the RS and E pins as I've swapped them over - force of habbit as that way they are all connected straight onto the PIC)

Watch the circuit in action here

Code:
Device 16F876A
Declare XTAL 20

Config XT_OSC , WDT_OFF , PWRTE_ON , BODEN_OFF , LVP_OFF , CPD_OFF, CP_OFF , DEBUG_OFF

ALL_DIGITAL = TRUE

Declare LCD_TYPE 0
Declare LCD_DTPIN PORTB.4
Declare LCD_ENPIN PORTB.3
Declare LCD_RSPIN PORTB.2
Declare LCD_INTERFACE 4
Declare LCD_LINES 2

Dim KMH As Float
Dim Temp_Float As Float
Dim KMHT As DWord
Dim KMH_Last As DWord

TRISC.0 = 1

DelayMS 1000
Cls

Print At 1,5, "KM/Hr"
KMHT = 0

Start:

        KMHT = Counter PORTC.0, 250
	
	If KMHT = 0 Then Goto Display
	
	Temp_Float = KMHT
	Temp_Float = (Temp_Float * 4) * 7.2
        KMH =  Temp_Float / 1000
	KMHT = KMH

Display:
	
	If KMH_Last <> KMHT Then
            Print At 1, 1, DEC3 KMHT
	    KMH_Last = KMHT
	EndIf
    
    GoTo Start

Notice I do all the Float functions with floats - so theres no multiplying a Word (0 - 65535) by decimal numbers (such as 7.2) as the answer will be calulated in Word format, and the deciamls will be dropped..

I've used a DWord for KMHT as some of the values can get quite high, and this allows storage of extremely large whole numbers. The Data from KMH is transferred to KMHT so that the decimals are dropped, and to allow the DEC3 modifier to always display three whole numbers i.e. 010, 060, 122 not 10.1, 60.5, 122.9 (theres no need to see the decimal place for speed)

7.2 was calulated by just doing the math before hand (0.002 * 3600)

I threw in the config lines just out of force of habbit

Hope this helps improve the program a little :)
 
Last edited:
gramo said:
There were a couple of things that could have been improved in your program;

- many compilers cant handle cross variable type operations with floats
- you were not polling the info before it was displayed (PIC's work extremely fast, esp @ 20Mhz, and if the value has not changed, why re-write it too the display?
- There is no need to re-write "KM/Hr" over and over
- ALL_DIGITAL = True is a Compiler setting, no need to throw it in the main loop of the program

I modified it a little (you will have to change over the RS and E pins as I've swapped them over - force of habbit as that way they are all connected straight onto the PIC)

Watch the circuit in action here

Code:
Device 16F876A
Declare XTAL 20

Config XT_OSC , WDT_OFF , PWRTE_ON , BODEN_OFF , LVP_OFF , CPD_OFF, CP_OFF , DEBUG_OFF

ALL_DIGITAL = TRUE

Declare LCD_TYPE 0
Declare LCD_DTPIN PORTB.4
Declare LCD_ENPIN PORTB.3
Declare LCD_RSPIN PORTB.2
Declare LCD_INTERFACE 4
Declare LCD_LINES 2

Dim KMH As Float
Dim Temp_Float As Float
Dim KMHT As DWord
Dim KMH_Last As DWord

TRISC.0 = 1

DelayMS 1000
Cls

Print At 1,5, "KM/Hr"
KMHT = 0

Start:

        KMHT = Counter PORTC.0, 250
	
	If KMHT = 0 Then Goto Display
	
	Temp_Float = KMHT
	Temp_Float = (Temp_Float * 4) * 7.2
        KMH =  Temp_Float / 1000
	KMHT = KMH

Display:
	
	If KMH_Last <> KMHT Then
            Print At 1, 1, DEC3 KMHT
	    KMH_Last = KMHT
	EndIf
    
    GoTo Start

Notice I do all the Float functions with floats - so theres no multiplying a Word (0 - 65535) by decimal numbers (such as 7.2) as the answer will be calulated in Word format, and the deciamls will be dropped..

I've used a DWord for KMHT as some of the values can get quite high, and this allows storage of extremely large whole numbers. The Data from KMH is transferred to KMHT so that the decimals are dropped, and to allow the DEC3 modifier to always display three whole numbers i.e. 010, 060, 122 not 10.1, 60.5, 122.9 (theres no need to see the decimal place for speed)

7.2 was calulated by just doing the math before hand (0.002 * 3600)

I threw in the config lines just out of force of habbit

Hope this helps improve the program a little :)


OK sir I got it, as I'm not a programmer nor a enginner any help with a exemple like you did are welcome. Thank you very much...

And like I post before this is not the only problem I have because I want to make a gear indicator and this is the worse problem I'm having and I think you can help with this issue. I'll try to explain the problem (in english) in another post. Thank you again.
 
My Suzuki bike has an OEM gear position sensor (GPS) that gives the output voltage as follow:

1st gear = 1.782v
2nd gear = 2.242v
3rd gear = 2.960v
4th gear = 3.630v
5th gear = 4.310v
6th gear = 4.660v
Neutral = 5.000v

My circuit have a voltage divider using RA0 as input and with this setup I can do a routine to show me the gear I'm on the LCD. But the problem start to grow up when I start the engine because the voltage that come from the GPS is not the same when just the ignition is on and in the 6th gear for exemple I have a voltage that vary from 4 to 5v and them the the LCD shows sometimes 5th gear neutral and 6th gear when I'm in the 6th gear.

Follows are the voltages I've taken running the bike:

1st gear = 1.243v to 2.586v
2nd gear = 2.124v to 3.210v
3rd gear = 3.178v to 3.486v
4th gear = 3.633v to 4.400v
5th gear = 4.215v to 4.887v
6th gear = 4.461v to 4.942v
Neutral = 4.678v to 5.245v

The idea then is to write a routine that whem I'm in 6th (betwen 4.461 and 4.942) the program lock only the reading (6th gear on LCD) but still monitoring the voltages and jump to another gear without interfere with each other.

I don't know if I could explain... But any help will be wellcome.
 
Kiko said:
My Suzuki bike has an OEM gear position sensor (GPS) that gives the output voltage as follow:

1st gear = 1.782v
2nd gear = 2.242v
3rd gear = 2.960v
4th gear = 3.630v
5th gear = 4.310v
6th gear = 4.660v
Neutral = 5.000v

Follows are the voltages I've taken running the bike:

1st gear = 1.243v to 2.586v
2nd gear = 2.124v to 3.210v
3rd gear = 3.178v to 3.486v
4th gear = 3.633v to 4.400v
5th gear = 4.215v to 4.887v
6th gear = 4.461v to 4.942v
Neutral = 4.678v to 5.245v

The idea then is to write a routine that whem I'm in 6th (betwen 4.461 and 4.942) the program lock only the reading (6th gear on LCD) but still monitoring the voltages and jump to another gear without interfere with each other.

I don't know if I could explain... But any help will be wellcome.

Hmm, over lapping voltages for different gears, leave it with me, I'm sure with enough samples we could calculate the average that would be a lot closer to the actual manufacture's specifications.. Its 2am here, I'll get on it tomorrow and make another program for you
 
gramo said:
Hmm, over lapping voltages for different gears, leave it with me, I'm sure with enough samples we could calculate the average that would be a lot closer to the actual manufacture's specifications.. Its 2am here, I'll get on it tomorrow and make another program for you

Over lapping... I hate this word at this moment (just kidding).

I apreciate your help.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top