? about sleep/wake on pin change and WDT


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Jan 2007
    Posts
    15

    Default ? about sleep/wake on pin change and WDT

    I am making a device using the pic10f series microcontrollers whose main purpose is to do a pulsout every couple of seconds. I want it to pulsout and then NAP (go into low power mode between pulses for less than a second to maybe 2 seconds). This is easy.

    However, I need to be able to put it to sleep and wake it up on pin change (using a magnetic switch internally sealed from elements) which requires that the WDT be disabled. I am using watch batteries (due to size restrictions) I really need for it to have the lowest power consumption possible AT ALL TIMES. NAP will not work without WDT enabled.

    What else can I do, any suggestions?

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


    Did you find this post helpful? Yes | No

    Default

    Use the assembler @ SLEEP option & WDT to wake up periodically and
    generate your pulse. Using the prescaler you can have up to 2.3 second
    sleep periods.

    Use one I/O-pin to wake up on keypress, and another to enter sleep mode
    when pressed.
    Regards,

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

  3. #3
    Join Date
    Jan 2007
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Thanks for your reply but.... Unfortunately I want to be able to just wave the magnet over the switch which will change the pin state and make the pic sleep or wake. I cannot leave the magnet in place on the magnetic switch.

    So I need the pic to stay sleeping after an "@ SLEEP" and not to wake at all until the pin changes when the magnet has been waved over the switch.

    This means the WDT has to be disabled which kills my "NAP" or "SLEEP" usage and forces me to use pause which will not be the low power usage desired.

    Anything else I could try at all?

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


    Did you find this post helpful? Yes | No

    Default

    Is the magnetic switch the "only" thing that will be used to wake it up?
    Regards,

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

  5. #5
    Join Date
    Jan 2007
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Yes, the magnetic switch will be the ony thing to wake it and tell it to sleep in this application. It should not turn on/off (wake/sleep) until a user turns it or on with the switch..

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


    Did you find this post helpful? Yes | No

    Default

    Here's one scenario;

    The PIC wakes up at regular intervals using the WDT. If switch = 0, then go
    back to sleep. It's only awake for a few uS testing the switch.

    If switch = 1, then do whatever you need to do, then test the switch input
    before going back to sleep.

    A switch press can also wake the PIC up before a WDT timeout. Handle
    whatever you need to do, test the switch, and go back to sleep or stay
    awake (resetting WDT) as required, based on the switch input.

    It's still going to save a boat-load of power since it will be sleeping until your
    switch is active, or the WDT times out.

    If the switch isn't active, it's still alseep for the majority of time, and you'll
    be operating at low current until the switch input forces the wake up, or the
    WDT timeout.

    Wouldn't that work?
    Regards,

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

  7. #7
    Join Date
    Jan 2007
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    This could work.... I will try this as soon as I get the chance (prob after the weekend). Thanks for your suggestions, I've been working on multiple projects and they all run together which makes it hard to really focus on the issue at hand enough to get outside the box. Sometimes its just nice to get a fresh perspective on a project.

    Thanks again Bruce! I'll post my results when I get back to it next week.

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


    Did you find this post helpful? Yes | No

    Default

    Kessral

    If I understand you correctly, you want to do a pulsout (1) every time the PIC is woken by the magnetic switch. Waking on a magnetic switch can be done by a pin change interrupt, if available in the 10F(Havent used, so I cant comment on this). So, your ideal work loop will be something like

    while (1)
    PULSOUT pin, period
    @ SLEEP
    @ nop
    @ nop
    ' on waking from interrupt, go back to pulsout
    wend

    Of course, I haven't shown the part needed to configure the PIC for interrupt on change, etc

    Jerson

  9. #9
    Join Date
    Jan 2007
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    No Jerson, I'm trying to get it to pulsout as the main function every few seconds or so. I want it to sleep as if it were turned off. And then continue its normal function pulsing when awakened.

    I have tried your suggestion tho Bruce and come up with this code:

    __________________________________________________ ____________

    TRISIO=%11111111
    STATUS=%10010000
    OPTION_REG=%00001000
    check var bit
    Low GPIO.0

    loop:

    nap 4
    pulsout 0, 4000
    nap 5

    IF GPIO.1 = 1 then
    suspend:
    pause 2000
    check = GPIO
    sleep 65535
    IF GPIO.1 = 1 then
    goto loop
    else
    goto suspend
    endif
    endif

    goto loop
    __________________________________________________ _____________

    This seems to work. It wakes and sleeps on pin change just fine... however my problem now is that its drawing some 60uA instead of the 5-10uA listed in the datasheet. I'll keep looking through to see if there is something else I can do to lower the current drain, but for now this seems to be as close as I am going to get.

    I DID notice however that GPIO 3 is constantly high... this could have something to do with current drain being slightly higher so that is what I am currently looking into.

    Again thanks for the Input guys.

    P.S. This is on a PIC10F202 and I am using MPLAB IDE v7.11
    Last edited by kessral; - 15th January 2007 at 21:11.

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kessral View Post
    No Jerson, I'm trying to get it to pulsout as the main function every few seconds or so. I want it to sleep as if it were turned off. And then continue its normal function pulsing when awakened.

    I have tried your suggestion tho Bruce and come up with this code:

    __________________________________________________ ____________

    TRISIO=%11111111
    STATUS=%10010000
    OPTION_REG=%00001000
    check var bit
    Low GPIO.0

    loop:

    nap 4
    pulsout 0, 4000
    nap 5

    IF GPIO.1 = 1 then
    suspend:
    pause 2000
    check = GPIO
    sleep 65535
    IF GPIO.1 = 1 then
    goto loop
    else
    goto suspend
    endif
    endif

    goto loop
    __________________________________________________ _____________

    This seems to work. It wakes and sleeps on pin change just fine... however my problem now is that its drawing some 60uA instead of the 5-10uA listed in the datasheet. I'll keep looking through to see if there is something else I can do to lower the current drain, but for now this seems to be as close as I am going to get.

    I DID notice however that GPIO 3 is constantly high... this could have something to do with current drain being slightly higher so that is what I am currently looking into.

    Again thanks for the Input guys.

    P.S. This is on a PIC10F202 and I am using MPLAB IDE v7.11
    Have you got any pullup or pulldown resistors in there anywhere?
    5v / 10k = 500uA
    And the datasheet does say that the weak pull up current is 250uA average.
    Just a couple of ideas for ya...

  11. #11
    Join Date
    Jan 2007
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    This is a good point. And I did think of this. Currently I have 1 15k pulldown to ground from the pin connected to magnetic switch to help determine high/low state.

    However 60uA is not consistent with this.. I'll just have to keep it in the back of my mind, as I have many other things to get to as well, maybe I'll think of something.
    Last edited by kessral; - 15th January 2007 at 23:02.

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


    Did you find this post helpful? Yes | No

    Default

    Try this;
    Code:
    DEFINE OSC 4
        
        ' GPIO.1 & 3 inputs, rest outputs. Use external pull-ups
        ' on GPIO.1 & 3.
        TRISIO=%00001010
        ' Internal pull-ups off, prescaler to wdt, 1:128 prescale,
        ' wakes up approx every 2.3 seconds.
        OPTION_REG=%01001111
    
        Low GPIO.0 ' pre-condition output for high pulsout
    
    Loop: ' 100K external pull-up on GPIO.1, switch grounds GPIO.1
          ' when pressed
        WHILE GPIO.1 = 0    ' if button pressed, do pulsout
           CLEARWDT         ' reset WDT while in loop
           pulsout 0, 4000  ' pulsout GPIO.0
        WEND
        
        ' Note: It will wakeup about every 2.3 seconds on WDT timeout,
        ' or switch press, but doesn't pulsout unless switch is pressed.    
        @ SLEEP             ; else sleep
        ' Don't need goto here since wake up is a device reset.
        END
    Regards,

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

  13. #13
    Join Date
    Jan 2007
    Posts
    2


    Did you find this post helpful? Yes | No

    Default ultra low power

    just use a inline resistor and a cap to GND on the output of your switch.

    V+ --- [resistor, 10K?]----[reed switch]----[Capacitor from this line to GND]----pic I/O

    The cap will "store" the switch closure event so that when the unit wakes up it can tell the reed switch was closed while it was sleeping.

    The PIC can then, once it wakes up, flip the input bit to a grounded output to "reset" the circuit. Then just before SLEEP it can make the pin back into an input.

    Note that if the circuit board is damp or dirty and you don't reset the circuit on every wake up from sleep, that eventually the cap can charge up.

    The cap can be very small, 0.01uF (10nF) would work just fine. I tried to make
    a proper ascii schematic but this forum has no code mode that I can see.
    Last edited by dolphin42; - 25th January 2007 at 23:35.

Similar Threads

  1. saving RCREG to word
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th September 2008, 13:51
  2. Changing 18F WDT postscaler on-the-fly
    By Bruce in forum Code Examples
    Replies: 4
    Last Post: - 1st August 2006, 21:09

Members who have read this thread : 2

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