I'm trying to program a 16F15323 for a battery application.
I operate the µC with the internal 32 kHz low power oscillator (LFINTOSC).
Sleep mode works, wake up via a button also....
However, I would have to wake up the controller at fixed intervals (doesn't have to be too exact) about 1x per minute (preferably WITHOUT resetting), the variables should be preserved.
Timer1 only seems to run in wake-up mode (in this case, timer interrupts also work).
Does anyone have sample code for waking up from sleep mode? Or how can I use the watchdog for this? Can someone help me?
Thank you very much!
Frank
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"When the SLEEP instruction is being executed, the next instruction (PC + 1) is pre-fetched, so that on wake-up the processor could execute the next instruction after the SLEEP command." - this means that the µC is not reset after waking up but continues working directly after the SLEEP command!!!
My circuit is driven by a 9V battery over a MCP1702 LDO. The complete power consumption in sleep mode is about 3.9µA!!!
I'm not sure if all the presettings are really necessary.....
Here is my code as basis for a battery powered device - You can wake up the µC at any time by pressing a button against GND on PORTA. 5.
Otherwise the µC wakes up every 64 seconds, does its job and sleeps again!
(Maybe someone finds this program useful or helps someone else...)
Frank
'******************************************************************'* *'* *** (Compiled with GCB 0.98.010) *** *'* *'******************************************************************''*** Initialisation ***'Select chip model and speed#chip 16F15323#config mclr_off, FCMEN_OFF, WDT_ON,WDTCCS_LFINTOSC,WDTE_SWDTEN, LPBOREN_ON, BOREN_OFF, RSTOSC_LFINT, FEXTOSC_OFF'Low-Power Internal 32 kHz Oscillator#OPTION Explicit 'All variables must first be declared!!!DIMZaehlerASByte'Temporary counter#define SWITCH PORTA.5 'Switch to GND with a 470K pullup#define SoundOut PORTC.5 'Piezo Buzzer#define Valve_open PORTC.3 'Impulsdriven valve on H-bridge#define Valve_close PORTC.4 'Impulsdriven valve on H-bridgeWDTCON0=b'00100001''Set Watchdog to 64s nominal and turn WDT onCLRWDT'Clear Watchdog timer'Setup an Interrupt event when PORTA.5 goes negative.IOCAN5=1OnInterruptPORTChangeCallInterruptHandler'*** beep 5 times on startup and wait 5 seconds ***forzaehler=1to5Tone2000,5Wait500msnextwait5s'*** MAINLOOP ***do'*** beep 3 times ***forzaehler=1to3Tone4000,5Wait10msnext'*** Valve activation ***PulseOutValve_open,5msWait3sPulseOutValve_close,5msWait3sCCP1CON=CCP1CONANDb'01111111''CCPx Module Enable bit=0 => CCPx is disabledTRISC=b'00000000''Define all ports as output and set to GND (exclusively SWITCH)'*** Preparation for deep sleep ***LATC=b'00000000'TRISA=b'00100000'LATA=b'00000000'VREGCON=VREGCONORb'00000010''VREGPM=1 => Low-Power Sleep mode enabled in Sleep'Draws lowest current in Sleep, slower wake-upsleep'Sleep for 64s or push button on switchTone2000,5wait200msloop' '***SoundwithPWM-Modul(alternative)***' TRISC = b'11011111' 'RC5asOutput'' 'Module:CCP1(createdwith"PIC PPS Tool for GCB"!' RC5PPS = 0x0009 'CCP1>RC5' CCP1PPS = 0x0015 'RC5>CCP1(bi-directional)'' for zaehler = 1 to 10' #define PWM_Freq 4 'SetfrequencyinKHz' #define PWM_Duty 50 'Setdutycycleto50%' PWMOn 'TurnonthePWM' WAIT 300 ms 'Wait' PWMOff 'TurnoffthePWM' Wait 100 ms' next'*** ON INTERRUPT ***subInterruptHandlerifIOCAF5=1then'SWITCH was just pressedIOCAN5=0'Prevent the event from reentering the InterruptHandler routineIOCAF5=0'We must clear the flag in softwarewait5ms'debounce by waiting and seeing if still held downIOCAN5=1'ReEnable the InterruptHandler routineendifendsubEnd
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That's a really good power draw for sleep, nice job, and thanks for sharing the code. I know that nano amp is possible with these devices under certain situations, but probably not with the wdt enabled.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are right! But not with a MCP1702 LDO - this LDO needs about 2-3µA for itself and the WDT also has its price. The µC is operated in my circuit with 5V - with 3V3 it should have an even lower current consumption.
...but I am satisfied with 3.9µA complete power consumption. My battery should have 230mAh - that should last for 6,7 years standby time...
Frank
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Now I see that you were including the regulator, my mistake. The standby power for those MCP LDO regulators are amazing, I have used both the 5V and 3.3V models, and the TO92 packages are handy.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi to all,
I'm trying to program a 16F15323 for a battery application.
I operate the µC with the internal 32 kHz low power oscillator (LFINTOSC).
Sleep mode works, wake up via a button also....
However, I would have to wake up the controller at fixed intervals (doesn't have to be too exact) about 1x per minute (preferably WITHOUT resetting), the variables should be preserved.
Timer1 only seems to run in wake-up mode (in this case, timer interrupts also work).
Does anyone have sample code for waking up from sleep mode? Or how can I use the watchdog for this? Can someone help me?
Thank you very much!
Frank
Here is an example of using the software WDT. Will need adapting for your chip.
Hi kent_twt4,
thanks for your fast response and for your help! ...it seems that this chip needs more presettings...
First a link to the page where I found useful information about the watchdog:
http://embedded-lab.com/blog/lab-17-sleep-and-wake-pic-microcontrollers/
"When the SLEEP instruction is being executed, the next instruction (PC + 1) is pre-fetched, so that on wake-up the processor could execute the next instruction after the SLEEP command." - this means that the µC is not reset after waking up but continues working directly after the SLEEP command!!!
My circuit is driven by a 9V battery over a MCP1702 LDO. The complete power consumption in sleep mode is about 3.9µA!!!
I'm not sure if all the presettings are really necessary.....
Here is my code as basis for a battery powered device - You can wake up the µC at any time by pressing a button against GND on PORTA. 5.
Otherwise the µC wakes up every 64 seconds, does its job and sleeps again!
(Maybe someone finds this program useful or helps someone else...)
Frank
That's a really good power draw for sleep, nice job, and thanks for sharing the code. I know that nano amp is possible with these devices under certain situations, but probably not with the wdt enabled.
You are right! But not with a MCP1702 LDO - this LDO needs about 2-3µA for itself and the WDT also has its price. The µC is operated in my circuit with 5V - with 3V3 it should have an even lower current consumption.
...but I am satisfied with 3.9µA complete power consumption. My battery should have 230mAh - that should last for 6,7 years standby time...
Frank
Now I see that you were including the regulator, my mistake. The standby power for those MCP LDO regulators are amazing, I have used both the 5V and 3.3V models, and the TO92 packages are handy.