Expanding Timer1 counting range


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Location
    Malaysia
    Posts
    20

    Default Expanding Timer1 counting range

    I use Timer1 as a free running timer, using 4Mhz clock and 16F877A MCU. I do not know how to extend the timer range as it is from 0 to 65536 microsecond using 4Mhz clock.

    Can anyone teach me to extend the timer range from 0 to 5 seconds?

    Thanks in advance.
    Last edited by sycluap; - 13th January 2008 at 11:56.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Post

    Hi,

    Hardw.solution : Just use the external TMR1 clock with a 32,768 Hz Xtal ... easily gives 1 count per ms !!!

    SoftW.Solution : increment a variable for each overflow ( interrupts using or polling the overflow bit TMR1IF )

    Also See Darrel's posts about instant interrupts ... The Hardw solution is described here !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Dec 2007
    Location
    Malaysia
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    I am using 4MHZ, 16F877a, Timer1, setting TMR1H = $00 and TMR1L = $00. Tried to activate the timer as free running timer. Previously used to capture the timer time from 0 - 65536 microseconds (full range). Now that I am trying to extend the timer range and to respond to 1ms interval, I change the TMR1H = $FC and TMR1L = $18, with the codes below to capture the timer1 overflow.

    Looping:
    While PIR1.0=0
    Wend
    PIR1.0=0
    TimerOverflow=TimerOverflow+1
    LCDOUT $FE,$C0,DEC5 TimerOverFlow
    If ButStop = 1 Then goto StopTimer
    Goto Looping

    But I am unable to get in 1ms interval. Can anyone guide me on this?

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    You just need to preload Timer 1 with a value "not so far" from 65536 - 1000 ... no more free running timer usable !!!

    it will overflow for 1000 counts = 1 ms ...

    "not so far" mean you have to add the time to reload the timer and do what you want to the "64536" value ...

    See Steve's ( Mr E !!! ) calculator here : http://www.mister-e.org/pages/utilitiespag.html


    I also forgot you could use the "compare" function of the CCP module ... and poll the CCPIF bit !

    Alain
    Last edited by Acetronics2; - 13th January 2008 at 14:26.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Dec 2007
    Location
    Malaysia
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Yeah, I did make TMR1H = $FC, TMR1L=$18, which is obtained from 65536-1000. But the timer does not give me 1ms interval. I do not know what is wrong. Below is my program:

    'MAIN PROGRAM
    '------------
    ResetTimer:
    GoSub SetReg
    LCDOUT $FE, 1
    Timer1H = 0
    Timer1L = 0
    Result = 0
    TimerOverflow = 0

    Main:
    LCDOUT $FE, $80, "Test Mode 1"
    LCDOUT $FE, $C0, "Visual Response Test"
    If ButStart = 1 Then goto StartTimer
    Goto Main

    StartTimer:
    LCDOUT $Fe, 1
    LCDOUT $FE, $80, "Calculating..."
    T1CON.0=1

    Looping:
    While PIR1.0=0
    Wend
    PIR1.0=0
    TimerOverflow=TimerOverflow+1
    LCDOUT $FE,$C0,DEC5 TimerOverFlow
    If ButStop = 1 Then goto StopTimer
    Goto Looping

    StopTimer:
    T1CON.0 = 0
    LCDOUT $Fe, 1
    GoSub GetValue

    DisplayResult:
    Result = TimerOverflow
    LCDOUT $FE,$C0, dec5 Result
    If ButStart = 1 Then goto StartTimer
    If ButReset = 1 Then goto ResetTimer
    goto DisplayResult


    'SUBROUTINES
    '===========
    'Reset Timer1 Register to Start from 1ms interval
    '-------------------------------------------------------
    SetReg:
    TMR1H = $FC
    TMR1L = $18
    Return

    Is there anything wrong with the program that cause the Timer unable to display 1ms interval timing on LCD?
    Last edited by sycluap; - 13th January 2008 at 14:57.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Post

    Your LCD display is unable to show time for EACH ms ... the LCDOUT command needs much more thant 1 ms - OR you should use LED Display ...

    With that way of programming You might have enough time to refresh the display between two interrupts ...

    Here, to be accurate ... you just can display exact time ONLY once timer stopped !!!


    see How Darrel's "Elapsed timer Demo " works ... and you will be able to see "intermediate time"

    http://www.picbasic.co.uk/forum/show...=Elapsed+timer


    Alain

    PS: you can read the ms "on the fly" .... Wooowww !!! you got a fantastic pair of eyes !!!
    LOL ...
    Last edited by Acetronics2; - 13th January 2008 at 16:16.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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. continious counting process (capture)
    By asynch in forum General
    Replies: 1
    Last Post: - 17th February 2006, 07:42
  5. Timer1 and Interupt wierdness
    By mind in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 23rd August 2005, 01:24

Members who have read this thread : 2

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