pic with countdown timer register?


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2014
    Posts
    13

    Default pic with countdown timer register?

    Hi All,

    Newbie question...

    Is there a PIC with a countdown timer register ?

    I have an external event and on the event I want to calculate a delay (max 0.8 seconds), load it to a countdown timer and have an interrupt when the timer reaches zero.

    Are there any PIC chips with that sort of capability?

    Googling 'PIC Countdown timer' just gets you lots of results for how to build 0-99 sec timers.

    Thanks,

    Wilson.

  2. #2
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: pic with countdown timer register?

    There is interrupt on overflow. You can easy calculate start value, depending on clock speed, prescaler settings and desired time/frequency for interrupt.

  3. #3
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: pic with countdown timer register?

    Being a non wonderful programmer myself I wonder why you'd need a countdown timer? At the maximum of .8 seconds you'd never be able to display the countdown sequence.

    Why can't you use a chip that has an Interrupt on Change pin? Use the IOC event, calculate the delay and use a pause command?

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: pic with countdown timer register?

    @AvionicsMaster1. Not wanting to be rude but that is a terrible idea, you will tie up the PIC doing nothing but pausing. The countdowntimer is so much better, little or no cpu time used for little or no programming effort.

    George

  5. #5
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: pic with countdown timer register?

    I got the idea the event wouldn't happen all time and wouldn't require a pause every second of .8 second.

    Even if there was only .2 seconds couldn't he do like 200 commands doing something else?

    Just to me, a pause for an intermittent event would make more sense.

    PS Maybe ifn I knew all of what he was trying to do I wouldn't make a poor suggestion like that. You'd also have to work harder than that to be rude. Teach on.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: pic with countdown timer register?

    Hi,
    As far as I know there no count down timers in any PIC but I don't really see the need for one.
    As have been said before, instead of counting from 100 to 0 you count from 156 to 0 (with an 8-bit timer). There's really no difference. What you need to do (which pedja089 also covered) is to set the timer up so you have enough "range" then simply calculate at what value you need to start in order to have it overflow after 0.8 seconds or whatever. Depending on the PIC and timer used you may not be able to get long enough time in "one" go. In that case you could, for example, set it up to give you "ticks" of 0.1s (or whatever) and count 8 of them.

    /Henrik.

  7. #7
    Join Date
    Aug 2014
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: pic with countdown timer register?

    Hi Guys,

    Thanks, interrupt on overflow sounds ideal.

    FYI my event happens regularly with a max freq of 600 events per second and a min freq of 30 events per second. Depending on the time between events I have to calculate a time delay to generate an output event to occur within the time window of the time measured between the last two input events.

    So if the time measured between input events is 0.8 seconds, I need to calculate a time which will always be < or = 0.8 seconds.

    I'm measuring other process control variables so I'm trying to unload counting/timing tasks to hardware.

    Thanks,

    Wilson.

  8. #8
    Join Date
    Aug 2014
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: pic with countdown timer register?

    OK, so I am using the PIC16F877A.

    Can I attach an external clock that only the timers will use (not the CPU) ?

    If so I could attach a 32.768khz clock which at a prescaler of 1:32 should give me a max delay of 1 second inside which I could fit my required 0.8 second delay.

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: pic with countdown timer register?

    Hi Wilson,
    Even at the min frequency of 30 events per second the time between events is ~33ms while you're talking about 800ms?
    Are you actually talking about 30-800 events per minute?

    /Henrik.

  10. #10
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: pic with countdown timer register?

    Hi Wilson.
    Yes, you can connect an external clock source to either TMR0 or TMR1 on the 16F877A.
    If, however, you're talking about connecting a 32.768kHz crystal directly then only TMR1 has that capability (it's got an internal oscillator circuit specifically for this purpose). TMR1 is 16bits wide so you'd get 2 overflows per second. A prescaler of 2:1 will allow you to fit your 800ms in one go.

    /Henrik.

  11. #11


    Did you find this post helpful? Yes | No

    Default Re: pic with countdown timer register?

    @Wilson

    as Henrik points out you have a problem. Even if you mean 600 times per minute thats still every 100ms. The countdown timer will barely have stated before your next event happens.

    You need to state the problem in detail. Perhaps drawing a waveform diagram might help.

    George

  12. #12
    Join Date
    Aug 2014
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: pic with countdown timer register?

    @George @/Henrik

    Yes, you are quite correct. 30 - 600 events per second = 0.033 to 0.00167 seconds between events.

    A 32.768kHz crystal with a prescaler of 2:1 looks ideal.

    Thanks,

    Wilson.

Similar Threads

  1. pic+shift register+lcd
    By eworld in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd October 2012, 05:11
  2. long countdown timer, how to save power?
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 15th November 2008, 05:15
  3. help: countdown with timer0 interrupt
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 19th August 2008, 14:12
  4. Replacing shift register with PIC
    By TonyA in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 7th April 2008, 18:31
  5. dual 7-segment countdown timer code
    By dr.ragh in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 30th April 2007, 13:19

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