View previous topic :: View next topic |
Author |
Message |
Marco27293
Joined: 09 May 2020 Posts: 126
|
PIC18F47J53 CCS C Compiler 5.090 restart_cause info |
Posted: Tue Oct 13, 2020 4:43 am |
|
|
Good morning,
Is it possible to exit deep sleep using ext1 interrupt remapped on PIN_C1 ?
If yes, will restart_cause() return EXT_FROM_DS ?
During deep sleep is it possible to keep high PIN_B2 in order to keep enabled a voltage switch (required to supply the peripheral which eventually trigger the isr on PIN_C1) ?
regards |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Tue Oct 13, 2020 5:13 am |
|
|
quick reply..
While I've never had any PIC goto sleep in 2.5 decades, I was curious, downloaded the datasheet. section 4.6.2(page 56..) does explain it ! yes, a pin set high before will remain high.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Tue Oct 13, 2020 5:13 am |
|
|
Yes.
The pin if set to drive high, will remain driving high. You will have to
ensure your wake up code does not change this if you want it to remain
driving high. You need to clear the 'RELEASE' bit to allow normal I/O.
The compiler will probably do this.
INT1 will need to be setup with PPS to this pin (just to confuse CCS calls
this INT1).
Obviously any current drawn on B2, will increase the sleep current. |
|
|
Marco27293
Joined: 09 May 2020 Posts: 126
|
|
Posted: Tue Oct 13, 2020 5:23 am |
|
|
Thanks,
I do not clearly understand: Will restart_cause() return EXT_FROM_DS ?
regards |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Tue Oct 13, 2020 6:12 am |
|
|
Yes.
But when you re-awaken, the I/O pins wil be locked in the state they were
when you went to sleep, until 'RELEASE' is cleared/ So you need to
program their I/O levels and state, restore your variables and then clear this bit.
Understand, if you program a variable like:
Code: |
int8 a_variable=10;
|
This will be set to '10' when the chip boots or restarts from deep sleep.
However if you code like
Code: |
int8 a_variable;
#bit RELEASE=getenv("bit:RELEASE")
void main(void)
{
int16 cause;
cause=restart_cause();
if (cause==MORMAL_POWER_UP || cause==MCLR_FROM_RUN)
{
//set all your variables to the 'power on' values
a_variable=10;
//etc..
}
else if (cause==EXT_FROM_DS)
{
//set all your variables to their 'running' values
a_variable=read_eeprom(0); //using EEPROM for example
//etc..
out[ut_high(xxx); //etc.
RELEASE=0; //release I/O pins back to program control
}
else if (cause==WDT_TIMEOUT || cause==BROWNOUT_RESTART)
{
//here variables won't have been lost can leave as they are
}
//main code
}
|
|
|
|
|