![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack (4) | Thread Tools | Display Modes |
| | (permalink) |
| 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 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
__________________ Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net Last edited by gramo; 10th March 2007 at 08:43 AM. | |
| |
| | (permalink) | |
| Quote:
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. | ||
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) | |
| Quote:
__________________ Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net | ||
| |
| | (permalink) | |
| Quote:
I apreciate your help. | ||
| |
| | (permalink) |
| All finished, heres the code; Code: Device 16F876
Declare XTAL 20
Config XT_OSC , WDT_OFF , PWRTE_ON , BODEN_OFF , LVP_OFF , CPD_OFF, CP_OFF , DEBUG_OFF
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
Dim Result As Word
Dim Total As Float
Dim Last_Result As Float
Dim X As Byte
Symbol _1_Min = 1.243
Symbol _1_Max = 2.355
Symbol _2_Min = 2.356
Symbol _2_Max = 3.194
Symbol _3_Min = 3.195
Symbol _3_Max = 3.709
Symbol _4_Min = 3.710
Symbol _4_Max = 4.307
Symbol _5_Min = 4.308
Symbol _5_Max = 4.674
Symbol _6_Min = 4.675
Symbol _6_Max = 4.810
Symbol _N_Min = 4.811
Symbol _N_Max = 5.245
TRISC.0 = 1
DelayMS 1000
Cls
Print At 1,5, "KM/Hr"
KMHT = 0
TRISA.0 = 1
ADCON1 = %10000000 ' Set analogue input, Vref is Vdd
Start:
Result = 0
Total = 0
X = 0
Repeat
Result = ADIN 0
Result = Result * 2
Total = Total + Result
Inc X
Until X = 15
Total = Total / 15
Total = Total * 5 / 1023
Select Total
Case _1_Min To _1_Max
Print At 2, 1, "1st Gear ", DEC3 Total, "V"
Case _2_Min To _2_Max
Print At 2, 1, "2nd Gear ", DEC3 Total, "V"
Case _3_Min To _3_Max
Print At 2, 1, "3rd Gear ", DEC3 Total, "V"
Case _4_Min To _4_Max
Print At 2, 1, "4th Gear ", DEC3 Total, "V"
Case _5_Min To _5_Max
Print At 2, 1, "5th Gear ", DEC3 Total, "V"
Case _6_Min To _6_Max
Print At 2, 1, "6th Gear ", DEC3 Total, "V"
Case _N_Min To _N_Max
Print At 2, 1, "Neutral ", DEC3 Total, "V"
Case Else
Print At 2, 1, "Unknown ", DEC3 Total, "V"
EndSelect
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 The program can probably be tweaked - eg I left the volt display on there for debugging and you can remove it once you feel happy you know all of the volages are correct. Watch the circuit in action here The SIM appears laggy as there are 7 Signal gererators in use. It will be much faster in real time.
__________________ Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net | |
| |
| | (permalink) |
| You might be asking why on earth I used a voltage divider in the circuit - its because in Neutral, the were voltages over 5V, and PIC's don’t like that! So to keep everything to operating standards, the voltage divider is just halving the sample voltage; eg, 5.5V from the gear selector output will now be sampled as 2.25V by the PIC. The program scales it back up mathematically
__________________ Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net | |
| |
| | (permalink) | |
| Quote:
I apreciate you help indeed and thank you very much ps: If you have any more ideas please let me know. | ||
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) |
| Does the gear voltage vary with engine RPM. If so, the voltage may be relative to the battery voltage and you may be able to fix it by setting the ADC reference voltage to a division of the battery voltage. BTW, have you changed to a schmitt trigger input and if you have, did it work? Mike. | |
| |
| | (permalink) |
| I used PORTC.0 as the RPM sensor, all of the Pins have a built in schmitt trigger on PORTC, so I hope that helps him out
__________________ Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net | |
| |
| | (permalink) | |
| Quote:
I will post the news later just for information. Thank you very much. | ||
| |
| | (permalink) |
| FYI attached is the circuit I'm using. I increased the value of C5 and C7 to try to filter any noise (didn't work). I've placed a 10k resistor (pull-down) on PORTC7 then I removed because it killed the signal to the original bike's speedometer. | |
| |
| | (permalink) |
| I think your problem is in the ground - what ground did you use when you measured the voltages? I think you should use the black/white wire on the gear position switch connector, not just any ground on the bike. Attached is a picture of how I think the Suzuki gear position switch is wired. D. | |
| |
| | (permalink) | |
| Quote:
Symbol _1_Min = 1.243 Symbol _1_Max = 2.355 Symbol _2_Min = 2.356 Symbol _2_Max = 3.194 Symbol _3_Min = 3.195 Symbol _3_Max = 3.709 Symbol _4_Min = 3.710 Symbol _4_Max = 4.307 Symbol _5_Min = 4.308 Symbol _5_Max = 4.674 Symbol _6_Min = 4.675 Symbol _6_Max = 4.810 Symbol _N_Min = 4.811 Symbol _N_Max = 5.245 | ||
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| LinkBack to this Thread: http://www.electro-tech-online.com/micro-controllers/28100-speedometer.html | ||||
| Posted By | For | Type | Date | |
| Anyone make their own top gear indicator? - Page 8 - Stromtrooper.com | This thread | Refback | 21st May 2008 09:22 PM | |
| Anyone make their own top gear indicator? - Page 8 - Stromtrooper.com | This thread | Refback | 21st May 2008 04:11 AM | |
| Anyone make their own top gear indicator? - Page 8 - Stromtrooper.com | This thread | Refback | 20th May 2008 04:52 AM | |
| RENAULT 9-11 KULÜBÜ - Dijital km göstergesi ? | This thread | Refback | 18th May 2008 12:36 PM | |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| digital speedometer using AT90S2313 | fever | Micro Controllers | 57 | 29th January 2008 07:45 PM |
| Speedometer Project Help | ADAM117 | Electronic Projects Design/Ideas/Reviews | 2 | 8th December 2006 06:00 PM |
| Pulse divider for a Speedometer | spestis | Electronic Projects Design/Ideas/Reviews | 3 | 25th July 2006 03:17 AM |
| Tachometer and Speedometer replies | Kiko | Micro Controllers | 0 | 26th April 2004 01:57 AM |
| Electronic Speedometer using stepper motor | roryp | General Electronics Chat | 6 | 10th April 2003 01:06 PM |