Cap Sense ...getting a drowsy PIC to wake out of sleep!!


Results 1 to 14 of 14

Threaded View

  1. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Cap Sense ...getting a drowsy PIC to wake out of sleep!!

    Quote Originally Posted by rsocor01 View Post
    The CSM app notes recommend to compare the last count vs an average instead of comparing to the previous count.

    I don't see how you can use CSM in sleep mode. If you use the WDT to make the pulses anyways, you need an interrupt to see how many pulses you have in a fixed amount of time. So, you really need two timers. Also, you need to make some calculation to know if the button was touched.

    Robert
    Hi Robert,

    Firstly, you don't use the WDT to make the pulses....the CSM makes the pulses (clock)....and they feed into timer1. You use the WDT simply as the timeframe. The flow of things goes something like this...

    CSM Module pulses out-> Timer1 (which obviously counts those pulses)
    WDT wakes PIC up (sample period set by the WDTCON register)
    Store the present timer1 count
    compare the present timer count vs the last stored timer1 count
    if it has deviated by 'x' percent, then point your code back into the main loop (out of the 'sleep/WDT loop')
    if it hasn't deviated by 'x' percent, then
    clear timer1 down
    put the pic back to sleep
    WDT wakes PIC up
    Stores the present timer1 count
    compares the present count vs the last count
    rinse repeat.

    (btw, yes I know Microchip recommend using averages, but it's not necessary...the deviation is massive - like 90% when my sensor is touched - it's easy to trap. Also 'averaging' when your sample period is in the order of seconds is not ideal.)

    I've actually got it all working in sleep mode ...the CSM does run in sleeps & Timer1 counts ...all you have to do is wake the pic up with the WDT & check the present count vs the last count.

    The gotcha, is that when you're sleeping your PIC - which is obviously to save battery power - you only want the PIC to wake up couple of seconds....but if you don't change the timer1 prescaler & adjust the CSM oscillator output frequency down before sending the PIC off to sleep, then timer1 overflows (but interrupts are disabled before going to sleep- since we don't want the timer to actually overflow here) So, before going to sleep I use the CPSCON1 register to drop the CSM oscillator frequency as well as the T1CON register to changed the pre/post scaler so that during your chosen WDT sample period, it's well under the number that TMR1 overflows.

    Got to do a bit more tweaking but like I say it works...& the current draw while the PIC is asleep is sub 100uA! (in fact below what my meter can measure). This is great beause what it means in reality, is that you don't have to mess about implementing a power switch....ie with a couple of AA batteries you'll get a few years of sleep.
    Last edited by HankMcSpank; - 10th May 2011 at 00:33.

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