Totally Baffled with Elapsed Timer


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    It looks like you may have modified the Elapsed.bas file.
    And it's probably interfering with the system variables now.

    Can you show the changes?
    <br>
    DT

  2. #2


    Did you find this post helpful? Yes | No

    Default

    I think I have some other problems lurking in the woodwork. Debugging right now to narrow the search.

    Code:
    '****************************************************************
    '*  Name    : ELAPSED.PBP                                       *
    '*  Author  : Darrel Taylor                                     *
    '*  Notice  : Copyright (c) 2003                                *
    '*  Date    : 12/16/2003                                        *
    '*  Notes   :                                                   *
    '****************************************************************
    
    Define  INTHAND _ClockCount    ' Tell PBP Where the code starts on an interrupt
    Include "ASM_INTS.pbp"         ' ASM Interrupt Stubs
    
        Ticks           var     byte   ' 1/100th of a second
        Seconds         var     byte
        Minutes         var     byte
        Hours           var     byte
        Days            var     word
        AccuTicks       var     word
        AccuSeconds     var     word
        AccuMinutes     var     word
        AccuHours       var     word
        AccuDays        var     word
        R0save          var     word
        R1save          var     word
    
        SecondsChanged  var bit : SecondsChanged = 1
        MinutesChanged  var bit : MinutesChanged = 1
        HoursChanged    var bit
        DaysChanged     var bit
    
    Goto OverElapsed
    
    ' ------------------------------------------------------------------------------
    Asm
      IF OSC == 4                       ; Constants for 100hz interrupt from Timer1
    TimerConst = 0D8F7h                 ; Executed at compile time only
      EndIF
      If OSC == 8
    TimerConst = 0B1E7h
      EndIF
      If OSC == 10
    TimerConst = 09E5Fh
      EndIF
      If OSC == 20
    TimerConst = 03CB7h
      EndIF
      
    ; -----------------  ADD TimerConst to TMR1H:TMR1L
    ADD2_TIMER   macro
        CHK?RP  T1CON
        BCF     T1CON,TMR1ON           ; Turn off timer
        MOVLW   LOW(TimerConst)        ;  1
        ADDWF   TMR1L,F                ;  1    ; reload timer with correct value
        BTFSC   STATUS,C               ;  1/2
        INCF    TMR1H,F                ;  1
        MOVLW   HIGH(TimerConst)       ;  1
        ADDWF   TMR1H,F                ;  1
        endm
    
    ; -----------------  ADD TimerConst to TMR1H:TMR1L and restart TIMER1 
    RELOAD_TIMER  macro
        ADD2_TIMER
        BSF     T1CON,TMR1ON           ;  1    ; Turn TIMER1 back on
        CHK?RP  PIR1
        bcf     PIR1, TMR1IF           ; Clear Timer1 Interrupt Flag
        endm
    
    ; -----------------  Load TimerConst into TMR1H:TMR1L 
    LOAD_TIMER  macro
    EndAsm
        T1CON.0 = 0                    ; Turn OFF Timer1
        TMR1L = 0
        TMR1H = 0
    Asm
        ADD2_TIMER
        endm
    EndAsm
    
    ' ------[ This is the Interrupt Handler ]---------------------------------------
    ClockCount:   ' Note: this is being handled as an ASM interrupt
    @ INT_START                    
    @ RELOAD_TIMER                    ; Reload TIMER1
      R0save = R0                     ; Save 2 PBP system vars that are used during
      R1save = R1                     ; the interrupt
        Ticks = Ticks + 1
        AccuTicks = AccuTicks + 1
        if Ticks = 100 then
           Ticks = Ticks-100
           Seconds = Seconds + 1
           AccuSeconds = AccuSeconds + 1
           SecondsChanged = 1
           if Seconds = 60 then
              Minutes = Minutes + 1
              AccuMinutes = AccuMinutes + 1
              MinutesChanged = 1
              Seconds = 0
           endif
           if Minutes = 60 then
              Hours = Hours + 1
              AccuHours = AccuHours + 1
              HoursChanged = 1
              Minutes = 0
           endif
           if Hours = 24 then
              Days = Days + 1
              AccuDays = AccuDays + 1
              DaysChanged = 1
              Hours = 0
           endif
        endif
      R1 = R1save                     ; Restore the PBP system vars
      R0 = R0save
    @ INT_RETURN                      ; Restore context and return from interrupt
    
    '-----====[ END OF TMR1 Interrupt Handler ]====---------------------------------
    
    StartTimer:
        T1CON.1 = 0                   ; (TMR1CS) Select FOSC/4 Clock Source
        T1CON.3 = 0                   ; (T1OSCEN) Disable External Oscillator
        PIR1.0  = 0                   ; (TMR1IF) Clear Timer1 Interrupt Flag
        PIE1.0  = 1                   ; (TMR1IE) Enable TMR1 overflow interrupt
        INTCON.6 = 1                  ; (PEIE) Enable peripheral interrupts
        INTCON.7 = 1                  ; (GIE) Enable global interrupts
        T1CON.0 = 1                   ; (TMR1ON) Start TIMER1
    return
    
    ; -----------------
    StopTimer:
        T1CON.0 = 0                   ; Turn OFF Timer1
    return
    
    ; -----------------
    ResetTime:
        R0save = T1CON.0              ; Save TMR1ON bit
        T1CON.0 = 0                   ; Turn OFF Timer1
        TMR1L = 0
        TMR1H = 0
    @   LOAD_TIMER                    ; Load TimerConst
        T1CON.0 = R0save              ; Restore TMR1ON bit
        Ticks = 0
        Seconds = 0
        Minutes = 0
        Hours = 0
        Days = 0
        AccuTicks = 0
        AccuSeconds = 0
        AccuMinutes = 0
        AccuHours = 0
        AccuDays = 0
        SecondsChanged = 1
    return
    
    OverElapsed:

  3. #3


    Did you find this post helpful? Yes | No

    Red face

    I figured out the problems, first had the on and off reversed and then somehow forgot the base resistor to the transistor firing the outlet relay, oops. lol

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Great! Glad you found it.

    And just for more info, I compiled the modified elapsed file and everything looks good. It doesn't use any more system vars.

    Cheers,
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default

    The only modification I made to the ELASPED include file was the addition of the Accumulative seconds, minutes, hours and days variables. This allows me to enter 150 seconds instead of 2 minutes 30 seconds. I may get fancy and automatically scale the variables down as they decrease in value, just depends on what code space I will have left over.

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 23:14
  2. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 18:39
  3. Get elapsed time while TIMER samples pulses
    By RodSTAR in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th March 2009, 17:27
  4. Elapsed Timer Demo in a PIC12F675
    By Leonardo in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 21st November 2008, 01:01
  5. Darrel Taylor Elapsed Timer
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th March 2008, 02:22

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