Timing And Loop Fundamentals


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Timing And Loop Fundamentals

    I'm fairly new to 'sleep' (fairly new to PICs and programming come to that), but if you intend using sleep, then I'd suggest dedicating Timer1 to any counting that must happen while asleep.

    I'm not sure I'm understanding this sentence...
    I have assumed that the device would go to sleep, wake up via the interupt (which would be accurate), then increment all the counters & check the conditions and set outputs etc. all from inside the interupt rountine.??
    When you say increment all counters....from what? (I guess a bit more meat on the bones wrt what's happening in your circuit)

    How I'm doing it...

    pic goes to sleep (timer 1 still counts while asleep)
    WDT wakes PIC up (pretty accurately)
    the PIC while briefly awake (digesting toast & supping coffee), checks timer1 blah blah
    pic then goes back to sleep
    WDT wakes pic up, the kettle goes on...rinse repeat.

    To save more battery power, I set the WDT period initially to wake the pic up every 128mS, but then after 2 hours of no buttons being pressed (no humans about), the WDT only wakes the PIC up every 2 seconds (I have to change timer1's prescalers to reflect the longer 'sampling period'). As an aside, I've got my overall 'sleep' circuit current draw down to 10uA ....I'm pretty happy with that ( about 6 years in standby for a single 9v battery)

    I've still not learned a good way to approach all the loop timing thoughs (& yes, it's a PITA when you change parts of your loop...the timing then go out the window!)...I use online stopwatch & hserout a lot!
    Last edited by HankMcSpank; - 28th June 2011 at 22:28.

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


    Did you find this post helpful? Yes | No

    Default Re: Timing And Loop Fundamentals

    Hi Hank,
    I suspect Gordon is maintaining a bunch of software counter/timers in his code, much like in a PLC or something like that. I'm sure he'll elaborate on that.
    How I'm doing it...
    pic goes to sleep (timer 1 still counts while asleep)
    So are you clocking TMR1 externally then or are you using one of the "idle-modes" where the oscillator isn't shut down?

    I'm asking because I was sure that the main oscillator is shut down when entering sleep-mode and when TMR1 (or any timer) is set to timer mode it is being clocked by the now shut down oscillator so it can't keep ticking.

    If indeed your TMR1 is ticking while the device goes to sleep can you tell us what device that is, I'd like to read up on the datasheet on that one.

    /Henrik.

  3. #3
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Timing And Loop Fundamentals

    Sorry for not being clear, I was outlining how I appproach sleep in general (using the WDT to wake the PIC up vs using a timer interrupt)

    Like I say I'm still finding my way & new to sleep....presently learning about capacitive touch....during sleep, when configrued right, Timer1 counts the output pulses from the capacitive touch module ...which still outputs during sleep (I would have offfered that up as an idea...use the capactive touch module to clock timer1 while sleeping, but it's not particularly steady & its frequency drifts quite a bit with enviromentals!)

  4. #4
    Join Date
    Jun 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: Timing And Loop Fundamentals

    Thankyou for the comments.

    Sorry i was not clear about the timers, yes, these are just software variables which are incremented and cleared as required.

    My questions are general, i don't have something specific in mind just thinking about the best way of doing things, i think i have got lazy and just stick to the same old methods all the time.

    The devices i have been using don't have the power managed idle mode, but i can see others that do and this seems quite a good idea.

    I thought that if i used the WDT to wake the chip, then do whatever, this would not be as accurate as using the TMR interupt.

    Also, i am right in thinking that if i used the TMR1 with the external crystal, which would be accurate, then i could set the main oscillator to internal? As the program timings would all come from TMR1.

    Gordon,

  5. #5
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Timing And Loop Fundamentals

    If you use XLP device, and running tmrX from x-tal, and everything else turned off, it consumes only about 1uA...
    You have in code example RTCC that use only 2 uA...

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