PIC24FJ256GA702 - Get into sleep mode

Thread Starter

JLC_Microchip

Joined Jun 4, 2019
12
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 :

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();
Mod edit: code tags
 
Last edited by a moderator:

Thread Starter

JLC_Microchip

Joined Jun 4, 2019
12
Hello Bob,

PIC is used "bare".
Here are the components around it :
- a (10k + 0.1k) resistors between VCC and MCLR pin,
- a 1K resistor between RB5 and LED, cathode connected to 0v.

At the beginning, I used capacitors (as datasheet preconizes) :
- on VCap pin
- on VDD
- on the junction between 10k and 0.1k
I removed all of them, results are identical.

Power comes from a laboratory supply, current limit is around 2A, voltage is 3v.
The meter is inserted between de supply positive plug and VDD.
 

jpanhalt

Joined Jan 18, 2008
11,087
I haven't worked with that device, but I took a quick look at its datasheet. The first place I would look for a high sleep current is whether the HF oscillators are shut down. There is a myriad of oscillators settings for that chip compared to my old friends, the 8-bit chips. Are you sure that C instruction sets them all to the lowest power state?
 

Thread Starter

JLC_Microchip

Joined Jun 4, 2019
12
I haven't worked with that device, but I took a quick look at its datasheet. The first place I would look for a high sleep current is whether the HF oscillators are shut down. There is a myriad of oscillators settings for that chip compared to my old friends, the 8-bit chips. Are you sure that C instruction sets them all to the lowest power state?
That's what datasheet says about the sleep() instruction: it stops clocks.
Only that solution should lower power state to about µA, not mA.
There is also an internal low voltage regulator that can lower more.
I'm using the internal Fast RC oscillator (FRC).
 

jpanhalt

Joined Jan 18, 2008
11,087
That's what datasheet says about the sleep() instruction: it stops clocks.
Only that solution should lower power state to about µA, not mA.
There is also an internal low voltage regulator that can lower more.
I'm using the internal Fast RC oscillator (FRC).
I saw the "Fast RC". Have you checked the Assembly decompile to be sure?
 

Thread Starter

JLC_Microchip

Joined Jun 4, 2019
12
Hello,

I've just past a few hours to measure and test codes again and again for the same result...

I removed the PIC from the Lab Board to measure any currents due to a probably faulting board, but there was no leaking current.
This PIC came from samples I ordered on MicrochipSample. So I tried another identical PIC coming from that same samples... and all problems disappeared !!!

Problem was a faulty PIC !!!
Such a wasted time to search solutions on the web... arrrg.
Was it faulty when arrived from Microchip or did I burn anything...?

So now the program works well, and PIC consumption is less thant 1 µA !
Here are the measures in function of RETEN and VREGS bits from RCON register when sleep is called :

RETEN VREGS Itot
0 0 4.5µA
0 1 41.5µA
1 0 0.35µA
1 1 2.7µA

Be carreful to datahseet PIC24FJ705 Family (DS30010118D), there's an error on page 114.
Correction is introduced in Errata sheet & Clarifications (DS80000718E), corresponding to the table above.

Thanks a lot for your answers and helps.
Regards,
JL
 

jpanhalt

Joined Jan 18, 2008
11,087
Was the original chip a new chip or had it been used for something else? There seem to be several settings that affect how the oscillators work or don't work in sleep. You might want to check to see whether the first chip, if not new, had those settings changed.
 
Top