关于lpc1112深睡眠(低功耗)的调试报告
扫描二维码
随时随地手机看文章
由于产品为移动设备,所以功耗要求是比较严格的。目前采用了大MCU+小MCU的方式实现,小MCU主要是控制大MCU的电源,以实现系统的最低功耗。当然也就要求小单片机也在不工作的时候,进入低功耗状态。
大MCU目前采用的是LPC1788,掉电模式理论最低功耗为65uA,但是实际调试并没有达到那么小(因为外设没有完全断电)。所以用小MCU来控制大MCU的电源,在需要的时候,在给大MCU供电。
小MCU采用的是LPC111x(lpc1112/28pin),深睡眠模式的理论值约为6uA(这个。)。
Lpc1112在不接外设的情况下,首先对深睡眠功耗进行测试,目前达到了5uA左右。
以下为源代码:
#include "nxplpc11xx.h"
#include "pmu.h"
#define NVIC_LP_SLEEPDEEP 1<<2
extern int key_value;
void WAKEUP6_IRQHandler(void)
{
//PMU->PCON = (1<<8); //清除标志
SYSCON->STARTRSRP0CLR = 1<<6; /*清除唤醒中断标志 */
__nop();
key_value=2;
}
void WAKEUP5_IRQHandler(void)
{
//PMU->PCON = (1<<8); //清除标志
SYSCON->STARTRSRP0CLR = 1<<5; /*清除唤醒中断标志 */
__nop();
key_value=1;
}
void config_ios(void);
void PMU_DeepSleep(void)
{
//reset IOs
config_ios();
/* Specify peripherals to be powered up again when returning from deep sleep mode */
SYSCON->PDAWAKECFG = SYSCON->PDRUNCFG;
SYSCON->PDRUNCFG |=(1<<3); //BOD power down
/* Switch MAINCLKSEL to IRC */
SYSCON->MAINCLKSEL = 0;
SYSCON->MAINCLKUEN = 0;
SYSCON->MAINCLKUEN = 1;
while (!(SYSCON->MAINCLKUEN & 0x01));
/* Ensure DPDEN is disabled in the power control register */
PMU->PCON = (1<<11); //Clear DPDFLAG if it was set
/* Clear the Deep Sleep Flag */
PMU->PCON = (1<<8);
/* All OFF */
//SYSCON->PDSLEEPCFG = 0x000018FF;
SYSCON->PDSLEEPCFG = 0x0000ffFF;
/* Specify peripherals to be powered up again when returning from deep sleep mode */
//SYSCON->PDAWAKECFG = SYSCON->PDRUNCFG;
///GPIO0-6
IOCON->PIO0_6 &= ~0x07;
IOCON->PIO0_6 |= 0x20;
GPIO0->DIR &= ~(0x01 << 6);
IOCON->PIO0_5 &= ~0x07;
IOCON->PIO0_5 |= 0x20;
GPIO0->DIR &= ~(0x01 << 5);
/* Only edge trigger. activation polarity on P0.5 p0.6 is FALLING EDGE. */
SYSCON->STARTAPRP0 &=~(1<<6|1<<5); //0x00000000;
/* Clear all wakeup source */
SYSCON->STARTRSRP0CLR |=(1<<6|1<<5); //0xFFFFFFFF;
/* Enable Port 0.4 as wakeup source. */
SYSCON->STARTERP0 = (0x1<<6|1<<5);
NVIC_ClearPendingIRQ(WAKEUP6_IRQn);
NVIC_EnableIRQ(WAKEUP6_IRQn); // P0.6 as wakeup
NVIC_ClearPendingIRQ(WAKEUP5_IRQn);
NVIC_EnableIRQ(WAKEUP5_IRQn); // P0.5 as wakeup
SCB->SCR = NVIC_LP_SLEEPDEEP; //0x04
/* Enter Deep Sleep mode */
__wfi();
}
void config_ios(void)
{
/* Configure all IOs as GPIO w/o pull-up & pull-down resistors */
IOCON->RESET_PIO0_0 = 0xC8; // RST_BOOT/P0_0
IOCON->PIO0_1 = 0xC8; //0xC0; // CLKOUT/CT32B0_MAT2/USB_SOF
IOCON->PIO1_8 = 0xC8;
IOCON->PIO0_2 = 0xC8; // SSEL/CT16B0_CAP0 //Trigger input
IOCON->PIO0_3 = 0xC8; //
IOCON->PIO0_4 = 0x80; // PIO
IOCON->PIO0_5 = 0x80; // PIO
IOCON->PIO1_9 = 0xC8; // CT16B1_MAT0
IOCON->PIO0_6 = 0xC8; // SCK0
IOCON->PIO0_7 = 0xC8;
IOCON->PIO0_8 = 0xC8; //0xC0; // SSP_MISO/CT16B0_MAT0/TRACE_CLK; MISO
IOCON->PIO0_9 = 0xC8; //0xC0; // SSP_MOSI/CT16B0_MAT1/TRACE_SWV; MOSI
IOCON->PIO0_10 = 0xC8; // JTAG_CLK/P0_10/SSP_CLK/CT16B0_MAT2
//IOCON->PIO1_10 = 0xC8; // ADCIN6/CT16B1_MAT1
IOCON->PIO0_11 = 0xC9; // JTAG_TDI/P0_11/ADCIN0/CT32B0_MAT3
IOCON->PIO1_0 = 0xC9; // JTAG_TMS/P1_0/ADCIN1/CT32B1_CAP0
IOCON->PIO1_1 = 0xC9; // JTAG_TDO/P1_1/ADCIN2/CT32B1_MAT0
IOCON->PIO1_2 = 0xC9; // JTAG_TRST/P1_2/ADCIN3/CT32B1_MAT1
IOCON->PIO1_3 = 0xC9; // ARM_SWD/P1_3/ADCIN4/CT32B1_MAT2
IOCON->PIO1_4 = 0xC8; // ADCIN5/CT32B1_MAT3/WAKEUP
//IOCON->PIO1_11 = 0xC8; // ADCIN7
IOCON->PIO1_5 = 0xC9; // UART_DIR/CT32B0_CAP0
IOCON->PIO1_6 = 0xC9; // UART_RXD/CT32B0_MAT0
IOCON->PIO1_7 = 0xC9; // UART_TXD/CT32B0_MAT1
/* GPIOs at outputs */
GPIO0->DIR = ~0; //Trigger Pin input only
GPIO1->DIR = ~0; //WAKEUP Pin and PIO1_6/RXD input only
/* GPIO outputs to LOW */
GPIO0->DATA = 0x0;
GPIO1->DATA = 0X0;
/* GPIOs at inputs */
GPIO0->DIR = 0;
GPIO1->DIR = 0;
return;
}
1、 需要对io重新配置,函数config_ios:
a) 配置位普通的io口功能,并且是下拉
b) 将io设置为输出模式,并输出信号为0;
c) 再将io口设置为输入。(实验证明如果不再设置为输入模式,功耗将增加)
注意:对io口的配置,也是在lpc1788芯片上进行过实验的,通过以上操作会使功耗比较低。所以目前对单片机要进入低功耗状态,暂时对io配置都如上方式进行。
2、以上配置,并没有每一行代码进行调试,一些配置可能可以配置为其他值。
其中:
SYSCON->PDRUNCFG |=(1<<3); //BOD power down//
//SYSCON->PDSLEEPCFG = 0x000018FF;
SYSCON->PDSLEEPCFG = 0x0000ffFF;
这两条代码不能去掉。
SYSCON->PDSLEEPCFG 配置为0x00000aff,也会增加功耗,配置位0x000018FF功耗较低,所以看了看寄存器,在没什么大问题的情况下,索性都配置为0x0000ffFF。
因为昨天才开始建工程,找资料,所以对LPC1112还不是很熟悉,但是基本能满足功耗要求,暂时先记录下来,后续还是需要对这款单片机低功耗配置进行更深入的了解。