Ultra low power in a PIC18F microcontroller

Discussion in 'Embedded Systems and Microcontrollers' started by portreathbeach, Sep 12, 2016.

  1. portreathbeach

    Thread Starter Active Member

    Mar 7, 2010
    143
    5
    I am designing a Nixie tube watch. It is all on proto board at the moment and am still testing it. It runs from a 100mAh lithium battery and I obviously want it to run at the lowest power possible. There is an accelerometer which is powered up and takes readings and then powered off, this happens every 200ms. When the correct tip angle is reached, the Nixie tubes display the time.

    The average current consumption is just under 100uA, which is great, but I want to improve this.

    Currently I have a loop which waits for a 200ms interrupt to set a variable called 'wait' to 1, in the main loop I have...

    while(wait == 0);
    wait = 0;


    So every 200ms, the interrupt fires and sets 'wait' to 1, then my while(wait == 0); is skipped, 'wait' is set back to 0 and the rest of the loop runs (it takes about 25ms). Then we get back to the while(..... again, and we wait for the interrupt to set 'wait' again......and so on.

    I've read a bit online about 'sleep' and 'idle' in the PIC18F chips and I know 'sleep' won't work as the timers will be stopped, but would 'idle' save any power for me. I mean, idle mode keeps all the peripherals running, so would this save any power over what I'm currently doing? as surely the PIC isn't using much power sitting in a while loop.


    Any help on this topic would be great.
     
  2. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,673
    2,712
    Which PIC are you using? Is there an RTCC? Can you wake from that?

    You could use the WDT to wake occasionally. The wake-up period will not be accurate, though.

    Timer 1 will work in sleep with an external 32.767 kHz watch crystal, IIRC.
     
  3. dannyf

    Well-Known Member

    Sep 13, 2015
    1,767
    357
    get it to wake up from timer1. Do its things and then go back to sleep.

    Remember to insert a NOP() after the sleep instruction.
     
    atferrari likes this.
  4. JohnInTX

    Moderator

    Jun 26, 2012
    2,339
    1,022
    atferrari likes this.
  5. portreathbeach

    Thread Starter Active Member

    Mar 7, 2010
    143
    5
    Thanks for all the replies.

    The timing for wake up isn't that critical, as long as it's something around 125ms.

    I'm using a PIC18F13K22. This has 'idle' mode, and from what I've read, I can use the WDT to wake it.

    So I will try something like this...

    1) clear watchdog
    2) enable watchdog
    3) go into idle mode
    4) when woken from idle mode by WDT, disable WTD
    5) carry out my code
    6) back to start

    I'll report back my progress
     
  6. NorthGuy

    Active Member

    Jun 28, 2014
    603
    121
    WDT uses LFINTOSC, which is not very accurate - 20%. When you go to sleep all your timers stop and you lose all sense of time. When you wake up, it might be anywhere between 160 and 240 ms since you fell asleep.

    If you need better accuracy then you need some sort of clock outside of the chip, such as SOSC with watch crystal. Then you can use asynchronous timer to keep track of time and it can wake you up as well.
     
  7. portreathbeach

    Thread Starter Active Member

    Mar 7, 2010
    143
    5
    I'm using an external RTC chip, so the timing is not critical.

    I just did a test, I had...

    while(1){
    __delay_ms(125);
    LATAbits.LA1 = 1;
    __delay_ms(25);
    LATAbits.LA1 = 0;
    }

    The total current drawn was 36uA.


    I then setup the WDT for 1:32 (4ms x 32 = 128ms)


    while(1){
    WDTCONbits.SWDTEN = 1;
    CLRWDT();
    SLEEP();
    WDTCONbits.SWDTEN = 0;
    LATAbits.LA1 = 1;
    __delay_ms(25);
    LATAbits.LA1 = 0;
    }

    So, enable WDT, clear timer, sleep, disable WDT, then toggle pin.


    Because I was toggling the pin, I used a scope to prove that it was actually doing what it should be doing, and it was.

    But the current draw was slightly higher than before.

    I am only using the internal 32KHz oscillator for the project, and all the peripherals are off. So maybe having the WDT also counting is using power. I would have thought I should be able to get the PIC to draw a lot less power than 36uA. The datasheet talks about nA
     
  8. dannyf

    Well-Known Member

    Sep 13, 2015
    1,767
    357
    Read the data sheet and features like wdt or bod are quite current hangury.

    Since you already have a rtc chances are that it can interrupt the MCU and wake it up that way.

    Btw: using delays in such a set up defeats the very purpose of putting the MCU to sleep.
     
  9. NorthGuy

    Active Member

    Jun 28, 2014
    603
    121
    WDT uses the same LFINTOSC. Can your RTC chip produce some sort of output signal? This will give you something for your asynchronous timer. If not, you can replace your RTC chip with a watch crystal - this may even save more power.
     
  10. portreathbeach

    Thread Starter Active Member

    Mar 7, 2010
    143
    5
    The RTC chip only draws 3uA to keep time, which is low enough power for me.

    It's just the PIC is drawing 35uA when it's in a loop, or when it's asleep.

    Dannyf, the example I put with the WDT and Sleep was just to test current consumption. The WDT was waking up the PIC every 128ms, then the delay was so I could see a 23ms pulse on my scope. Surely putting the PIC to sleep for 125ms, then waking it and having a 25ms dely should use way less power than having a 125ms delay, setting the pin, delaying for 25ms, and then unsetting the pin. After all, the PIC is asleep for 80% of the time.

    Because I was scoping the pin, I know that the WDT and Sleep functions were working, as the trace looked like correct.

    The datasheet says that in sleep mode consumes 34nA, watchdog timer consumes 460nA and timer 1 consumes 650nA at 32KHz. That's 1.144uA of current. Why am I seeing over 30uA? I did a test where I had nothing connected to the PIC and put it to sleep and it still drew 30uA, which I know is a very small amount of current, but still way over what the datasheet states.

    NorthGuy, The RTC chip does have a 1 second output pulse, but I need to check analogs from the accelerometer 6 times a second, so that won't work for me.
     
  11. NorthGuy

    Active Member

    Jun 28, 2014
    603
    121
    You need to inspect every pin.

    Input pins not tied to the ground or VDD will produce nose switching.

    Output pins with source/sink their loads, including internal pull-ups. You're only looking for 100K load.

    Also consider your power source. If it has ripple, some energy will be lost. You need to measure using pure DC source such as battery.
     
    atferrari likes this.
  12. dannyf

    Well-Known Member

    Sep 13, 2015
    1,767
    357
    if your measurement were true, that would be a miracle PIC.

    you are not getting what low-power programming is all about. until you get over that hurdle, you aren't going to get what you want to do.
     
  13. portreathbeach

    Thread Starter Active Member

    Mar 7, 2010
    143
    5
    If connected to the lithium battery with no other input/output pins connected, 35uA is the lowest I can get it. I'm pretty happy with that, so I'll call it a day with the low power and stick with it.

    Thanks for the comments

    Craig
     
  14. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    Hola Craig,
    Out of curiosity, what is the reason to struggle to get that low power level when you are using nixie tubes?
     
  15. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,673
    2,712
    How are these pins configured in your code?
     
  16. portreathbeach

    Thread Starter Active Member

    Mar 7, 2010
    143
    5
    atferrari, The Nixie tubes only display the time when the watch it tipped towards you. And yes, this does use about 200mA for this, but when they are not illuminated, the watch needs to draw very little power so it lasts for a week or so.

    joeyd999, I've tried lots of configurations with the pins. The 35uA I have achieved is with a bare PIC, nothing connected to it. I have tried making the pins outputs, inputs etc. turning off all peripherals. I am quite happy with <40uA, but I just can't understand why this is so much higher than the datasheet says.
     
  17. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    Craig,

    To post a link, a nightmare in this tablet.

    Google Jack Ganssle ultra low power design. Took me time to remember his name.

    Buena suerte.
     
  18. portreathbeach

    Thread Starter Active Member

    Mar 7, 2010
    143
    5

    Brilliant,

    What a very interesting read.


    Thanks
     
    Last edited: Sep 18, 2016
Loading...