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

    Quote Originally Posted by financecatalyst View Post
    I did TMR1H.7=1, but the code is not entering the interrupt. I checked it with changing it to TMR0, it works. Am I making a mistake in setting up timer1?
    T1CON=%00001010 ; Timer 1 settings towards the beginning of the code

    You might want to turn the Timer ON.
    DT

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Sorry Darrel, I put Timer1 On now, but the problem is still there.

    T1CON=%00001011
    Further investigation revealed that this bit is the problem. Looks like in the simulation software I need to look into crystal setup again. I tried with this bit cleared and it worked fine.
    Last edited by financecatalyst; - 19th December 2010 at 03:03. Reason: Updated info
    ___________________
    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

    With that bit cleared, Timer1 is clocked from FOSC/4 instead of the Timer1 oscillator.

    What simulator are you using?
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default

    I am using Proteus 6.9 (which I am also new to).
    Screenshot of the setup is attached.
    It is not working with external clock settings on timer 1
    I tried changing capacitor values, crystal values but no response.
    Attached Images Attached Images  
    ___________________
    WHY things get boring when they work just fine?

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


    Did you find this post helpful? Yes | No

    Default

    Hmmm, apparently the Timer1 oscillator doesn't work.

    Instead ... exclude the crystal and caps from the simulation, and add a clock generator on the T1OSI input.



    Set it up like this.

    DT

  6. #6


    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?

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

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