Author Topic: The final power down  (Read 3231 times)

0 Members and 1 Guest are viewing this topic.

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
The final power down
« on: September 14, 2018, 06:00:03 pm »
My application requires the PIC (16F1827) to operate for a while unattended and then shut-off to save power.

Is it possible to do this? I can only see how to do it with the watchdog for a max of 256s. This means waking then sleeping again. Can it just go to sleep until the user can get to it again?

Cheers,
You can release yourself but the only way to go is down!
RJD
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3240
  • Country: gb
Re: The final power down
« Reply #1 on: September 14, 2018, 06:06:20 pm »
You can configure the watchdog to stop running during sleep.  Some current will still be drawn, but with careful design of hardware and firmware this can be very low.

Another solution is to power the PIC via a transistor which the PIC can control.  A press button bypasses the transistor at power on, the PIC then switches the transistor on to maintain power until it needs to power off again.
 

Offline ggchab

  • Frequent Contributor
  • **
  • Posts: 276
  • Country: be
Re: The final power down
« Reply #2 on: September 14, 2018, 08:14:25 pm »
Why not programming a delay and using the SLEEP instruction ?
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 826
Re: The final power down
« Reply #3 on: September 14, 2018, 10:08:23 pm »
You can simply shut every thing down that could cause a wake up, then SLEEP. Then it will require a mclr reset or power off/on to run again. Sleep will not draw any significant current if done right (pay attention to the output pins, they remain unchanged in sleep).

If you want to wake from user input and have a switch, there are IOC pins on port b, and an int pin, which can cause a wake from sleep.

Chapter 9 in the datasheet will give details of sleep.

This is overthinking a bit, but to provide another alternative for thought-
if you want to run the app (I gather from previous threads, recording temp at intervals) then power off, and not run again (and overwrite previous records) until certain conditions (like a power-on reset occurring) you could-
in your startup code, check the STATUS and PCON registers, and if the power-on reset combo is not set (table 7-3,7-4), SLEEP.
STATUS ---11000, PCON 00--110x

uint8_t p = PCON;
PCON = 0; //to prevent BOR appearing as POR
if(  ((p & 0b11001110) != 0b00001100) || ((STATUS & 0b00011000) != 0b00011000)  ){
SLEEP; //not a POR, no run
}


when you want to 'shutdown', just issue RESET instruction

Now, since you are always at a reset condition when SLEEP is run, you will be pretty much at the lowest power as you cannot forget to turn things off (pins, timers, etc.) since they are not setup yet, and the only way to start the app, is via a power up. Any other reset will result in SLEEP and preserve previous recordings.
 

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: The final power down
« Reply #4 on: September 16, 2018, 02:22:34 pm »
Can it just go to sleep until the user can get to it again?

Similar to what cv007 says.
Should be able to Set Interrupt On Change on some button input, the interrupt doesn't have to do anything other than wake from sleep. With all the outputs left in the correct direction the sleep current should be around 50nA.
« Last Edit: September 16, 2018, 02:24:05 pm by StillTrying »
.  That took much longer than I thought it would.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14470
  • Country: fr
Re: The final power down
« Reply #5 on: September 16, 2018, 10:13:53 pm »
Yes you can set the watchdog to be disabled during sleep (it's a config bit: "WDT enabled while running and disabled in Sleep"), and have the MCU wake up by an external interrupt, such as a state or edge change on a given input pin (IOC pins).

What's your target power draw during sleep? The watchdog timer is given at 500 nA. Unless you absolutely need to get below that, I would let the watchdog run during sleep. If anything goes bonkers on the MCU (hardware or software), it could remain stuck in sleep mode forever until you reset it manually or power-cycle it. I'm not very fond of that. The added power draw of waking up every few seconds for a few µs is completely negligible, and would give you the opportunity to maybe issue some checks before getting it to sleep again.

Of course if the added 500 nA is too much for your application, you'd have no choice.
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: The final power down
« Reply #6 on: September 18, 2018, 01:31:33 pm »
Thank you very much all.

This sounds sensible mikerj, I prefer the software solution though it’s true I hadn’t (also ggchab) thought the sleep route was the best.

However, I see, cv007, that if I use sleep with reset that this would work, brilliant as I don’t have to worry about turning stuff off. I guess this is ‘C’ and thank you for the example. I think it means that:
if on start-up the conditions in PCON do not (!= means “true if not equal” crazy!) match the power-on condition OR conditions in STATUS do not, then sleep?
Having set nothing yet (I put this code at 0005h) it will sleep forever at low power.
Is this correct?

Yes, thank you for remembering, I need it to measure temperature unattended until it fills the EEPROM then sleep, possibly for hours/days, until the user returns.
Could I ask a few questions please?
What does  the uint8_t p = PCON line do?
Which bits does PCON = 0 clear?
Why is it OR rather than AND between the PCON/STATUS test elements?
Could I not use PCON,2 RI bit as the test for reset (easier in assembly)?

StillTrying I have no spare pins and don’t need it to wake, the user will just turn it off. SiliconWizard I don’t really have a target for power consumption as it will be unattended for an unknown time the lowest power will preserve the battery the most.
You can release yourself but the only way to go is down!
RJD
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 826
Re: The final power down
« Reply #7 on: September 18, 2018, 05:46:07 pm »
Quote
Could I not use PCON,2 RI bit as the test for reset (easier in assembly)?
That would better and simpler.  I over-complicated it and now see the only thing to worry about is that bit.  The only other possible way any reset will occur after sleep is either a POR or a BOR. The POR will have to be deliberate, and the BOR will most likely not happen while in sleep unless you plan on leaving it in sleep for 10 years (plus by the time you get to a BOR in sleep, you surely will not have enough power to do anything anyway). The brown-out reset could also be disabled before going to sleep (some config bit and register bit combo I'm sure spelled out in datasheet), but would not worry too much about it.

 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: The final power down
« Reply #8 on: September 19, 2018, 04:21:10 pm »
I tried using RI and all works well, thank you.

The only thing is that I measured the current usage of the entire "system" and got the following:

"normal"  SLEEP = 183uA       - between usual temperature readings no reset, nothing turned-off
  "reset"   SLEEP = 227uA      - using the reset technique as above with nothing initialised

How can it possibly use MORE power (voltage was the same)  when everything is off?  :o
You can release yourself but the only way to go is down!
RJD
 

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: The final power down
« Reply #9 on: September 19, 2018, 04:43:26 pm »
How can it possibly use MORE power (voltage was the same)  when everything is off?

If your reset is setting pins as inputs, floating digital inputs will draw current when they're not held at or near logic 0 or 1, I think.
« Last Edit: September 19, 2018, 04:45:44 pm by StillTrying »
.  That took much longer than I thought it would.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14470
  • Country: fr
Re: The final power down
« Reply #10 on: September 19, 2018, 06:57:42 pm »
Yes all pins are configured as inputs during reset so if there are no external pull-ups or pull-downs, power draw will increase.

If you still draw that much current in sleep mode (183 µA), you probably have to look elsewhere than the MCU. This MCU properly configured and in sleep should draw a lot less.
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 826
Re: The final power down
« Reply #11 on: September 20, 2018, 01:00:05 am »
One thing to keep in mind, is it appears you have the F version, not the LF- only the LF parts will get into the nano amps.

the datasheet can give some clues about power consumption-
 DC Characteristics - power down
(note there are separate values for F and LF)

Since everything (peripherals that could be current draws) should be off after a reset, about the only thing (other than pin io) is the watchdog and brownout. Depending on config bits, these could be drawing current in sleep (how much, I don't know).

Here is what I would do. Get the bare chip going with nothing attached to io pins- power only. Simple program- just sleep, config bits set to WDT disabled, BOREN disabled. Program, disconnect programmer, power up, measure current. You now have a baseline current value.

Add to the program- set analog pins to digital in, then sleep. Repeat test. You now have another value. Then try setting pins to digital out low. Test. Digital out high. Test. Config bits- BOR enabled, WDT software enabled. You get the idea. You will be seeing where the current is going and will have recorded values for a 'bare' chip.

Now add whatever you have hanging on the pins. Repeat tests (and you obviously will know not to set a pin output to a state which will power a device). Eventually you will get enough info to figure out what effects sleep current.

With that info. you most likely could do a few things before going to sleep to help your numbers.
 

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
Re: The final power down
« Reply #12 on: September 20, 2018, 01:06:36 am »
I did some tests with a similar PIC:

https://hackaday.io/project/27471-monoflop

Turns out, the normal F version needs much more power than the LF version in sleep mode: 2.8 uA compared to 13.3 nA. And when the brown-out reset bit was enabled, the F version needed even 6.4 uA. So if your supply voltage is not too high, use the LF version, and if you don't need the brown-out reset, disable it.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: The final power down
« Reply #13 on: September 20, 2018, 04:17:58 pm »
Thanks all.

I don't know what I'm doing wrong but I did what you suggested cv007 and I got (5V power supply), inter alia:
1. simple prog (i.e. just sleep) with BOR and WDT config to off = 23.9uA [base case]
2. [base case] but with BOR on                                              = 29.6uA
3. [base case] with pins set to digital and input                       = 49.1uA

Yes, it is the F version but I can't get near the 2.8uA and the more I "control" the higher the current!
You can release yourself but the only way to go is down!
RJD
 

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
Re: The final power down
« Reply #14 on: September 20, 2018, 06:42:53 pm »
23.9 uA is within the specs of the datasheet. See page 347:

http://ww1.microchip.com/downloads/en/DeviceDoc/41391D.pdf

The table is a bit tricky: rows with the grey background is the "F" version and the white background is the "LF" version. The parameter D022 says max 45 uA at 5 V, so 23.9 uA is pretty good and close to the typical value of 19 uA.

If you compare this to the datasheet of the PIC12F1572, page 266:

http://ww1.microchip.com/downloads/en/DeviceDoc/40001723D.pdf

you can see that the D022 parameter for the "F" version is max 4.5 uA at 5 V. I measured 2.8 uA at 3.3 V, for which the typical value is 0.3 uA and max value is 3.0 uA, so within the specs. But still a bit high, now that I think about it, maybe I should try again to get to the typical value of 0.3 uA even with the "F" version.

Conclusion: you probably won't get lower than 23 uA with a PIC16F1827. You either need to use the "LF" version, or a different PIC with a lower D022 parameter (looks like they are named the same for many PICs, which makes searching for it easier).
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: The final power down
« Reply #15 on: September 20, 2018, 07:29:45 pm »
I can't work out what parts you're leaving on, it could be just one output left in the wrong direction, what's wrong with sleep. :)

Extreme Low-Power Management
PIC16LF1826/27 with nanoWatt XLP:
• Operating Current: 75 uA @ 1 MHz, 1.8V, typical
Sleep mode: 30 nA
• Watchdog Timer: 500 nA
• Timer1 Oscillator: 600 nA @ 32 kHz
.  That took much longer than I thought it would.
 

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2365
  • Country: de
    • Frank Buss
Re: The final power down
« Reply #16 on: September 20, 2018, 10:51:58 pm »
Sleep mode: 30 nA

This is the LF version, the F version has much more sleep current, as you can read in the datasheet.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 826
Re: The final power down
« Reply #17 on: September 20, 2018, 11:14:00 pm »
For a 12F1822 (8 pin device) i get about 15ua in sleep, for a 12LF1822 I can get ~50na (at about 3v). If you can get about 20ua for a higher pin count device (non LF), I think you are doing ok.

In the mchp forums, I got a reply once to a power question-
Quote
I spoke with one of our test engineers, and he said that when they test for IPDs, they typically set all the I/Os as outputs and tie them to VSS. Apparently, there are some internal transistors that may have some very small leakage, and when tied to VDD, the leakage will add just a tiny amount of additional current to the reading, at most 10nA per pin. In low pin count parts, that will make a slight difference, but in higher pin count devices, that can make a big difference.
where the datasheet had said the pins were tied to Vdd when tested. This is dealing in the low nA range so this really does not affect you, but someday when searching for that ultra low nA the sell sheet makes claim to you will know they do everything possible to get those numbers and you may not have a usable chip for your application in that test configuration. In most cases, those last nA really make no difference.
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: The final power down
« Reply #18 on: September 22, 2018, 10:57:36 am »
Thank you FrankBuss. I see what you are saying (I did mis-read the datasheet!) but my problem is that I am doing this project to "use up" some stuff that I already have, namely: PIC16F1827 and 7-seg LED.

Thanks StillTrying but it's true, I only have the "F" version to use up.

Cheers cv007.


So ... having "bottomed" the PIC element, I now realise, after the investigations that I did (as suggested by cv007) why the overall power drain is so high: it's because of the LM35 and the dimmer potentiometer - yes, I am a numpty!

The LM35 draws about 50uA as does the potentiometer (100kOhms). I want to use the pot so as to practice ADC as a way of "pwm-ing" the LED brightness. So, I need to turn these off when in sleep and I've been experimenting with a p-channel MOSFET which works - as a LED flasher at the moment. Is there anything to bear in mind when using such an arrangement?

The problem is that I have no pins left. However, I just tie MCLR to Vdd; I never use it to reset. Does this have to be done or can I reasign this to be a "normal" input and reasign another pin as the output to switch the MOSFET?
You can release yourself but the only way to go is down!
RJD
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 826
Re: The final power down
« Reply #19 on: September 22, 2018, 09:34:46 pm »
MCLR can be used as an input if you have a high voltage programmer (like pickit3), but not if you only have something like a curiosity board (lvp programming only). To use it as an input, you have to set the config bits- LVP=0, MCLRE=0.

You could probably just power your pot/lm35 from a pin- when going to sleep just set the pin low.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf