counter command


Closed Thread
Results 1 to 3 of 3

Thread: counter command

Hybrid View

  1. #1
    Join Date
    Aug 2008
    Posts
    2

    Cool counter command

    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

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Are you sure you've got the right forum?
    I don't think these lines will compile and run correctly using PicBasicPro...
    Code:
    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
    .............

  3. #3
    Join Date
    Aug 2008
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    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..

Similar Threads

  1. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  2. Sony LanC Program
    By l_gaminde in forum Code Examples
    Replies: 2
    Last Post: - 25th September 2009, 18:51
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Can I do this???
    By noobie in forum mel PIC BASIC
    Replies: 2
    Last Post: - 10th June 2006, 18:57

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts