View previous topic :: View next topic |
Author |
Message |
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
Problems waking PIC24FJ128GB204 from deep sleep |
Posted: Wed Feb 21, 2018 6:38 am |
|
|
Hi Guys,
I may be missing something here (at least I hope I am).
By my understanding I can put my processor into deep sleep, where it will only be woken by an event on INT_EXT.
When it does get woken, rather than returning to the point after the sleep() command like normal however, it does a normal "power on reboot".
I've been tinkering a bit with normal sleep, before I found out about deep sleep and use the following routine to put the device to sleep.
Code: |
void Send_To_Sleep()
{
/* TURN OFF THE ADC */
setup_adc(ADC_OFF);
/* TURN OFF BAND GAP VOLTAGE REFERENCE */
VBGEN = FALSE;
BGREQ = FALSE;
/* DISABLE THE UARTS */
setup_uart(FALSE, DEBUG_PORT);
setup_uart(FALSE, BLUETOOTH_PORT);
/* TURN ALL I/O TO OUTPUTS AND TURN OFF */
output_drive(LCD_D0);
output_low(LCD_D0);
output_drive(LCD_D1);
output_low(LCD_D1);
output_drive(LCD_D2);
output_low(LCD_D2);
output_drive(LCD_D3);
output_low(LCD_D3);
output_drive(LCD_D4);
output_low(LCD_D4);
output_drive(LCD_D5);
output_low(LCD_D5);
output_drive(LCD_D6);
output_low(LCD_D6);
output_drive(LCD_D7);
output_low(LCD_D7);
output_drive(LCD_EN);
output_low(LCD_EN);
output_drive(LCD_RESET);
output_low(LCD_RESET);
output_drive(LCD_CD);
output_low(LCD_CD);
output_drive(LCD_CS0);
output_low(LCD_CS0);
output_drive(LCD_RW);
output_low(LCD_RW);
/* BUZZER */
output_drive(BUZZER);
output_low(BUZZER);
/* BLUETOOTH MODULE */
output_drive(BLUETOOTH_RESET);
output_low(BLUETOOTH_RESET);
output_drive(BLUETOOTH_RTS);
output_low(BLUETOOTH_RTS);
output_drive(BLUETOOTH_SLEEP);
output_low(BLUETOOTH_SLEEP);
output_drive(BLUETOOTH_POWER);
output_low(BLUETOOTH_POWER);
output_drive(BLUETOOTH_CTS);
output_low(BLUETOOTH_CTS);
/* TURN OFF THE I2C PORT */
i2c_init(DRV_PRESSURE_I2C,0);
/* BRING THE I2C PINS LOW */
output_drive(DRV_PRESSURE_SCL);
output_drive(DRV_PRESSURE_SDA);
output_low(DRV_PRESSURE_SCL);
output_low(DRV_PRESSURE_SDA);
/* TURN OFF THE WATCHDOG */
setup_wdt(WDT_OFF);
/* TURN OFF THE SWITCHED 3.3V LINE */
output_high(POWER_ENABLE);
/* MAKE SURE THAT EVERY SOURCE OF WAKE IS CLEARED */
Disable_And_Clear_All_IRQS();
/* WAKE ON THE ENTER BUTTON ONLY */
enable_interrupts(INT_EXT0);
clear_interrupt(INT_EXT0);
}
|
This is followed by the sleep(DEEP_SLEEP) or sleep(SLEEP_FULL) command in another routine.
If I use SLEEP_FULL - try as I might, I can't get the standby current to any less than 980uA. What else do I need to disable/turn off to reduce this? (I do have USB enabled, but can't seen to find a command to turn this off during sleep).
Using SLEEP_FULL the processor wakes up, and carries on.
However I digress, the above just serves to illustrate that I can wake up.
If however I put the device into deep sleep, it goes to sleep - my current drops to under 10uA (this does include quiescent current of power supply etc).
When I press the wake button however - the current increases from 10uA to 713uA but absolutely nothing else happens - the device certainly doesn't reboot!
so in essence :
a) what am I doing wrong with deep sleep?
b) How can I reduce my current in FULL_SLEEP? (If I can bring this current down to something sensible - it will enable me to use both of the buttons on the device to wake me up, which would be preferable).
Thanks in advance
James |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Wed Feb 21, 2018 6:54 am |
|
|
Ok, now I don't use that PIC but...
generally speaking you need to place a NOP instruction AFTER the sleep command, well, that's been said here a few times...it might be applicable for your PIC.
sleep current consumption can be VDD related. What the spec says is based on VDD. I know some are Ultra Low Power but NOT at 5volts, rather 1.8V, so you have to read the 'specs' real careful.
have another look at the data sheet to see how to disable each peripheral. Maybe code in order of the datasheet chapters ? So you don't have to 2nd guess yourself...did I do this or not ??
other who use that PIC will chime in, just take awhile, we're all in different time zones ! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Wed Feb 21, 2018 7:06 am |
|
|
I think you are misunderstanding the sleep modes.
Look at table 10-2 in the data sheet.
If you are putting the chip into a full 'deep sleep', then the RAM is lost, and the wake-up will result in a POR.
You probably want to be using the Low voltage sleep mode, which is almost the same, but retains the regulator running to feed the RAM. Slightly more power used, but it can wake to the next instruction. |
|
![](templates/subSilver/images/spacer.gif) |
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
|
Posted: Wed Feb 21, 2018 7:06 am |
|
|
Stuck a delay_cycles(1) after the sleep(DEEP_SLEEP) command and it made no difference - I still don't wake up, but the current increases.
The unit is running on 3.3V |
|
![](templates/subSilver/images/spacer.gif) |
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
|
Posted: Wed Feb 21, 2018 7:42 am |
|
|
I'm not worried about the RAM contents, as on a power up reset everything is loaded from eeprom anyway.
I'm running on batteries, so the key thing here is that I take as little power as possible when I am "off".
As such deep sleep should be perfect. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Wed Feb 21, 2018 8:10 am |
|
|
option ? use a higher capacity battery ??
I did this 'trick' 25 years ago when 10ma was 'low power'.....
While I understand the 'quest to reduce', consider your TIME vs a $1 upgrade in battery..
Jay |
|
![](templates/subSilver/images/spacer.gif) |
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
|
Posted: Wed Feb 21, 2018 8:12 am |
|
|
Love to - but designing a new product for our client to fit inside a case for an existing product, which means that I'm stuck with a 9V PP3 battery. |
|
![](templates/subSilver/images/spacer.gif) |
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
|
Posted: Wed Feb 21, 2018 8:19 am |
|
|
Back to deep sleep mode - I've also just added in the code, to check the state of the INT_EXT pin and then determine whether I need a H_TO_L or an L_TO_H wake and this makes no difference.
As mentioned - in deep sleep mode, the current does increase when I push the button - but the processor doesn't wake up. (And then you get stuck with a processor taking more power but unable to do anything).
According to the datasheet, on a wake the DSEN bit is automatically cleared. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Wed Feb 21, 2018 9:52 am |
|
|
The 'nop' after the sleep will make no difference to waking. What it does is avoid a problem on normal sleep that can lead to the next instruction being corrupted. It is required by the PIC.
On your power, you do need to switch off the USB. The best way is to only wake it when the USB connection is made. usb_detach is the call to disable the USB. All you do it test the connection sense pin, and only attach when this is high (usb_attach). |
|
![](templates/subSilver/images/spacer.gif) |
jeremiah
Joined: 20 Jul 2010 Posts: 1329
|
|
Posted: Thu Feb 22, 2018 9:38 pm |
|
|
As for your current in non deepsleep. I do a lot of low current applications with PIC24 chips. Some things to look out for:
PMD - Peripheral Module Disable - Use this to completely disable unused parts of your device before going to sleep. Be aware that doing this may reset some of the configuration SFR registers, so you may need to redo your setup routines after lifting the disable for some peripherals. UARTS come to mind here (I had to re-enable the TX buffer because using the PMD to disable the UART reset that bit to disabled).
Make sure all I/O are either driven or have appropriate pullups/pulldowns in the power down state.
Errata - Make sure you read your chips errata sheet. In the past I have been burned by extra power consumption because something doesn't fully cut off (like ADC for some chips) without a workaround.
We've used the PIC24F32KAxxx for sub micro amp current draw in sleep mode and the PIC24FJ64GA104 for single digit microamp current in sleep mode. It is possible if the chip supports it. |
|
![](templates/subSilver/images/spacer.gif) |
|