Timings, Loops - More.


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2011
    Posts
    17

    Default Timings, Loops - More.

    I recently asked some questions about timings, loops and interupts, with some good responses - however, further reading has raised even more questions.

    I have noticed that several people refer to the watchdog timing waking up the PIC when in sleep, i thought that the watchdog timer just reset the PIC?

    Is the internal RC oscillator used for the watchdog also used for anything else, i.e. sleep?

    Also, if i was to create an application that, for example:-

    1, Used TMR1 with an external 32Khz crystal, an the interal RC oscillator for the main program (or even just one oscillator using idle).

    2, Had an interupt set for say, 25ms, which then incremented some variables, then jumped to a main routinue.

    3, The main routinue then checked some inputs and the variable counters and set anything that was needed, then went to sleep waiting for the next interupt.

    How do you set this, would you just make the sleep command longer than the expected interupt time?

    Any guidance would help.

    Gordon.

  2. #2
    Join Date
    Jun 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: Timings, Loops - More.

    Would really appreciate any comments or feedback…

    Thanks


    gord11

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Timings, Loops - More.

    what chip? I think how it works WRT watchdog and internal timers will depend on the uP being used.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Jun 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: Timings, Loops - More.

    Hi,,

    Lets say it's a 16F689, although i am just trying to understand general best methods, so it's a bit open....

    Gordon.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: Timings, Loops - More.

    Hi,
    I have noticed that several people refer to the watchdog timing waking up the PIC when in sleep, i thought that the watchdog timer just reset the PIC?
    I believe you are right - sort of. It does reset the PIC but it's a different kind of reset compared to, say, pulling MCLR. If you look in the datasheet (I'm looking at 18F4520 at the moment) you'll find a table called Initialization condition for all registers or something like that. It shows that when the PIC wakes up or "resets" due to an interrupt OR the WDT the internal register contents remains unchanged as opposed to a Power on reset or a MCLR reset. (Exceptions exists)

    Is the internal RC oscillator used for the watchdog also used for anything else, i.e. sleep?
    The watchdog timer has its own built in RC oscillator. It does not depend on the osciallator used to clock the program execution - if it did it would be impossible for it to wake the PIC up since the main oscillator is shut down when entering "normal" sleep mode. This RC oscillator is, as far as I know, not callibrated and can drift quite a bit over temperature which is why it's not very good at keeping "real" time.

    EDIT: The PBP command Sleep works by keeping track of the number of times that the WDT waked the PIC up. Pretty much as you're doing with your software timers. If the WDT period is 200ms (I've no idea what it really is) and you execute a Sleep 10 the WDT will wake the PIC up 50 times, each time the PBP "system" will increment a counter and when it hits 50 it will countinue executing your code.

    ...
    ...
    How do you set this, would you just make the sleep command longer than the expected interupt time?
    That would work. With the PBP command Sleep the specified period is in seconds so if you intend to have a "cycle time" of 25ms then executing a Sleep 1 in your Main routine should do it.

    On the other hand you could just turn off the WDT all together. Then Sleep (or Nap) will put the PIC to sleep "for ever" - or until something wakes it up which in this case would be your TMR1 interrupt.

    Hope that helps.
    /Henrik.
    Last edited by HenrikOlsson; - 5th July 2011 at 18:14.

  6. #6
    Join Date
    Jun 2011
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: Timings, Loops - More.

    Hi Henrik,

    Yes that has helped.... Many Thanks.

    Just to clarify, if others are using the WDT to wake the PIC, then they must be referring to using "Sleep"? Or some other NON-PBP method.

    But anyway if i want my applications to be as accurate as i can, then TMR0,1 with external crystal etc. would be best.

    Thankyou,


    Gordon

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: Timings, Loops - More.

    Hi Gordon,
    Glad it helped.
    Just to clarify, if others are using the WDT to wake the PIC, then they must be referring to using "Sleep"? Or some other NON-PBP method.
    Yes, when PBP is compiling your program it automatically "sprinkles" the code with CLRWDT which is what "kicks the dog" ie. it resets the WDT, keeping it from timing out. If you stop "kicking the dog" (for whatever reason) it will eventually time out and reset the PIC.

    If the reason you stopped "kicking the dog" was because you went to sleep (program execution stops, thus no CLRWDT instructions) then the PIC will wake up.

    But anyway if i want my applications to be as accurate as i can, then TMR0,1 with external crystal etc. would be best.
    Yes, that's my opinion. Or, as we discussed in the other thread, use a power managed mode which doesn't shut down the main oscillator. Saves an external x-tal but costs on current consumption.

    /Henrik.

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