Hello,
I spent many weeks trying to search the solution to set that PIC into sleep mode.
I found many informations from several sources : Microchip developpers, examples, and so on. But none helped me to make it work.
sleep() instruction I use stops the program but PIC is still consumming about 1~2 mA (should be close to µA).
PIC is PIC24FJ256GA702, running with FRC 8MHz at 3v.
My program make a LED blinks once and calls sleep instruction.
Except the LED and MCLR, I have not connected any pins, all of them are configured as outputs with low level.
Power signals are all connected as PIC requires.
In software, watchdog and all peripherals are disabled.
Looks like something is still running...
Would you have any ideas please ?
Thanks a lot.
Here is the code :
Mod edit: code tags
I spent many weeks trying to search the solution to set that PIC into sleep mode.
I found many informations from several sources : Microchip developpers, examples, and so on. But none helped me to make it work.
sleep() instruction I use stops the program but PIC is still consumming about 1~2 mA (should be close to µA).
PIC is PIC24FJ256GA702, running with FRC 8MHz at 3v.
My program make a LED blinks once and calls sleep instruction.
Except the LED and MCLR, I have not connected any pins, all of them are configured as outputs with low level.
Power signals are all connected as PIC requires.
In software, watchdog and all peripherals are disabled.
Looks like something is still running...
Would you have any ideas please ?
Thanks a lot.
Here is the code :
C:
// FSEC
#pragma config BWRP = OFF //Boot Segment Write-Protect bit->Boot Segment may be written
#pragma config BSS = DISABLED //Boot Segment Code-Protect Level bits->No Protection (other than BWRP)
#pragma config BSEN = OFF //Boot Segment Control bit->No Boot Segment
#pragma config GWRP = OFF //General Segment Write-Protect bit->General Segment may be written
#pragma config GSS = DISABLED //General Segment Code-Protect Level bits->No Protection (other than GWRP)
#pragma config CWRP = OFF //Configuration Segment Write-Protect bit->Configuration Segment may be written
#pragma config CSS = DISABLED //Configuration Segment Code-Protect Level bits->No Protection (other than CWRP)
#pragma config AIVTDIS = OFF //Alternate Interrupt Vector Table bit->Disabled AIVT
// FBSLIM
#pragma config BSLIM = 8191 //Boot Segment Flash Page Address Limit bits->8191
// FOSCSEL
#pragma config FNOSC = FRC //Oscillator Source Selection->Internal Fast RC (FRC)
#pragma config PLLMODE = DISABLED //PLL Mode Selection->No PLL used; PLLEN bit is not available
#pragma config IESO = OFF //Two-speed Oscillator Start-up Enable bit->Start up with user-selected oscillator source
// FOSC
#pragma config POSCMD = NONE //Primary Oscillator Mode Select bits->Primary Oscillator disabled
#pragma config OSCIOFCN = ON //OSC2 Pin Function bit->OSC2 is general purpose digital I/O pin
#pragma config SOSCSEL = OFF //SOSC Power Selection Configuration bits->Digital (SCLKI) mode
#pragma config PLLSS = PLL_PRI //PLL Secondary Selection Configuration bit->PLL is fed by the Primary oscillator
#pragma config IOL1WAY = ON //Peripheral pin select configuration bit->Allow only one reconfiguration
#pragma config FCKSM = CSDCMD //Clock Switching Mode bits->Both Clock switching and Fail-safe Clock Monitor are disabled
// FWDT
#pragma config WDTPS = PS32768 //Watchdog Timer Postscaler bits->1:32768
#pragma config FWPSA = PR128 //Watchdog Timer Prescaler bit->1:128
#pragma config FWDTEN = OFF //Watchdog Timer Enable bits->WDT and SWDTEN disabled
#pragma config WINDIS = OFF //Watchdog Timer Window Enable bit->Watchdog Timer in Non-Window mode
#pragma config WDTWIN = WIN25 //Watchdog Timer Window Select bits->WDT Window is 25% of WDT period
#pragma config WDTCMX = WDTCLK //WDT MUX Source Select bits->WDT clock source is determined by the WDTCLK Configuration bits
#pragma config WDTCLK = LPRC //WDT Clock Source Select bits->WDT uses LPRC
// FPOR
#pragma config BOREN = OFF //Brown Out Enable bit->Brown Out Disabled
#pragma config LPCFG = ON //Low power regulator control->Retention Sleep controlled by RETEN
#pragma config DNVPEN = DISABLE //Downside Voltage Protection Enable bit->Downside protection disabled when BOR is inactive
// FICD
#pragma config ICS = NONE //ICD Communication Channel Select bits->Reserved, do not use
#pragma config JTAGEN = OFF //JTAG Enable bit->JTAG is disabled
// FDEVOPT1
#pragma config ALTCMPI = DISABLE //Alternate Comparator Input Enable bit->C1INC, C2INC, and C3INC are on their standard pin locations
#pragma config TMPRPIN = OFF //Tamper Pin Enable bit->TMPRN pin function is disabled
#pragma config SOSCHP = OFF //SOSC High Power Enable bit (valid only when SOSCSEL = 1->Enable SOSC low power mode
#pragma config ALTI2C1 = ALTI2CEN //Alternate I2C pin Location->SDA1 and SCL1 on RB9 and RB8
// CPDIV 1:1; PLLEN disabled; DOZE 1:8; RCDIV FRC; DOZEN disabled; ROI disabled;
CLKDIV = 0x3000;
// STOR disabled; STORPOL Interrupt when STOR is 1; STSIDL disabled; STLPOL Interrupt when STLOCK is 1; STLOCK disabled; STSRC SOSC; STEN disabled; TUN Center frequency;
OSCTUN = 0x00;
// ROEN disabled; ROSWEN disabled; ROSEL FOSC; ROOUT disabled; ROSIDL disabled; ROSLP disabled;
REFOCONL = 0x00;
// RODIV 0;
REFOCONH = 0x00;
// DCOTUN 0;
DCOTUN = 0x00;
// DCOFSEL 8; DCOEN disabled;
DCOCON = 0x700;
// DIV 0;
OSCDIV = 0x00;
// TRIM 0;
OSCFDIV = 0x00;
// AD1MD disabled; T3MD disabled; T1MD disabled; U2MD disabled; T2MD disabled; U1MD disabled; SPI2MD disabled; SPI1MD disabled; I2C1MD disabled;
PMD1 = 0x38F9;
// IC3MD disabled; OC1MD disabled; IC2MD disabled; OC2MD disabled; IC1MD disabled; OC3MD disabled;
PMD2 = 0x707;
// PMPMD disabled; RTCCMD disabled; CMPMD disabled; CRCMD disabled; I2C2MD disabled;
PMD3 = 0x782;
// CTMUMD disabled; REFOMD disabled; LVDMD disabled;
PMD4 = 0x0E;
// CCP2MD disabled; CCP1MD disabled; CCP4MD disabled; CCP3MD disabled; CCP5MD disabled;
PMD5 = 0x1F;
// SPI3MD disabled;
PMD6 = 0x01;
// DMA1MD disabled; DMA0MD disabled;
PMD7 = 0x30;
// CLC1MD disabled; CLC2MD disabled;
PMD8 = 0x0C;
// CF no clock failure; NOSC FRC; SOSCEN disabled; POSCEN disabled; CLKLOCK unlocked; OSWEN Switch is Complete; IOLOCK not-active;
__builtin_write_OSCCONH((uint8_t) (0x00));
__builtin_write_OSCCONL((uint8_t) (0x00));
ODCA = 0;
IOCPA = 0;
IOCNA = 0;
IOCFA = 0;
IOCPUA = 0;
IOCPDA = 0;
ANSA = 0; // Disable analog inputs
LATA = 0; // Outputs low
TRISA = 0; // Pins as outputs
ODCB = 0;
IOCPB = 0;
IOCNB = 0;
IOCFB = 0;
IOCPUB = 0;
IOCPDB = 0;
ANSB = 0;
LATB = 0;
TRISB = 0;
// Disable all peripheral clocks
PMD1 = 0xFFFF;
PMD2 = 0xFFFF;
PMD3 = 0xFFFF;
PMD4 = 0xFFFF;
PMD5 = 0xFFFF;
PMD6 = 0xFFFF;
PMD7 = 0xFFFF;
PMD8 = 0xFFFF;
// tried those nops as seen in one example but useless
asm( "nop" );
asm( "nop" );
// tried that trick too as seen in one example but useless
// RCONbits.SWDTEN = 0;
// Get asleep (should stop all clocks)
Sleep();
Last edited by a moderator: