PDA

View Full Version : counter command



amateurtje
- 21st August 2008, 20:18
Hello

I am new here and experimenting with a Speedometer, a tachometer, a gear indication and meter counter. at the moment I am still using the 16F628.

The first 3 I have done. The speedometer and the tachometer is based on the pulsin command. I take Pulsin low and pulsin high, count them together (time of 1 complete puls)and do some calculations. Works perfect. Now if the car is in a specific gear, these two times are in a constant pase and trough a division I know the gear.

To minimise the influence of misreads, I loop this 3 times before displaying. hereby my code, below please find my problem:


For i =0 To 2
; Tachometer
VAR1 = PulsIn RPMPoort , Laag
VAR2 = PulsIn RPMPoort , Hoog
TPL = (VAR1 * TPP) + (VAR2 * TPP); TPL total puls length

DwordTemp=(60000000 / N) * X ;Delen door TPL want is de tijd van de puls
DwordTemp = DwordTemp/TPL
Toeren[i]= DwordTemp ; 3 readings before displaying

; speedometer
VAR1 = PulsIn KmPoort , Laag
VAR2 = PulsIn KmPoort , Hoog
TPLkm = (VAR1 * TPP) + (VAR2 * TPP)

DwordTemp = (3600 / APPO)
Snelheid[i] = DwordTemp * OVW/TPLkm ; again three speeds

;Gear indicator
Indicatie = 300000 * TPLkm / TPL ;

; Meter counter
TempTeller =Counter KmPoort,2000
TempTeller = (TempTeller/APPO)*OVW
Teller = Teller + TempTeller /1000

Select Indicatie
Case (95 * V1 * Diff) To (105 * V1 * Diff) ; gear ratios +- 5%
versnellingstemp[i] = 1
Case (96 * V2 * Diff) To (104 * V2 * Diff)
versnellingstemp[i] = 2
Case (97 * V3 * Diff) To (103 * V3 * Diff)
versnellingstemp[i] = 3
Case (98 * V4 * Diff) To (102 * V4 * Diff)
versnellingstemp[i] = 4
Case (99 * V5 * Diff) To (101 * V5 * Diff)
versnellingstemp[i] = 5
Case Else
versnellingstemp[i] = 10 ;Extra value when clutch is active

EndSelect
If versnellingstemp[0]=versnellingstemp[1] Then ; If three times indication is the same then display it against blinking misreads
If versnellingstemp[1]=versnellingstemp[2] Then
Versnelling = versnellingstemp[1]
EndIf
EndIf

Next

DwordTemp = (Snelheid[0]+ Snelheid[1]+ Snelheid[2])
DwordTemp = (DwordTemp )/3
Snelheid1 =DwordTemp ; taking avarage speed
DwordTemp = (Toeren[0]+ Toeren[1]+ Toeren[2])
DwordTemp = (DwordTemp)/3
Toeren1 = DwordTemp
GoSub Weergeven ; goto display routine


Now I used inbetween a counter for counting the total amount of meters driven (tripmeter). The problem is that he stays in this and therefore makes the program very slow. probably when the program is somewhere else it does not count.

Should I use an interrupt with tmr0,1,2? does this work with the pulsin commands? For the counter I can not afford to loose/miss counts (too much) while it needs to be accurate. Secondly I am using at this moment another input pin for this signal, what I can change if really necessary of course.

Anybody a good idea?

Amateurtje

skimask
- 21st August 2008, 20:24
Are you sure you've got the right forum?
I don't think these lines will compile and run correctly using PicBasicPro...


VAR1 = PulsIn RPMPoort , Laag
VAR2 = PulsIn RPMPoort , Hoog
...........
VAR1 = PulsIn KmPoort , Laag
VAR2 = PulsIn KmPoort , Hoog
...........
Case (95 * V1 * Diff) To (105 * V1 * Diff) ; gear ratios +- 5%
versnellingstemp[i] = 1
Case (96 * V2 * Diff) To (104 * V2 * Diff)
versnellingstemp[i] = 2
Case (97 * V3 * Diff) To (103 * V3 * Diff)
versnellingstemp[i] = 3
Case (98 * V4 * Diff) To (102 * V4 * Diff)
versnellingstemp[i] = 4
Case (99 * V5 * Diff) To (101 * V5 * Diff)
versnellingstemp[i] = 5
.............

amateurtje
- 21st August 2008, 20:45
hi,

Thanks for the reply. Maybe not, but I thought that I needed to be here. This is code from the Crownhill proton IDE developer. I see now I need to be on the proton picbasic forum.

Sorry for the inconvenience..