using TMR0 as a counter..


Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108

    Default using TMR0 as a counter..

    Hi! I have two question, can you help me?

    1) I'm using TMR1 as a timer and it ticks every 100ms. Now, I would like to measure an external clock (RPM) (0 - 1000Hz) and display it every 500ms on a LCD display. The extenal source is connected to RA4 and think it is possible to use TMR0 as a counter. The problem is that TMR0 is a 8-bit timer and it counts till 256 until overflow. So, my question is: If I set TMR0 prescaler to 1:4, would it be possible to count 256*4 = 1024 until overflow? I mean, will TMR0 count every 4 external ticks?

    Here is Bruce's TMR0 counter prescaled 1:1 from the forum. It uses interrupt but as my TMR1 ticks every 100ms, i think it's not necessary to interrupt TMR0.

    Code:
    TRISA = %00010000    ' Set PORTA.4 (TOCKI) to input for timer0
    
       OPTION_REG = %00111000 
       'Transition on TOCKI (RA4), 
       'Increment on falling edge
       'Prescalar assigned to WDT for a 1:1 TMR0 ratio.
       INTCON.2 = 0 ' Clear Timer0 int flag
       INTCON.5 = 1 ' Enable Timer0 int
       TMR0 = 0   ' Set TMR0 to 0.
    
       ON INTERRUPT GOTO LapCount
    Main:
       ' Do something here
       goto Main
    
       disable
    LapCount:
       TMR0 = 0      ' Indicate we're in interrupt handler
       INTCON.2 = 0    ' Clear TMR0 Interrupt Flag (Bit 2)
       
       Resume 
       Enable
    2) If a set TMR2 prescaler to 1:256 and set TMR2 = 0, it will interrupt every ~65,5ms (4MHz crystal). I a set the postscaler to 1:16, will it interrupt every 16*65,5ms = 1,048s?

    Thanks in advance.

    Sylvio
    Last edited by sirvo; - 27th July 2007 at 16:57. Reason: added question 2, :)

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. TMR0 as counter
    By savnik in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 31st March 2009, 19:34
  3. help: TMR0 interrupts disabling PORTAchange interrupts???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2008, 15:10
  4. 20 Digit Virtual LED Counter
    By T.Jackson in forum Code Examples
    Replies: 9
    Last Post: - 19th November 2007, 05:02
  5. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27

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