Making a timer, 32.768kHz+555+DT_INT. Good idea?


Closed Thread
Results 1 to 38 of 38

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    The timer continues counting no matter what the program is doing.

    And yes, it does take time to save all the PBP system registers before it gets to the interrupt handler.
    But that has no affect on the reload value.

    Your problem before was that you were overwriting the timers value with TMR1L = 0.

    Here is the program I used with the Digital Clock Generator shown above, and it does keep perfect time.
    Code:
    ;--------------------------------------------------------------
    wsave        VAR BYTE $70 SYSTEM
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ; Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,    Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,   _Clock,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE   TMR1_INT     ; enable external (INT) interrupts
    ;--------------------------------------------------------------
    Sec          VAR BYTE
    Minute       VAR BYTE
    Hour         VAR BYTE
    SecChanged   VAR BIT
    
    ;--------------------------------------------------------------
    ADCON1 = 7
    TMR1L = 0
    TMR1H = $80
    T1CON = %00001011
    PAUSE 250
    LCDOUT $FE,1
    
    ;--------------------------------------------------------------
    Main:
        IF SecChanged THEN
            SecChanged = 0
            LCDOUT $FE,$80, DEC2 Hour,":",DEC2 Minute,":",DEC2 Sec 
        ENDIF
    GOTO Main
    
    ;--------------------------------------------------------------
    Clock:
        TMR1H.7 = 1
        Sec = Sec + 1
        SecChanged = 1
        IF Sec = 60 THEN Sec = 0 : Minute = Minute + 1
        IF Minute = 60 THEN Minute = 0 : Hour = Hour + 1
        IF Hour = 24 THEN Hour = 0
    @ INT_RETURN
    DT

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Thank you very much Darrel. Surely learnt something new in this project.

    So, even when variables are getting saved before entering ISR, only lower bit of timer one is getting incremented in that time. Previously I was resetting it again to '0', which I shouldn't do and let it increment to keep it in sync. BUT it does not reach to higher bit of timer1 in such short time, so we only put TMR1H.7=1, which keep everything simple and in sync.

    That is why you also said that in my code it does not matter if that statement is in the beginning of the code or end, because the increment does not reach that higher value even after executing some statements in my ISR.

    Got it now (Atleast I hope I have this concept cleared FOREVER)
    ___________________
    WHY things get boring when they work just fine?

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


    Did you find this post helpful? Yes | No

    Default

    Excellent!

    Now you really have "Got It".
    And described it well.

    Cheers,
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default Some final problems!

    I made my circuit on my breadboard. It works kind of OK (INT are longer than 1 sec intervals) with TICON=%00001111 the clock still keeps incrementing even when I take out the 32KHz crystal from RC0-RC1.

    The clock stops with
    TICON=%00001011, seems Interrupts stop happening with this setting. Can someone please put some light on why this could be happening?
    ___________________
    WHY things get boring when they work just fine?

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Anyone? Should I start a new thread with this problem?
    ___________________
    WHY things get boring when they work just fine?

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Maybe??
    Do you have the Watchdog turned off?
    Dave
    Always wear safety glasses while programming.

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Maybe??
    Do you have the Watchdog turned off?
    Observations:
    Watchdog is OFF.I just tried it with 4MHz oscillator, everything works fine. Intervals are 1 sec as expected. I took out the 32kHz crystal while PIC was working, it suddenly increased the speed of counting seconds(I WAS EXPECTING IT TO STOP ENTERING IN ISR) i.e. interrupts started happening a little faster. I inserted the crystal back in, the speed became ideal i.e. 1 sec interrupts.
    Two questions now please:
    1) Why didn't the Interrupts Stopped when I took the crystal out?
    2) Why things get slow when I use 32768 Hz crystal as an oscillator for the PIC as well as the timer? 4MHz for PIC increases the current consumption to 2.5mA which is criminal when running on batteries.
    ___________________
    WHY things get boring when they work just fine?

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