Hardware timers


Closed Thread
Results 1 to 10 of 10

Thread: Hardware timers

  1. #1
    Join Date
    Jun 2008
    Posts
    30

    Post Hardware timers

    I'm using "COUNT" command to count the number of pulses coming in but now i need to use the hardware timers. I want to count my pulse for 30 seconds, i was thinking of using TMR2 8 bit with prescaler. I'm using a PIC16F873 with a 20 Mhz crystal, could anyone let me know how to approach this.

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


    Did you find this post helpful? Yes | No

    Default

    Are you trying to use a timer for the 30 second period, or trying to use a timer/counter?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Jun 2008
    Posts
    30


    Did you find this post helpful? Yes | No

    Smile Hardware timers

    I would just like to use the hardware timers, just to pause for 30 seconds so in the mean time my pic can keep running and keep collecting data for that 30 sec.


    thanks

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    I would think, you need a timer to keep count of the seconds. Any timer would do fine as long as you know how to extend it, in code, to count 1 second. This timer can then be further extended to count the 30 seconds interval you want.

    Similarly, the pulses could come into the INT pin on your device and you could count the interrupt when it occurs.

    Just ideas you could evaluate

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Why not just let the timer/counter count your pulses?

    MyCount VAR WORD

    TMR1L=0 ' clear the low byte
    TMR1H=0 ' clear the high byte
    T1CON = %00000011 ' set Timer1 up as a hardware counter

    This counts rising edge pulses on RC0. The count is held in TMR1L and TMR1H.

    Do whatever you need to collect other data for 30 seconds then just read the count.

    MyCount.LowByte = TMR1L
    MyCount.HighByte = TMR1H

    You could set Timer1 to overflow, count overflows incrementing a variable, but it would be
    a lot easier using a built-in hardware counter. And it doesn't interrupt whatever else your
    program is doing. It counts in the background.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    May 2008
    Posts
    21


    Did you find this post helpful? Yes | No

    Default

    When I had to learn how to use timers, I used this thread.

    This thread also happens to have EXACTLY what you want... a timer that counts down from 30.

    http://www.picbasic.co.uk/forum/show...hlight=O_FLOWS

    Sorry the link highlights O_FLOWS, I just happen to rememberthat variable so used it to find the thread.
    Also wish I'd have read the forum sooner >.<;

  7. #7
    Join Date
    Jun 2008
    Posts
    30


    Did you find this post helpful? Yes | No

    Smile TMR1 Help

    I looked at this forum http://www.picbasic.co.uk/forum/show...hlight=O_FLOWS and it seems a little to complicated for what i need.

    I am using a 20mhz crystal so I'm not sure if i need to use a prescaler.

    but all i want to do is monitor a battery I'm using adc 10 bits so when my battery reaches 9 volts i want a 10 second pause using TMR1 so my adc can still keep collecting, and after the 10sec pause is done just keep resuming the program.

    so something like this.......

    voltage var byte

    timercount:

    '10 sec TMR1 pause here

    if voltage = 9 then


    goto timercount

    portb.4 = 1 ' after 10 sec resume from here

    endif


    Can anyone point me in the right direction thanks

  8. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    At 20MHz, if you're using the internal clock, Timer1 will count to 65,535, then roll-over on
    the next tick in just 13.1072mS with a 1:1 prescaler.

    If you set the prescaler to 1:8 it would take 8 times this period before it rolls-over. The
    only way you could use Timer1 for a 10 second delay period would be to monitor & count
    over-flows until your 10 second period is up.

    Unless you're just trying to learn to use timers, a long pause would be the easiest.

    Steve has a nice utility here: http://www.mister-e.org/pages/utilitiespag.html you might
    find helpful. Check out the timer helper.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  9. #9
    Join Date
    Mar 2006
    Location
    Pennsylvania, USA.
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    For a long delay like 9 seconds, I use Steve's calculator utility to set up a timer to go for 10 milliseconds. Then I use Darrell's Instant Interrupts, and set up an interrupt, let's say for Timer 3. I just set my variable seconds to 0, and then enable the timer interrupt. When the 10 ms. is up, the interrupt goes to the following;

    '********************** TIMER 3 INTERRUPT*************************************
    TIMER3INT: 'THIS INTERRUPT OCCURS EVERY 10 MILLISECONDS
    TICKS = TICKS + 1 'INCREMENT TICKS
    IF TICKS > 100 THEN
    TICKS = 0
    SECONDS = SECONDS + 1
    ENDIF
    @ INT_RETURN
    '********************** END TIMER 3 INTERRUPT ********************************
    now I just add a line in my main program to see if seconds is equal to nine, and when it is I disable the interrupt and go do what ever comes next. This works well if I'm waiting for a user to make a selection, I'll wait ten seconds, and if they don't respond, then the program will move on.

    Good Luck!

    Jerry.
    If your oscilloscope costs more than your car...

  10. #10
    Join Date
    Jun 2008
    Posts
    30


    Did you find this post helpful? Yes | No

    Smile Hardware timers

    Wow that Picmulticalc is really amazing thanks for referring me to it i will defiantly be using it.
    I don't need to use a interrupt. Right now i am using a really long pause 10 sec, so when my battery charges up to 9 volts my led comes on saying the battery is fully charge. Then i have my pause that checks back in ten seconds if my battery is still full or not. The only things i don't like about this process is that for that seconds my pic hangs and all my other operations are on a alt until the 10 seconds is completed. Now i was thinking if i could figure out how to use the hardware timers, my timers could count in the background without affecting my ADC, and LCD etc.

    Could anyone clarify this for me and maybe suggest a better way of doing this.

    thanks

Similar Threads

  1. Timers
    By mitchf14 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th November 2008, 20:08
  2. using hardware ports
    By sebapostigo in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 19th November 2007, 22:01
  3. Reading Timers
    By kevj in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th August 2007, 08:19
  4. hardware timers
    By Adam in forum General
    Replies: 3
    Last Post: - 7th March 2007, 00:10
  5. Bootloader Hardware Modification
    By NavMicroSystems in forum Schematics
    Replies: 1
    Last Post: - 5th August 2004, 00:46

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