PDA

View Full Version : Odo-meter for Knight Rider.



captain nguyen
- 26th July 2008, 16:32
Hi,

I'm new here, and I'm currently convert my car into KITT from Knight Rider.
Some design are ready.
And now I wanted making functional odo meter.

http://i38.tinypic.com/xkn37s.jpg
http://i32.tinypic.com/m7rv2o.jpg

I'm using cyberdyne speedosensor that count 8000 pulse a mile -> 5000 a KM.

I have fount the code and adapted that not count down. only count up.
But how can I change into 5000 pulse a KM.
It's writed in picbasic. (*.bas)
Oh, I'll use PIC16F628 or do you recommend other PIC.
And I use simple RCD programmer. (http://feng3.cool.ne.jp/en/rcd.html)



'************************************************* ***************
'* Author : Coenen Stijn [Stynus] *
'* Notice : Copyright (c) 2008 ElektronicaStynus.be *
'* : All Rights Reserved *
'* Date : 20/07/2008 *
'* Version : 1.8 *
'* Notes : Teller *
'************************************************* ***************
Device 16F628
Config WDT_OFF, PWRTE_OFF, MCLRE_OFF, INTRC_OSC_NOCLKOUT, LVP_OFF, BODEN_ON
ALL_DIGITAL = true
'************************************************* ***************
Symbol Cu = PORTA.0
Symbol noPower = PORTA.4
Symbol digit2 = PORTA.6
Symbol digit3 = PORTA.7
Symbol digit4 = PORTA.5
Symbol digita = PORTB.0
Symbol display = PORTB
Symbol digit1 = PORTB.7
'************************************************* ***************
TRISA = %00111111
TRISB = %00000000
'************************************************* ***************
Dim CuBit As Bit
Dim index As Byte
Dim waarde As Byte
Dim waarde1000 As Byte
Dim waarde100 As Byte
Dim waarde10 As Byte
Dim waarde1 As Byte
'************************************************* ***************
'Init
Clear
DelayMS 1000
'Oude tellerstand terug inlezen
waarde1 = ERead 0
waarde10 = ERead 1
waarde100 = ERead 2
waarde1000 = ERead 3

DelayMS 1000
'************************************************* ***************
While 1 = 1
'************************************************* ***********
'Knoppen inlezen
'Count up
If Cu = 0 And CuBit = 0 Then
Inc waarde1
If waarde1 = 10 Then
waarde1 = 0
Inc waarde10
If waarde10 = 10 Then
waarde10 = 0
Inc waarde100
If waarde100 = 10 Then
waarde100 = 0
Inc waarde1000
If waarde1000 = 10 Then
waarde1000 = 0
EndIf
EndIf
EndIf
EndIf
CuBit = 1
EndIf
If Cu = 1 And CuBit = 1 Then
CuBit = 0
EndIf
GoSub spanningweg
EndIf
'************************************************* ***********
GoSub dispuit
Wend
'************************************************* ***************
'Subroutines
dispuit:
For index = 0 To 3
Select index
Case 0
waarde = waarde1
Case 1
waarde = waarde10
Case 2
waarde = waarde100
Case 3
waarde = waarde1000
EndSelect
Select Case waarde
Case 0 'gfedcba
display = %00111111
Case 1 'gfedcba
display = %00000110
Case 2 'gfedcba
display = %01011011
Case 3 'gfedcba
display = %01001111
Case 4 'gfedcba
display = %01100110
Case 5 'gfedcba
display = %01101101
Case 6 'gfedcba
display = %01111101
Case 7 'gfedcba
display = %00000111
Case 8 'gfedcba
display = %01111111
Case 9 'gfedcba
display = %01101111
'Bij fout
Case Else 'gfedcba
display = %01111001
EndSelect
Select index
Case 0
High digit1
Case 1
High digit2
Case 2
High digit3
Case 3
High digit4
EndSelect
DelayMS 1
GoSub spanningweg
Low digit1
Low digit2
Low digit3
Low digit4
Next
Return
spanningweg:
'Controleren op voedingsspanning
If noPower = 1 Then
EWrite 0 , [waarde1]
DelayMS 20
EWrite 1 , [waarde10]
DelayMS 20
EWrite 2 , [waarde100]
DelayMS 20
EWrite 3 , [waarde1000]
While noPower = 1
DelayMS 1000
Wend
EndIf
Return
'************************************************* ***************
End

skimask
- 26th July 2008, 18:50
You posted this in the 'mel PIC BASIC' forum.
Try this statement:

Proton Basic <> MeLabs PicBasic AND Proton Basic <> MeLabs PicBasicPro

captain nguyen
- 26th July 2008, 19:10
Oh...

Can admin move this threat for me?

skimask
- 26th July 2008, 19:13
Oh...

Can admin move this threat for me?

Can you find the Proton Basic forum section here?

captain nguyen
- 26th July 2008, 19:22
Do you mean "mel PIC BASIC Pro"?
If yes, but how can I move this threat?

skimask
- 26th July 2008, 19:31
Do you mean "mel PIC BASIC Pro"?
If yes, but how can I move this threat?

There is no THREAT here.

Apparently, you are NOT using MeLabs PicBasicPro. You are using PROTON Basic.
Try again.
Or maybe you expect somebody to covert a Proton Basic program to PicBasicPro for you?

Darrel Taylor
- 26th July 2008, 20:17
Or maybe he just doesn't realize the Proton forum is at ...

http://www.picbasic.org/forum
<br>

Archangel
- 26th July 2008, 22:20
Hello Captain,
I'm not fluent even in PBP much less Proton, but here is what I see . . . Looks like you found some code that controls the display for the Odometer, I do not see anything here which does the math of turning 8000 counts into 1 mile. What I do see is this code writes to and reads from the eeprom and displays that on the 7 segment display, you would need to add some math routines to convert. In this case you know 8000 pulses = 1 mile so 8000/1.61 = 4968.944
not quite 5000, rounded up to 4969. Set up a 16 bit timer, preloaded with the difference between 65535 and 4969 and when it overflows you have traveled 1km, you will likely have to adjust that number some to account for "latency" in the pic while you are reloading the number in the timer. Oh, it is THREAD not Threat.

skimask
- 26th July 2008, 23:27
Looks like you found some code that controls the display for the Odometer, I do not see anything here which does the math of turning 8000 counts into 1 mile. What I do see is this code writes to and reads from the eeprom and displays that on the 7 segment display, you would need to add some math routines to convert. In this case you know 8000 pulses = 1 mile so 8000/1.61 = 4968.944
not quite 5000, rounded up to 4969. Set up a 16 bit timer, preloaded with the difference between 65535 and 4969 and when it overflows you have traveled 1km, you will likely have to adjust that number some to account for "latency" in the pic while you are reloading the number in the timer. Oh, it is THREAD not Threat.
I don't think you'd really need any sort of timer unless you were trying to convert the odo input into a speed output. If it's just an odometer pulse input (which we're not even sure if the O/P is able to read that input in the first place), then it is just a simple matter of counting.
If you do know it is actually 8000 pulses per mile, then yes, you are right in that 8000 / 1.61 = 4968.944.
But since PBP can't do fractional numbers, and to add a bit more accuracy...
km_travelled = ( pulses_total * 412 ) / 2048
and to make it execute just a bit faster
km_travelled = ( pulses_total * 103 ) >> 9
Therefore, if you get 8000 pulses,
8000 * 103 / 512 = 1609 = 1.609 kilometers.

Hopefully this user's actual compiler (whether it be Proton or PBP) is capable of LONG (32 bit) variables, because using the above example, this will overflow after 13.18 kilometers. If a 32 bit variable is available, it'll be capable of counting up to 431,912 km's.

captain nguyen
- 27th July 2008, 00:05
Oh sorry I did know now:D

Darrel Taylor
I did just really not know at other site not from this forum....

I'll move to other site....

But thanks to all to explaining me.