I need some help.
I'm using a TMS320F28335 in a battery powered device and I need to enter halt mode when the device is not in use to conserve battery power.
Randomly, the device seems to get stuck when going into halt mode, (maybe ~5% of the time).
Haven't been able to figure out why it's happening.
Here's where I'm setting the LPM mode before entering the main loop:
......................................................................................................................................
// Write the LPM code value
EALLOW;
if (SysCtrlRegs.PLLSTS.bit.MCLKSTS != 1) // Only enter low power mode when PLL is not in limp mode.
{
SysCtrlRegs.LPMCR0.bit.LPM = 0x0002; // LPM mode = Halt
}
EDIS;
......................................................................................................................................
Here's where I enter LPM mode. This is called upon either by a button press or a timeout.
......................................................................................................................................
void go2sleep(void)
{
PieCtrlRegs.PIEIER1.bit.INTx6 = 0; //disable adc int
//PieCtrlRegs.PIEIER8.bit.INTx1 = 1; //disable I2C int
PieCtrlRegs.PIEIER4.bit.INTx1 = 0; //disable ECAP isr
AllOff(); //turn off all device indicators
SetLEDState(LED_GREEN, LED_BLINK2); //let user know it's still alive
if(vib_enabled)Quickbuzz(3); //beep or buzz to confirm entering LPM mode
else Quickbeep(5);
DELAY_US(100000);
asm(" EALLOW");
//SysCtrlRegs.WDCR = 0x006F; //Disable Watchdog
//Power-down the ADC
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 0;
//AdcRegs.ADCTRL2.bit.ADCBGPWD = 0;
AdcRegs.ADCTRL3.bit.ADCPWDN = 0;
//AdcRegs.ADCTRL2.bit.ADCREFPWD = 0;
//SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 0;
//Turn-off clocks
SysCtrlRegs.PCLKCR0.all = 0;
SysCtrlRegs.PCLKCR1.all = 0;
SysCtrlRegs.PCLKCR3.all = 0;
//Enable all pull-ups
GpioCtrlRegs.GPAPUD.all = 0; // The pullups have to be enabled to minimize the
GpioCtrlRegs.GPBPUD.all = 0; // leakage currents, thereby the HALT mode current
// stays within the spec quoted in the datasheet.
EALLOW;
//Write the LPM code value
if (SysCtrlRegs.PLLSTS.bit.MCLKSTS != 1) // Only enter low power mode when PLL is not in limp mode.
{
SysCtrlRegs.LPMCR0.bit.LPM = 0x0002; // LPM mode = Halt
}
EDIS;
//FlashRegs.FPWR.bit.PWR = FLASH_SLEEP; // Put the Flash to sleep
//asm(" RPT #7 || NOP");
//asm(" EDIS");
// Force device into HALT
asm(" IDLE"); // Device waits in IDLE until falling edge on GPIO pin wakes device from halt mode
}
......................................................................................................................................
Here's the wake interrupt which is triggered from one of the port A IO pins
......................................................................................................................................
interrupt void WAKE_ISR(void)
{
asm(" EALLOW");
//undo what was done in go2sleep()
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;
AdcRegs.ADCTRL3.bit.ADCPWDN = 1;
SysCtrlRegs.PCLKCR0.all = 0xFD3C;
SysCtrlRegs.PCLKCR1.all = 0xFF3F;
SysCtrlRegs.PCLKCR3.all = 0x3F00;
GpioCtrlRegs.GPAPUD.all = 0x00000FDF;
GpioCtrlRegs.GPBPUD.all = 0;
//FlashRegs.FPWR.bit.PWR = 0;
asm(" EDIS");
DELAY_US(100000);
if(vib_enabled)Quickbuzz(3); //beep or buzz to confirm coming out of LPM
else Quickbeep(4);
sleepflag=0;
sleeptimer=0;
//AllOff();
timer2flag=1; //go into pwr LED handling
PieCtrlRegs.PIEIER1.bit.INTx6 = 1; //enable adc int
PieCtrlRegs.PIEIER4.bit.INTx1 = 1; //enable ECAP isr
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
//PieCtrlRegs.PIEACK.bit.ACK1 = 1;
SetLEDState(LED_GREEN, LED_ON);
}