Adding a Value to Timer1


Closed Thread
Results 1 to 1 of 1
  1. #1
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343

    Question Adding a Value to Timer1

    I’ve got a couple of questions about adding a value to a timer (particularly TMR1 on the 18F4620). Looking in the datasheet for examples or info only yielded a case of setting bit 7 of TMR1H while it was running. This was not very helpful in my case. (If I missed something in the datasheets, point me in the right direction!)

    Here is the code I am looking at:
    Code:
        bcf		T1CON,TMR1ON	;  Turn off timer
        movlw	LOW(TimerConst)	;  1 instruction cycle
        addwf	TMR1L,F		;  1 instruction cycle
        movlw   	HIGH(TimerConst);  1 instruction cycle
        addwfc	TMR1H,F		;  1 instruction cycle
        bsf		T1CON,TMR1ON	;  1 instruction cycle - Turn TIMER1 back on

    1) Do I need to really need to stop the timer first?
    2) If I do stop the timer, do I need to account for the instructions starting and/or stopping the timer? If so, do I add 5 or 6 to TimerConst?

    My guess is yes, I need to stop the timer, or else on execution of the add, I will loose 1 increment of the timer (probably only with the add to TMR1L though). Also, I need to add 5 to TimerConst to account for all the instruction cycles between turning the timer off and on.
    I was also thinking I could get away with keeping the timer running, and just add 1 to TimerConst to account for a lost cycle. Not knowing for sure exactly how the the add and timer increment will interact, I just don't know how well this will work.

    BTW, this code taken from the elapsed timer demo in Darrel Taylor’s Instant Interrupts (credit where credit is due, thanks Darrel).

    Steve
    Last edited by SteveB; - 6th June 2006 at 17:11.

Similar Threads

  1. Software PWM using Timer1
    By muqasim in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2009, 11:49
  2. Help with TIMER1 + SLEEP
    By Yodoad in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd May 2009, 15:07
  3. Time Period of Timer1
    By arnol34 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th May 2007, 00:31
  4. Timer1 and Interupt wierdness
    By mind in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 23rd August 2005, 01:24
  5. Use of Timer1 with 16F819
    By Barry Johnson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th January 2005, 16:25

Members who have read this thread : 1

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