Sputnik said:Sorry, I think I got it. its in KILOMETERS, I was doing it for METERS
Should it be calculated for DIAMETER or CIRCUMFERENCE of the wheel??
Kiko said:In your case.
22in wheel diameter = 69.1152in circunference (2*PI*R)
69.1152in = 0.001755526Km
0.001755526Km * 3600 = 6,3198936
Temp_Float=(Temp_Float*4)*6,3198936
In the example above the number 4 multiple by counter period (250 or 1/4 of seconds)
You have to multiple by 3600 because you have Km/sec and you want Km/h
WheelDiam = 25
WheelCirc = 2 * 3.14 * WheelDiam / 2
Wheelkilo = WheelCirc * 2.54e-5
WheelConv = WheelKilo * 3600
Device 16F877
Declare XTAL 20
ALL_DIGITAL = TRUE
' LCD DEFINES
Declare LCD_TYPE 0
Declare LCD_DTPIN PORTd.4
Declare LCD_ENPIN PORTd.3
Declare LCD_RSPIN PORTd.2
Declare LCD_INTERFACE 4
Declare LCD_LINES 2
' Speedo Variables **
Dim KMH As Float
DIM MPH AS Float
dim dmph as Byte
Dim Temp_Float As Float
Dim KMHT As DWord
Dim KMH_Last As DWord
DIM WheelDiam as Float
Dim WheelConv as Float
dim WheelCirc as Float
Dim WheelKilo as Float
' Bargraph Variables **
Dim Bar_Val As Byte ' Value to be graphed.
Dim Bars As Byte ' Number of full ||| bars to draw.
Dim Balance As Byte ' Balance left after all |||s are drawn.
Dim Padding As Byte ' Number of spaces to fill width.
Dim Balf As Byte ' Is a 'Balance' character needed? (1=yes, 0=no).
Dim Temp As Byte
' Bargraph Constants **
Symbol B_Wdth = 32 ' Max width in characters of bar.
Symbol Maxbar = B_Wdth * 3 ' Max bar counts.
Symbol Fullbar = 3 ' ASCII value of ||| bar.
Symbol Basebar = 0 ' ASCII value of 0 bar (blank).
Symbol I = 254
Symbol Cgram = 64
' Duplicate Bargraph variable definitions
Dim B_Cnt As Bars ' Counter (0-15) for EEPROM/bit pat load.
Dim B_Row As Balance ' Row of bit pattern.
Dim B_Chr As Padding ' Bit pattern read from EEPROM.
' Alias RTC pins
Dim RST as PORTA.2
Dim IO as PORTC.1
Dim SCLK as PORTC.3
' RTC variables
Dim rtcyear as byte
Dim rtcday as byte
Dim rtcmonth as byte
Dim rtcdate as byte
Dim rtchr as byte
Dim rtcmin as byte
Dim rtcsec as byte
Dim rtccontrol as byte
DIM BTNVAR AS BYTE
dim BTNVAR1 as byte
Main:
DelayMS 500
Cls
Print I,Cgram ' Point to character-generator RAM.
For B_Cnt = 0 to 3
Lookupl B_Cnt,[0,%10000,%10100,%10101],B_Chr ' Get the bit pattern.
Print 0
For B_Row = 1 to 6
Print B_Chr ' Write the pattern to LCD CG RAM.
Next ' Next row
Print 0
Next ' Next Character pattern
Low RST ' Reset RTC
Low SCLK
ADCON1 = 7 ' PORTA and E digital
Low PORTE.2 ' LCD R/W low = write
' Set initial time to 8:00:00AM 07/16/99
rtcyear = $07
rtcday = $06
rtcmonth = $07
rtcdate = $16
rtchr = $11
rtcmin = $16
rtcsec = $56
Gosub settime ' Set the time
TRISC.0 = 1
WheelDiam = 25
StartSpeed:
cls
Print at 1,4, "SuperSpeed"
Print at 2,2, "By: Eric Flynn"
Delayms 1000
CLS
Print At 2,4, "MPh"
KMHT = 0
Start:
WheelCirc = 2 * 3.14 * WheelDiam / 2
Wheelkilo = WheelCirc * 2.54e-5
WheelConv = WheelKilo * 3600
Gosub gettime ' Read the time from the RTC
KMHT = Counter PORTC.0, 250
If KMHT = 0 Then Goto Display
Temp_Float = KMHT
Temp_Float = (Temp_Float * 4) * WheelConv
KMH = Temp_Float / 1000
KMHT = KMH
Display:
If porta.1 = 1 then
Goto SetupWheel
Endif
' If KMH_Last <> KMHT Then
' Print At 1, 1, DEC1 KMHT * 0.6213712
' KMH_Last = KMHT
' EndIf
mph=KMHT * 0.6213712
dmph=mph
if dmph<10 then
Print At 2, 2, " "
Print At 2, 1, " "
Print At 2, 3, DEC dmph
endif
if dmph<100 and dmph>=10 then
Print At 2, 1, " "
Print At 2, 2, DEC dmph
endif
if dmph>=100 then
PRINT AT 2, 1, DEC dmph
endif
Bargraph:
Bars = (dmph min MaxBar) / 6 ' One full bar for each 6 graph units.
Balance = (dmph min Maxbar) //3 ' Balance is the remainder after a division by 3.
Balf = Balance min 1
Padding = B_Wdth - (Bars + Balf) ' Number of spaces to fill bar width.
Print At 1, 1, Rep Fullbar\Bars,Rep (Balance + Basebar)\Balf,Rep " " \Padding
Print At 2, 12, hex2 rtchr, ":", hex2 rtcmin ', ":", hex2 rtcsec
GoTo Start
'write time to RTC
settime:
RST = 1 ' Ready for transfer
' Enable write
shout IO, SCLK, LSBFIRST, [$8e, 0]
RST = 0 ' Reset RTC
RST = 1 ' Ready for transfer
' Write all 8 RTC registers in burst mode
shout IO, SCLK, LSBFIRST, [$be, rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, 0]
RST = 0 ' Reset RTC
Return
'read time from RTC
gettime:
RST = 1 ' Ready for transfer
shout IO, SCLK, LSBFIRST, [$bf] ' Read all 8 RTC registers in burst mode
shin IO, SCLK, LSBPRE, [rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, rtccontrol]
RST = 0 ' Reset RTC
Return
SetupWheel:
cls
Print at 1,1, "Wheel Diam."
repeat
If porta.4 = 1 then
delayms 100
INc Wheeldiam
endif
If porta.5 = 1 then
delayms 100
Dec Wheeldiam
endif
Print at 2,1, dec1 WheelDiam
until porta.3 = 1
Goto StartSpeed
Sputnik said:OK, thanks!! Im not very good at this conversion stuff.
What I want to do is be able to select a wheel diameter from a menu (storing everything in variables) and do all the conversion on-the-fly.
I have this as of now does it look correct to you, (wheel diameter of 25 for example)
Code:WheelDiam = 25 WheelCirc = 2 * 3.14 * WheelDiam / 2 Wheelkilo = WheelCirc * 2.54e-5 WheelConv = WheelKilo * 3600
Here is my complete program. it will display a bargraph representing speed as well as the numeric representation. It also displays the time from a DS1302 RTC. It all works perfectly in Proteus, I just need to make sure I have the conversion stuff correct so it is accurate.
Code:Device 16F877 Declare XTAL 20 ALL_DIGITAL = TRUE ' LCD DEFINES Declare LCD_TYPE 0 Declare LCD_DTPIN PORTd.4 Declare LCD_ENPIN PORTd.3 Declare LCD_RSPIN PORTd.2 Declare LCD_INTERFACE 4 Declare LCD_LINES 2 ' Speedo Variables ** Dim KMH As Float DIM MPH AS Float dim dmph as Byte Dim Temp_Float As Float Dim KMHT As DWord Dim KMH_Last As DWord DIM WheelDiam as Float Dim WheelConv as Float dim WheelCirc as Float Dim WheelKilo as Float ' Bargraph Variables ** Dim Bar_Val As Byte ' Value to be graphed. Dim Bars As Byte ' Number of full ||| bars to draw. Dim Balance As Byte ' Balance left after all |||s are drawn. Dim Padding As Byte ' Number of spaces to fill width. Dim Balf As Byte ' Is a 'Balance' character needed? (1=yes, 0=no). Dim Temp As Byte ' Bargraph Constants ** Symbol B_Wdth = 32 ' Max width in characters of bar. Symbol Maxbar = B_Wdth * 3 ' Max bar counts. Symbol Fullbar = 3 ' ASCII value of ||| bar. Symbol Basebar = 0 ' ASCII value of 0 bar (blank). Symbol I = 254 Symbol Cgram = 64 ' Duplicate Bargraph variable definitions Dim B_Cnt As Bars ' Counter (0-15) for EEPROM/bit pat load. Dim B_Row As Balance ' Row of bit pattern. Dim B_Chr As Padding ' Bit pattern read from EEPROM. ' Alias RTC pins Dim RST as PORTA.2 Dim IO as PORTC.1 Dim SCLK as PORTC.3 ' RTC variables Dim rtcyear as byte Dim rtcday as byte Dim rtcmonth as byte Dim rtcdate as byte Dim rtchr as byte Dim rtcmin as byte Dim rtcsec as byte Dim rtccontrol as byte DIM BTNVAR AS BYTE dim BTNVAR1 as byte Main: DelayMS 500 Cls Print I,Cgram ' Point to character-generator RAM. For B_Cnt = 0 to 3 Lookupl B_Cnt,[0,%10000,%10100,%10101],B_Chr ' Get the bit pattern. Print 0 For B_Row = 1 to 6 Print B_Chr ' Write the pattern to LCD CG RAM. Next ' Next row Print 0 Next ' Next Character pattern Low RST ' Reset RTC Low SCLK ADCON1 = 7 ' PORTA and E digital Low PORTE.2 ' LCD R/W low = write ' Set initial time to 8:00:00AM 07/16/99 rtcyear = $07 rtcday = $06 rtcmonth = $07 rtcdate = $16 rtchr = $11 rtcmin = $16 rtcsec = $56 Gosub settime ' Set the time TRISC.0 = 1 WheelDiam = 25 StartSpeed: cls Print at 1,4, "SuperSpeed" Print at 2,2, "By: Eric Flynn" Delayms 1000 CLS Print At 2,4, "MPh" KMHT = 0 Start: WheelCirc = 2 * 3.14 * WheelDiam / 2 Wheelkilo = WheelCirc * 2.54e-5 WheelConv = WheelKilo * 3600 Gosub gettime ' Read the time from the RTC KMHT = Counter PORTC.0, 250 If KMHT = 0 Then Goto Display Temp_Float = KMHT Temp_Float = (Temp_Float * 4) * WheelConv KMH = Temp_Float / 1000 KMHT = KMH Display: If porta.1 = 1 then Goto SetupWheel Endif ' If KMH_Last <> KMHT Then ' Print At 1, 1, DEC1 KMHT * 0.6213712 ' KMH_Last = KMHT ' EndIf mph=KMHT * 0.6213712 dmph=mph if dmph<10 then Print At 2, 2, " " Print At 2, 1, " " Print At 2, 3, DEC dmph endif if dmph<100 and dmph>=10 then Print At 2, 1, " " Print At 2, 2, DEC dmph endif if dmph>=100 then PRINT AT 2, 1, DEC dmph endif Bargraph: Bars = (dmph min MaxBar) / 6 ' One full bar for each 6 graph units. Balance = (dmph min Maxbar) //3 ' Balance is the remainder after a division by 3. Balf = Balance min 1 Padding = B_Wdth - (Bars + Balf) ' Number of spaces to fill bar width. Print At 1, 1, Rep Fullbar\Bars,Rep (Balance + Basebar)\Balf,Rep " " \Padding Print At 2, 12, hex2 rtchr, ":", hex2 rtcmin ', ":", hex2 rtcsec GoTo Start 'write time to RTC settime: RST = 1 ' Ready for transfer ' Enable write shout IO, SCLK, LSBFIRST, [$8e, 0] RST = 0 ' Reset RTC RST = 1 ' Ready for transfer ' Write all 8 RTC registers in burst mode shout IO, SCLK, LSBFIRST, [$be, rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, 0] RST = 0 ' Reset RTC Return 'read time from RTC gettime: RST = 1 ' Ready for transfer shout IO, SCLK, LSBFIRST, [$bf] ' Read all 8 RTC registers in burst mode shin IO, SCLK, LSBPRE, [rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, rtccontrol] RST = 0 ' Reset RTC Return SetupWheel: cls Print at 1,1, "Wheel Diam." repeat If porta.4 = 1 then delayms 100 INc Wheeldiam endif If porta.5 = 1 then delayms 100 Dec Wheeldiam endif Print at 2,1, dec1 WheelDiam until porta.3 = 1 Goto StartSpeed
Sputnik said:Awesome, I wanted to use a Graphic LCD and use some cool graphics but im not very hip on how to use a GLCD for advanced graphics, just the simple charachter type usage and simple pixel plotting.
I am also integrating a turn signal stop light system into this for use with LED tail lights. I may also integrate sort of an ECU using a pic as a co-processor.
The turn/stop system has been done for a while, just need to integrate it all!!
This way I can have a complete bike computer!!! I may even implement GPS.
Its nice to have someone else who is working on the same thing, we can share ideas!!!
Thanks!!!!!!!!!!!!!!
Girish.krishnaiah said:Hi guys
I am begineer to automotive field...
I am intrested to know what is the kind of signal we get from speed sensors,RPM sensors,gear position sensors?
Are they common with all the automobiles? is there any standard for the same
please let me know any good informative website of the same!!
What is the ECU? which i often here in thread? is the place from where all the sensor signals come out.any useful site to understand automative electronics? please help me on this
Thanks in advance
kris
Kiko said:The project using GLCD is very simple for a while. It just shows speed, RPM e gear position, so I didn't post it yet because I'm having some problems with my GLCD pinout... And I have to learning about everything, because I'm not either an enginner and programmer. So, if you want to make some nice icons to use on GLCD try to use the LCDICONMAKER, it's a nice and easy program to deal with as well as FASTLCD to make some cool graphics. They are all freeware and small programs so I can send it to your e-mail if you want.
gramo said:Hey Kiko, what compiler are you using for your GLCD routines, and what type of PIC programmer do you have?
gramo said:Doh, I wish I coulda told you about the PICKit 2, its only $34.95 from microchip!
Owell, so your using Proton, you have a programmer that can handle 18F PIC's and you look like your getting the grip of things, perhaps your delve into GLCD's might be a bit easier when I put up my Swordfish examples for bitmaps/font's with GLCD's.
Its 'similar' to Proton, but lets you go about things in a modular way. Proton is a very flat 'top down' type of programming, you'll see in a week or two, I'll keep you posted
gramo said:Usally the -Vout Pin on the GLCD is for contrast, your's doesn't have one? Also known as Vee
Sputnik said:Hey Kiko, I tried your code and schematic in ISIS and I cannot get it to display properly!! The splash screen doesnt not show, and when it starts to show the actually working screen it is just a jumble in the lower right corner!!!
What are your LCD settings in ISIS?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?