關(guān)于lpc1112深睡眠(低功耗)的調(diào)試報(bào)告
由于產(chǎn)品為移動(dòng)設(shè)備,所以功耗要求是比較嚴(yán)格的。目前采用了大MCU+小MCU的方式實(shí)現(xiàn),小MCU主要是控制大MCU的電源,以實(shí)現(xiàn)系統(tǒng)的最低功耗。當(dāng)然也就要求小單片機(jī)也在不工作的時(shí)候,進(jìn)入低功耗狀態(tài)。
大MCU目前采用的是LPC1788,掉電模式理論最低功耗為65uA,但是實(shí)際調(diào)試并沒(méi)有達(dá)到那么?。ㄒ?yàn)橥庠O(shè)沒(méi)有完全斷電)。所以用小MCU來(lái)控制大MCU的電源,在需要的時(shí)候,在給大MCU供電。
小MCU采用的是LPC111x(lpc1112/28pin),深睡眠模式的理論值約為6uA(這個(gè)。)。
Lpc1112在不接外設(shè)的情況下,首先對(duì)深睡眠功耗進(jìn)行測(cè)試,目前達(dá)到了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); //清除標(biāo)志
SYSCON->STARTRSRP0CLR = 1<<6; /*清除喚醒中斷標(biāo)志 */
__nop();
key_value=2;
}
void WAKEUP5_IRQHandler(void)
{
//PMU->PCON = (1<<8); //清除標(biāo)志
SYSCON->STARTRSRP0CLR = 1<<5; /*清除喚醒中斷標(biāo)志 */
__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、 需要對(duì)io重新配置,函數(shù)config_ios:
a) 配置位普通的io口功能,并且是下拉
b) 將io設(shè)置為輸出模式,并輸出信號(hào)為0;
c) 再將io口設(shè)置為輸入。(實(shí)驗(yàn)證明如果不再設(shè)置為輸入模式,功耗將增加)
注意:對(duì)io口的配置,也是在lpc1788芯片上進(jìn)行過(guò)實(shí)驗(yàn)的,通過(guò)以上操作會(huì)使功耗比較低。所以目前對(duì)單片機(jī)要進(jìn)入低功耗狀態(tài),暫時(shí)對(duì)io配置都如上方式進(jìn)行。
2、以上配置,并沒(méi)有每一行代碼進(jìn)行調(diào)試,一些配置可能可以配置為其他值。
其中:
SYSCON->PDRUNCFG |=(1<<3); //BOD power down//
//SYSCON->PDSLEEPCFG = 0x000018FF;
SYSCON->PDSLEEPCFG = 0x0000ffFF;
這兩條代碼不能去掉。
SYSCON->PDSLEEPCFG 配置為0x00000aff,也會(huì)增加功耗,配置位0x000018FF功耗較低,所以看了看寄存器,在沒(méi)什么大問(wèn)題的情況下,索性都配置為0x0000ffFF。
因?yàn)樽蛱觳砰_(kāi)始建工程,找資料,所以對(duì)LPC1112還不是很熟悉,但是基本能滿足功耗要求,暫時(shí)先記錄下來(lái),后續(xù)還是需要對(duì)這款單片機(jī)低功耗配置進(jìn)行更深入的了解。