Elapsed timer data storage
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2016
    Posts
    51

    Default Elapsed timer data storage

    Hello,
    I try to create a simple milliseconds counter with DT Elapsed timer. The program works as follows: after initial countdown starts the timer, next if I press the "mic" button the "lap or split" time is shown on display and the count value is increment by one after each press.
    Code:
    '****************************************************************
    '*  Name    : timer                                             *
    '*  Author  : louis                                             *
    '*  Notice  : Copyright (c)                                     *
    '*          : All Rights Reserved                               *
    '*  Date    : 24. 2. 2019                                       *
    '*  Version : 1.0                                               *
    '*  Notes   : PIC16F1829                                        *
    '****************************************************************
      
    #CONFIG
    cfg= _FOSC_INTOSC
    cfg&= _WDTE_OFF
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_OFF
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _CLKOUTEN_OFF
    cfg&= _IESO_OFF 
    cfg&= _FCMEN_OFF
    #ENDCONFIG
    
    wsave   VAR BYTE    $70     SYSTEM      ' alternate save location for W 
      
    include "DT_INTS-14.bas"            'Needs to be in same PBP folder as PBPW.EXE 
    include "ReEnterPBP.bas"            'Needs to be in same PBP folder as PBPW.EXE
    include "ElapTimer_Interrupt.pbp"   'Needs to be in same PBP folder as PBPW.EXE
    
    DEFINE OSC 8     ; Use a 8 MHZ internal clock 
    OSCCON = %01110000
    CLKRCON = 0
    APFCON0 = 0   
    APFCON1 = 0
    CM1CON0 = 0
    
    CCP1CON = %00000000
    CCP2CON = %00000000
    ANSELA = %00000000
    ANSELB = %00000000
    ANSELC = %00000000
    TRISA = %000000
    TRISB = %11100000      
    TRISC = %00000000
    CM1CON0 = 0       ; Disable comparator 1
    CM2CON0 = 0       ; Disable comparator 2 
    OPTION_REG.6=0
    OPTION_REG.7=1
    
    Define LCD_DREG PORTC
    Define LCD_DBIT 0
    Define LCD_RSREG PORTC
    define LCD_RSBIT 4
    define LCD_EREG PORTC 
    define LCD_EBIT 5 
    define LCD_BITS 4
    define LCD_LINES 2
    define LCD_COMMANDUS 2000
    define LCD_DATAUS 50
    
    ent var portb.5
    res var portb.6
    mic var portb.7
    flag var bit
    shot var byte
    countd var byte 
    aray var byte
    
    ' Define and Create the Instant Interrupt for Timer1
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
        endm
    
        INT_CREATE            ; Creates the interrupt processor
    
        INT_ENABLE  TMR1_INT  ; Enable Timer 1 Interrupts  
    ENDASM
    zzac:
    flag = 0
    shot = 0
    countd = 2
    
    LCDout $FE, $80, " Timer  "
    LCDout $FE, $C0, " ENTER  "
    zac:
    if ent = 0 then 
    LCDOut $FE,1
    goto odpocet
    endif
    goto zac
    odpocet:
    countd = countd - 1
    LCDout $FE, $80, "CNT:" , dec2 countd
    pause 1000
    if countd = 1 then goto start
    goto odpocet
    
    
    start:
    Gosub ResetTime           ' Reset Time to  0d-00:00:00.000
    Gosub StartTimer          ' Start the Elapsed Timer
    
    main:
        if MSecsChanged = 1 then
            MSecsChanged = 0
            LCDout $FE, $80, dec2 Minutes, ":",dec2 Seconds, ".", dec2 MSecs        
        endif
        if mic = 1 then flag = 1
           if mic = 0 and flag = 1 then
              shot = shot + 1
               lcdout $FE, $C0 + 3, dec2 Seconds, ".", dec2 MSecs
            flag = 0
        endif
    LCDout $FE, $C0, dec2 shot
    if res = 0 then 
        shot = 0
          lcdout $FE, $C0 + 3, dec2 Seconds, ".", dec2 MSecs
           gosub resettime
            countd = 2
        goto zzac
    endif
    if ent = 0 then 
    gosub stoptimer
    goto showdata
    endif
    GOTO Main
    
    showdata:
    LCDout $FE, $80, "Saved DT" 
    lcdout $FE, $C0, dec2 shot," ", dec2 Seconds, ".", dec2 MSecs
    if res = 0 then goto zzac
    goto showdata
    Thats works fine, but I want to store each "lap time" if i press the mic button and from this stored data calculate the split time between each press.
    I try some variation with arrays, but no success.
    Then I write this primitive attempt which stores five presses and calculate the splits.
    Code:
    '****************************************************************
    '*  Name    : timer                                             *
    '*  Author  : Louis                                             *
    '*  Notice  : Copyright (c)                                     *
    '*          : All Rights Reserved                               *
    '*  Date    : 24. 2. 2019                                       *
    '*  Version : 2.0                                               *
    '*  Notes   : PIC16F1829                                        *
    '****************************************************************
      
    #CONFIG
    cfg= _FOSC_INTOSC
    cfg&= _WDTE_OFF
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_OFF
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _CLKOUTEN_OFF
    cfg&= _IESO_OFF 
    cfg&= _FCMEN_OFF
    #ENDCONFIG
    
    wsave   VAR BYTE    $70     SYSTEM      ' alternate save location for W 
      
    include "DT_INTS-14.bas"            'Needs to be in same PBP folder as PBPW.EXE 
    include "ReEnterPBP.bas"            'Needs to be in same PBP folder as PBPW.EXE
    include "ElapTimer_Interrupt.pbp"   'Needs to be in same PBP folder as PBPW.EXE
    
    DEFINE OSC 8     ; Use a 8 MHZ internal clock 
    OSCCON = %01110000
    CLKRCON = 0
    APFCON0 = 0   
    APFCON1 = 0
    CM1CON0 = 0
    
    CCP1CON = %00000000
    CCP2CON = %00000000
    ANSELA = %00000000
    ANSELB = %00000000
    ANSELC = %00000000
    TRISA = %000000
    TRISB = %11100000      
    TRISC = %00000000
    CM1CON0 = 0       ; Disable comparator 1
    CM2CON0 = 0       ; Disable comparator 2 
    OPTION_REG.6=0
    OPTION_REG.7=1
    
    
    Define LCD_DREG PORTC
    Define LCD_DBIT 0
    Define LCD_RSREG PORTC
    define LCD_RSBIT 4
    define LCD_EREG PORTC 
    define LCD_EBIT 5 
    define LCD_BITS 4
    define LCD_LINES 2
    define LCD_COMMANDUS 2000
    define LCD_DATAUS 50
    
    ent var portb.5
    res var portb.6
    mic var portb.7
    flag var bit
    shot var byte
    countd var byte
    shot1 var word
    shot2 var word
    shot3 var word
    shot4 var word 
    shot5 var word
    shot11 var word
    shot22 var word
    shot33 var word
    shot44 var word 
    shot55 var word 
    sp1 var word  
    sp2 var word 
    sp3 var word 
    sp4 var word 
    sp5 var word 
    ssp1 var word  
    ssp2 var word 
    ssp3 var word 
    ssp4 var word 
    ssp5 var word 
    shot1 =0
    shot2 =0
    shot3 =0
    shot4 =0
    shot5 =0
    shot11 =0
    shot22 =0
    shot33 =0
    shot44 =0 
    shot55 =0     
    
    ' Define and Create the Instant Interrupt for Timer1
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
        endm
    
        INT_CREATE            ; Creates the interrupt processor
    
        INT_ENABLE  TMR1_INT  ; Enable Timer 1 Interrupts  
    ENDASM
    
    zzac:
    flag = 0
    shot = 0
    countd = 2
    shot1 =0
    shot2 =0
    shot3 =0
    shot4 =0
    shot5 =0
    shot11 =0
    shot22 =0
    shot33 =0
    shot44 =0 
    shot55 =0  
    LCDout $FE, $80, " Timer  "
    LCDout $FE, $C0, "ENT / GO"
    zac:
    if ent = 0 then 
    LCDOut $FE,1
    goto odpocet
    endif
    goto zac
    odpocet:
    countd = countd - 1
    LCDout $FE, $80, "GO:" , dec2 countd
    pause 1000
    if countd = 1 then goto start
    goto odpocet
    
    
    start:
    Gosub ResetTime           ' Reset Time to  0d-00:00:00.000
    Gosub StartTimer          ' Start the Elapsed Timer
    
    main:
        if MSecsChanged = 1 then
            MSecsChanged = 0
            LCDout $FE, $80, dec2 Minutes, ":",dec2 Seconds, ".", dec2 MSecs
        endif
        if mic = 1 then flag = 1
        if mic = 0 and flag = 1 then
        shot = shot + 1
        lcdout $FE, $C0 + 3, dec2 Seconds, ".", dec2 MSecs
         if shot = 1 then shot11 = msecs  
        if shot = 1 then shot1 = seconds 
         if shot = 2 then shot22 = msecs 
        if shot = 2 then shot2 = seconds
         if shot = 3 then shot33 = msecs  
        if shot = 3 then shot3 = seconds
         if shot = 4 then shot44 = msecs  
        if shot = 4 then shot4 = seconds
         if shot = 5 then shot55 = msecs  
        if shot = 5 then shot5 = seconds 
        flag = 0
        endif
    LCDout $FE, $C0, dec2 shot
    if res = 0 then 
    shot = 0
    lcdout $FE, $C0 + 3, dec2 Seconds, ".", dec2 MSecs
    gosub resettime
    countd = 6
    goto zzac
    endif
    if ent = 0 then 
    gosub stoptimer
    goto showdata
    endif
    goto main
    
    showdata:
    pause 300
    lo0:
    lcdout $FE, $C0,"01 ", dec2 shot1, ".", dec2 shot11
    sp1=(shot1*100) + (shot11-((shot11/100)*100))
    ssp1=sp1
    LCDout $FE, $80, "sp      " 
    lcdout $FE, $80,"sp ", dec2 ssp1/100,"." ,dec2 ssp1//100
    lo1:
    if ent = 0 then 
    pause 200
    goto lo2
    endif
    if res = 0 then goto zzac
    goto lo1
    
    lo2:
    lcdout $FE, $C0,"02 ", dec2 shot2, ".", dec2 shot22
    sp2=(shot2*100) + (shot22-((shot22/100)*100))
    ssp2=sp2-sp1
    LCDout $FE, $80, "sp      " 
    lcdout $FE, $80,"sp ", dec2 ssp2/100,"." ,dec2 ssp2//100
    llo2:
    if ent = 0 then 
    pause 200
    goto lo3
    endif
    if res = 0 then goto zzac
    goto llo2
    
    lo3:
    lcdout $FE, $C0,"03 ", dec2 shot3, ".", dec2 shot33
    sp3=(shot3*100) + (shot33-((shot33/100)*100))
    ssp3=sp3-sp2
    LCDout $FE, $80, "sp      " 
    lcdout $FE, $80,"sp ", dec2 ssp3/100,"." ,dec2 ssp3//100
    llo3:
    if ent = 0 then 
    pause 200
    goto lo4
    endif
    if res = 0 then goto zzac
    goto llo3
    
    lo4:
    lcdout $FE, $C0,"04 ", dec2 shot4, ".", dec2 shot44
    sp4=(shot4*100) + (shot44-((shot44/100)*100))
    ssp4=sp4-sp3
    LCDout $FE, $80, "sp      " 
    lcdout $FE, $80,"sp ", dec2 ssp4/100,"." ,dec2 ssp4//100
    llo4:
    if ent = 0 then 
    pause 200
    goto lo5
    endif
    if res = 0 then goto zzac
    goto llo4
    
    lo5:
    lcdout $FE, $C0,"05 ", dec2 shot5, ".", dec2 shot55
    sp5=(shot5*100) + (shot55-((shot55/100)*100))
    ssp5=sp5-sp4
    LCDout $FE, $80, "sp      " 
    lcdout $FE, $80,"sp ", dec2 ssp5/100,"." ,dec2 ssp5//100
    llo5:
    if ent = 0 then 
    pause 200
    goto lo0
    endif
    if res = 0 then goto zzac
    goto llo5     
    
    GOTO showdata
    Can someone explain me the better way to do this, how to store and read this data in arrays maybe.
    Thanks,
    Louis

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    1,603

    Default Re: Elapsed timer data storage

    This is more entertaining than Free to Air TV

Similar Threads

  1. DT Elapsed Timer
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th December 2017, 00:21
  2. Elapsed Timer findings
    By Art in forum General
    Replies: 40
    Last Post: - 18th June 2015, 19:14
  3. data storage label
    By MINHLE in forum General
    Replies: 6
    Last Post: - 17th December 2009, 15:04
  4. DT Elapsed Timer
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th March 2008, 00:17
  5. data storage prior to use, whats the best way here?
    By enigma in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 4th February 2007, 15:31

Members who have read this thread : 16

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