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


Closed Thread
Results 1 to 38 of 38

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Thank you so much for helping me reaching near the completion this project.
    Adding the external clock as per the above image, has not solved the problem, I will need to check it on a real hardware from now on. Few last questions please:
    1) Please explain my earlier question, that as soon as the interrupt happens, what exactly is happening, my understanding upto now says (please correct me if I am wrong):-
    a) Few registers are saved [Which takes some time - Now, I have 15 byte variables, 2 Bit variables & 4 alias for 4 port pins - How do I calculate the exact delay & come up with a value to load into timer1 so I get perfect 1 sec intervals] (my pic is also running on 32.768kHz)
    b) As soon as the first instruction is executed in the ISR, does timer1 keeps the value 0 in it untill ISR is executed in full OR it starts incrementing straightaway regardless if it is in ISR or main code. The latter makes more sense to me as I think thats why you advised to reload it as a first instruction in the ISR.

    Please help me find answers to the above and hence get perfect 1 sec intervals.
    ___________________
    WHY things get boring when they work just fine?

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

  3. #3


    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?

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

  5. #5


    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?

  6. #6


    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?

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

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