0
votes

Actually I'm using a PIC24FJ128GB204 and I've have problems with DeepSleep.

My device is composed by 4 buttons and several LED (a colored torch). Have a button that make device Sleep until I want to use it, same button wakes up my device.

Consumption will all LED are off is 10mA.

I've tried Sleep mode, simply function that goes in basic sleep and than wakeup after selected pin is asserted. Measuring consumption in Sleep mode I've 2.50mA. Working very well.

I've started to work with DeepSleep, since I don't need any code retention and just need to keep my device in lowest possible consumption state (but avoiding to use a slide power switch). I've used Datasheet example codes to implement my function. As result I can enter in this state and than I've 0.45mA as consumption.

I've set an INT0 (as datasheet suggested) to wake up my device and associated it to correct wakeup PIN.

Problems starts now:

  • When I press wakeup button, my consumption goes to 10mA as normal, but I can't light ON any led. Seems that my device is not responsive.

  • If I press again Sleep button, my device goes in Sleep mode and not DeepSleep since my consumption back to 2.50mA. Again, if I wake up my device, it wakes up but are not responsive. Doesn't metter how much time I try again, but my device never go again to DeepSleep untill I power off and on again my device.

I've performed some test but can't understand what happen. Maybe after DeepSleep device should be manually reset (tried without success) or maybe some configuration bit need to be set again. Or maybe configuration bits are uncorrect?

Here's interested parts of code:

CONFIGURATION

// CONFIG4
#pragma config DSWDTPS = DSWDTPS3       // Deep Sleep Watchdog Timer Postscale Select bits (1: 256 (8.3 mS))
#pragma config DSWDTOSC = LPRC          // DSWDT Reference Clock Select (DSWDT uses LPRC as reference clock)
#pragma config DSBOREN = ON             // Deep Sleep BOR Enable bit (DSBOR Enabled)
#pragma config DSWDTEN = OFF            // Deep Sleep Watchdog Timer Enable (DSWDT Disabled)
//#pragma config DSSWEN = OFF             // DSEN Bit Enable (Deep Sleep operation is always disabled)
#pragma config DSSWEN = ON              // DSEN Bit Enable (Deep Sleep is controlled by the register bit DSEN)
#pragma config PLLDIV = DIVIDE2         // USB 96 MHz PLL Prescaler Select bits (Oscillator input divided by 2 (8 MHz input))
#pragma config I2C1SEL = DISABLE        // Alternate I2C1 enable bit (I2C1 uses SCL1 and SDA1 pins)
#pragma config IOL1WAY = ON             // PPS IOLOCK Set Only Once Enable bit (Once set, the IOLOCK bit cannot be cleared)

// CONFIG3
#pragma config WPFP = WPFP0             // Write Protection Flash Page Segment Boundary (Page 0 (0x00))
#pragma config SOSCSEL = ON             // SOSC Selection bits (SOSC circuit selected)
#pragma config WDTWIN = PS25_0          // Window Mode Watchdog Timer Window Width Select (Watch Dog Timer Window Width is 25 percent)
#pragma config PLLSS = PLL_PRI          // PLL Secondary Selection Configuration bit (PLL is fed by the Primary oscillator)
#pragma config BOREN = ON               // Brown-out Reset Enable (Brown-out Reset Enable)
#pragma config WPDIS = WPDIS            // Segment Write Protection Disable (Disabled)
#pragma config WPCFG = WPCFGDIS         // Write Protect Configuration Page Select (Disabled)
#pragma config WPEND = WPENDMEM         // Segment Write Protection End Page Select (Write Protect from WPFP to the last page of memory)

// CONFIG2
#pragma config POSCMD = HS              // Primary Oscillator Select (HS Oscillator Enabled)
#pragma config WDTCLK = LPRC            // WDT Clock Source Select bits (WDT uses LPRC)
#pragma config OSCIOFCN = ON            // OSCO Pin Configuration (OSCO/CLKO/RA3 functions as port I/O (RA3))
#pragma config FCKSM = CSECME           // Clock Switching and Fail-Safe Clock Monitor Configuration bits (Clock switching is enabled, Fail-Safe Clock Monitor is enabled)
//#pragma config FCKSM = CSDCMD           // Clock Switching and Fail-Safe Clock Monitor Configuration bits (Clock switching and Fail-Safe Clock Monitor are disabled)
#pragma config FNOSC = PRIPLL           // Initial Oscillator Select (Primary Oscillator with PLL module (XTPLL,HSPLL, ECPLL))
#pragma config ALTRB6 = APPEND          // Alternate RB6 pin function enable bit (Append the RP6/ASCL1/PMPD6 functions of RB6 to RA1 pin functions)
#pragma config ALTCMPI = CxINC_RX       // Alternate Comparator Input bit (C1INC, C2INC and C3INC are on RB9 )
#pragma config WDTCMX = WDTCLK          // WDT Clock Source Select bits (WDT clock source is determined by the WDTCLK Configuration bits)
#pragma config IESO = OFF               // Internal External Switchover (Disabled)

// CONFIG1
#pragma config WDTPS = PS1024           // Watchdog Timer Postscaler Select (1:1,024)
#pragma config FWPSA = PR128            // WDT Prescaler Ratio Select (1:128)
#pragma config WINDIS = OFF             // Windowed WDT Disable (Standard Watchdog Timer)
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config ICS = PGx3               // Emulator Pin Placement Select bits (Emulator functions are shared with PGEC3/PGED3)
#pragma config LPCFG = OFF              // Low power regulator control (Disabled - regardless of RETEN)
//#pragma config LPCFG = ON               // Low power regulator control (Low voltage regulator controlled by RETEN bit)
#pragma config GWRP = OFF               // General Segment Write Protect (Write to program memory allowed)
#pragma config GCP = OFF                // General Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = OFF             // JTAG Port Enable (Disabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

