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

    Quote Originally Posted by cncmachineguy View Post
    The number of instructions in your int routine does not matter as long as it doesn't take more then the amount of time to re interupt. I am guessing your int fires every sec (sec=sec+1). So there is plenty of time. What does matter is the time between the interupt firing and the time your routine is actually entered.This number may well be the difference here. What happens is this:
    The interupt fires (you think 1 sec has passed or whatever your time base is)
    context gets saved
    PBP variables get saved (depends on how you set up DT_INT)
    and finally you enter interupt routine.

    The above can take from 20 - 70 fosc/4 so that could be the out of sync.

    Also I don't see where you re-load the timer, Does it just free run and interupt on each rollover? If so the above information prolly IS NOT relevant. As a side note, you could update all the counters within your main code, just set a flag in the interupt so main can see one has occured.
    There is always something new you learn in this forum.
    1) Do you mean that once interrupt happens, the timer actually is still running even when interrupt routine is being executed? So, if this is the case, is it advisable to reload the timer straight away after entering the ISR instead of towards the end?
    2)".....Depends on how you set up DT_INT" - Is there more than one way to use DT_INT?
    The complete INT routine is below:
    Code:
    T1CON=%00001010 ; Timer 1 settings towards the beginning of the code
    counting:
    	if a=0 then
    		LCDOUT $FE,2,"Day",DEC days,"  ",DEC2 hrs,":",DEC2 minu,":",DEC2 sec
    	endif
    	if done=1 then
    		if a=0 then LCDOUT $FE,$C0,"ON",DEC2 hron,":",DEC2 minon," ","OFF",DEC2 hroff,":",DEC2 minoff
    		if  hron=hrs & minon=minu then PortA.5=1
    		if  hroff=hrs & minoff=minu then PortA.5=0
    	endif
         		sec=sec+1
    			if sec =60 then
    				sec=0
    				minu=minu+1
    					if minu=60 then
    						minu=0
    						hrs=hrs+1
    							if hrs=24 then
    								hrs=0
    								days=days+1
    									if days=8 then
    										days=1
    									endif
    							endif
    					endif
    			endif
    TMR1L=0
    TMR1H=128
    @ INT_RETURN
    I thought about doing what you said(set flag in the INT), but it will not be possible because when code leaves the main and enters other sub functions, the counter updates will be missed.
    Upto now I was simulating my PIC on a 4MHz clock, just to check if the code was working fine. I just ran into a new problem now when I switch onto 32.768kHz as operating frequency, my simulation has just stopped. LCD screen has gone blank.
    ___________________
    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

    There's the problem ...
    Code:
    TMR1L=0
    TMR1H=128
    @ INT_RETURN
    By the time it gets all the way through the interrupt handler, another tick or two may have been counted by Timer1.
    That gets lost when you reload both bytes of the Timer.

    For 32768 crystals, the reload is really simple ...
    Code:
    TMR1H.7 = 1
    And it's best to put it at the beginning of the handler.
    Although in your case, the handler is fast enough it won't matter were it is.
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    There's the problem ...
    Code:
    TMR1L=0
    TMR1H=128
    @ INT_RETURN
    By the time it gets all the way through the interrupt handler, another tick or two may have been counted by Timer1.
    That gets lost when you reload both bytes of the Timer.

    For 32768 crystals, the reload is really simple ...
    Code:
    TMR1H.7 = 1
    And it's best to put it at the beginning of the handler.
    Although in your case, the handler is fast enough it won't matter were it is.
    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?
    ___________________
    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

    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

  5. #5


    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 02:03. Reason: Updated info
    ___________________
    WHY things get boring when they work just fine?

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

  7. #7


    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?

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