Timer1 & array confusion; very new to PBP programming


Results 1 to 9 of 9

Threaded View

  1. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default

    Hi,
    By default the TMR1 "counts" at at fOSC/4 which means that every "tick" is 0.5us when running at 8Mhz. TMR1 is 16bits wide so it will overflow every 2^16*0.5us = 3.2768ms - not very good if you want to measure 1.2s.

    There are several ways of doing what you want:
    * Use the TMR1 prescaler to scale down the rate at which TMR1 is incremented. Unfortunately the highest ratio is 1:8 which means that one tick now equals 4us instead of 0.5 and that the timer will overflow in ~26ms - still not good....

    * Use an external clock source for the TMR1 osc. A 32.768Hz clock x-tal will give you a "tick-rate" of 1mS meaning that the value you get from the TMR1 registers are in ms and that you can measure times up to ~32 seconds.

    * Use the TMR1 interrupt and count the number of interrupts it generates. If you let it free-run it will cause an interrupt every 3.2768ms but you can stop and reload it in the interrupt service routine so it that it overflows and generates the interrupt every ms if you want to.

    To 'get the job done' I'd go with the second alternative. To get more used to the chip and PBP I'd go for the third alternative.

    The CLEARWD is not needed, PBP adds that automatically as long as you don't tell it no to.

    HTH.
    /Henrik.

    EDIT: Also, you do not use RESUME to return from a subroutine to which you jumped with a GOSUB as is the case with your SetTimer sub. You use RETURN. RESUME is for returning from an interrupt routine. I see that you also have a RESUME at the end of the EndTime sub to which you jump with a Goto - that won't work either....
    Last edited by HenrikOlsson; - 5th April 2010 at 12:07.

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