TURNOFF FUNCTION

void TurnOff(void)
{

    T1CONbits.TON = 0;
    IEC0bits.T1IE = 0;

    /* turn off */
    OC1CON1bits.OCM = 0;
    OC2CON1bits.OCM = 0;
    OC3CON1bits.OCM = 0;
    OC4CON1bits.OCM = 0;
    OC5CON1bits.OCM = 0;
    //    OC6CON1bits.OCM = 0;

    if (!USB_BUS_SENSE)
    {
        USBMaskInterrupts();
        USBModuleDisable();

        OS_ENTER_CRITICAL();
        T2CONbits.TON = 0;
        IEC0bits.T2IE = 0;

        TRISA = 0xffff;
        TRISB = 0xffff;
        TRISC = 0xffff;

        //        I2C1CONLbits.I2CEN = 0;
        //        
        //        SPI1CON1Lbits.SPIEN = 0;
        //        SPI2CON1Lbits.SPIEN = 0;
        //        SPI3CON1Lbits.SPIEN = 0;
        //        
        //        U1MODEbits.UARTEN = 0;
        //        U2MODEbits.UARTEN = 0;
        //        U3MODEbits.UARTEN = 0;
        //        U4MODEbits.UARTEN = 0;
        //        
        //        DMACONbits.DMAEN = 0;
        //        
        //        U1CONbits.USBEN = 0;
        //        PMD1 = 0xffff;
        //        PMD2 = 0xffff;
        //        PMD3 = 0xffff;
        //        PMD4 = 0xffff;
        //        PMD5 = 0xffff;
        //        PMD6 = 0xffff;
        //        PMD7 = 0xffff;
        //        PMD8 = 0xffff;

        WDTDisable();
        LPAppState = OFF_ST;
        CNInit();

        Nop();
        Nop();

        OS_EXIT_CRITICAL();
        //#ifndef DEBUG_PENNA
        {

            //            ENTRATA IN SLEEP MODE(pag 164)

            //            TEST 1
            //            DSCONbits.DSEN = 1;
            //            DSCONbits.DSEN = 1;
            //            __asm__ volatile("pwrsav #0");

            //            TEST 2    non funziona anche se c'è scritto così sul manuale (pag 164)
            //            __asm__ volatile("disi #7");
            //            __asm__ volatile("mov #8000, w2");
            //            __asm__ volatile("mov w2, DSCON");
            //            __asm__ volatile("mov w2, DSCON");
            //            __asm__ volatile("nop");
            //            __asm__ volatile("nop");
            //            __asm__ volatile("nop");
            //            __asm__ volatile("PWRSAV #0");

            //            TEST 3
            DSCONbits.DSEN = 1;
            DSCONbits.DSEN = 1;
            __asm__ volatile("nop");
            __asm__ volatile("nop");
            __asm__ volatile("nop");
            __asm__ volatile("PWRSAV #0");

            //            TEST 4    - LOW VOLTAGE (pag. 420) [provato sia con CONFIG LPCFG=1 e 0, l'effetto si ha con 1 anche se da manuale c'è scritto il contrario]
            //            RCONbits.RETEN = 1;
            //            __asm__ volatile("PWRSAV #0");
        }
        //#endif

        USBDeviceInit();
    }

    WDTEnable();
    T2CONbits.TON = 1;
    IEC0bits.T2IE = 1;
}

INTERRUPT DECLARATION

//------------------------------------------------

/**
    void INTERRUPT_Initialize (void)
 */
void INTERRUPT_Initialize(void)
{
    //    INT0I: INT0 - External Interrupt 0
    //    Priority: 1
    IPC0bits.INT0IP = 1;

}

/**
   Section: External Interrupt Handlers
 */

void __attribute__((weak)) EX_INT0_CallBack(void)
{
    // Add your custom callback code here
    // Verifico se il dispositivo è uscito dal Deep Sleep (pag.165 datasheet)
    if (RCONbits.DPSLP == 1)
    {
        // Risveglio da deep sleep
        RCONbits.DPSLP = 0;
        DSCONbits.RELEASE = 0;

    }
}

/**
  Interrupt Handler for EX_INT0 - INT0
 */
void __attribute__((interrupt, no_auto_psv)) _INT0Interrupt(void)
{
    //***User Area Begin->code: INT0 - External Interrupt 0***

    EX_INT0_CallBack();

    //***User Area End->code: INT0 - External Interrupt 0***
    EX_INT0_InterruptFlagClear();
}
/**
    Section: External Interrupt Initializers
 */

/**
    void EXT_INT_Initialize(void)

    Initializer for the following external interrupts
    INT0
 */
void EXT_INT_Initialize(void)
{
    /*******
     * INT0
     * Clear the interrupt flag
     * Set the external interrupt edge detect
     * Enable the interrupt, if enabled in the UI. 
     ********/
    EX_INT0_InterruptFlagClear();
    EX_INT0_PositiveEdgeSet();
    EX_INT0_InterruptEnable();
}
1

1 Answers

0
votes

When I press wakeup button, my consumption goes to 10mA as normal, but I can't light ON any led. Seems that my device is not responsive

Your problem is here:

TRISA = 0xffff;
TRISB = 0xffff;
TRISC = 0xffff;

You set the pins to input before entering deep sleep, but I don't see anywhere in your code where you set the pins up after you exit sleep so they are still acting as inputs and thus you won't be able to light an LED.