Timers using Pic16F819


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2004
    Posts
    81

    Default Timers using Pic16F819

    Please forgive me if this all has been covered before, Ive tried searching and just cant seem to find the answer I need...

    Here is the Problem I need to solve: I am building an electronic odometer. The specs for the vehicle in question say that there are 4000 pulses from the speed sensor per mile. So I need to count pulses some how. Because the PIC is going to be sending out serial information (the odometer reading) to VFD, I want to be sure that I do not miss any pulse counts so instead of using code to poll a pin I am guessing using the Timer1 as a counter is what would work best. Is this right?


    If that is right, then how do I scale the timer so that it rolls over at 4000 counts and sets the interupt flag?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Clock (Pulse) Input is on RB6, T1OSC must be disabled. See Figure 7-2.

    T1CON=%00000111

    See Register 7-1 as to why.

    TMR1 will interrupt when it rolls from $FFFF thru to $0000, so for 4000 counts preset the counter (Registers TMR1H & TMR1L) with $F060 ($0000-$0FA0). That means you'll get 4000 counts ($0FA0 Counts) before it interrupts.

    Your Interrupt Service Routine must reset TMR1 back to $F060 after each interrupt (as well as resetting the appropriate interrupt Flag)..

    I’ll let you sort out the configuration of INTCON (see section 12-10, INTCON Register 2-3, PIE1 Register 2-4 and PIR1 register 2-5) – after all, you’ve got to do something…

    Tip: If you interrupt every 400 rather than every 4000 counts, you'll be able to count increments of tenths of a mile - not just miles.

    Depending on the latency of your program, several pulses may have been counted after an interrupt has been generated before you get around to servicing the interrupt. Use a similar technique to that described in the Olympic Timer example to account for the extra pulses so none get missed.

    Melanie

  3. #3
    Join Date
    May 2004
    Posts
    81


    Did you find this post helpful? Yes | No

    Smile

    Thanks so very much. Being I'm some what new to the MCU world Im just not always sure Im reading the data sheets right (when I even understand what Im reading)

Similar Threads

  1. Timers
    By mitchf14 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th November 2008, 20:08
  2. Reading Timers
    By kevj in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th August 2007, 08:19
  3. Timers have me beat
    By Doormatt in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th June 2007, 14:05
  4. hardware timers
    By Adam in forum General
    Replies: 3
    Last Post: - 7th March 2007, 00:10
  5. Availability of PIC timers from PBP
    By coda64 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th February 2006, 07:18

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