Timers


Closed Thread
Results 1 to 3 of 3

Thread: Timers

  1. #1
    Join Date
    Jun 2008
    Posts
    30

    Unhappy Timers

    I need some help with the hardware timers I'm using pic16f873 with a 20 MHz crystal, how could i create the same simple program below with a hardware timer i want a 10 second pause in between. The program is very simple example to help me learn to use the timers. thank you


    Start

    portb.2 = 1

    pause 10000

    portb.3 = 1

    End

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    The "generic" way is to

    Figure out the maximum "length" of the timers (use Mr. E's Multi-Calc).
    Pick an appropriate timer and prescaler.
    Figure out what the pre-load count should be for the time interval you need based on the timer, prescaler and oscillator.

    The counter will increment from the pre-load value and when it reaches maximum count (0xFFFF for a 16 bit counter), it will set the timer's overflow flag bit (INTCON.2 in the case of TMR0).

    So to intialize:

    Load the counter with the pre-load count
    clear the timer overflow flag bit
    enable the timer

    Then --

    Code:
    Top_Of_Main_program:
    
    do some stuff here
    
    IF INTCON.2 THEN              ; the bit is set, so overflow has occurred.
        TMR0H = HighByte of preload value
        TMR0L = LowByte of preload value    ; the order is important!
        INTCON.2 = 0                                ; Clear the flag bit
        ;Do what you want here when the timeout value is reached.
    ENDIF
    
    
    Goto Top_Of_Main_program
    Charles Linquist

  3. #3
    Join Date
    Jun 2008
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Thanks

    Thanks for the reply i will try that out.

Similar Threads

  1. Timers and Interrupts
    By senior project1 in forum Off Topic
    Replies: 2
    Last Post: - 25th November 2008, 14:17
  2. Reading Timers
    By kevj in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th August 2007, 08:19
  3. hardware timers
    By Adam in forum General
    Replies: 3
    Last Post: - 7th March 2007, 00:10
  4. Availability of PIC timers from PBP
    By coda64 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th February 2006, 07:18
  5. Count Down Timers
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th October 2005, 17:34

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