1.该代码使用内部时钟 internal clock source 8 MHz Core clock = 4MHz, BusClock = 2MHz
2.VLPR模式下芯片功耗610uA
3.VLPS休眠模式下功耗110uA,手册上功耗5uA左右,为什么我的功耗怎么高,求助各位大神!
小白先谢谢各位了~
//---主函数
int main(void)
{
GPIO_InputPinInit();
GPIO_OutputPinInit();
LPTMR_init(1000,LPTMR_USE_LPOCLK);
GPIO_HAL_ClearPinOutput(GPIOB, 10);
PowerManager_EnterVLPR();
PowerManager_EnterVLPS();
while(1)
{
}
}
//---VLPR模式
uint8_t PowerManager_EnterVLPR(void)
{
uint16_t i = 0 ;
uint32_t clkdiv1 = 0;
//---系统时钟分频
clkdiv1 |= SIM_CLKDIV1_OUTDIV1(1U);
clkdiv1 |= SIM_CLKDIV1_OUTDIV4(7U);
SIM_WR_CLKDIV1(SIM, clkdiv1);
//---Set MCG mode
// 使能 VLPR
SMC_PMPROT = SMC_PMPROT_AVLP_MASK;
//--- 控制进入VLPR
SMC_PMCTRL &= ~SMC_PMCTRL_RUNM_MASK;
SMC_PMCTRL |= 0x40;
//---
for (i = 0 ; i < 10000 ; i++)
{ /* check that the value of REGONS bit is not 0
once it is a zero we can stop checking */
if ((PMC_REGSC & PMC_REGSC_REGONS_MASK) ==0x04)
{
/* 0 Regulator is in stop regulation or in transition
to/from it
1 MCU is in Run regulation mode */
}
else
{
break;
}
}
if ((PMC_REGSC & PMC_REGSC_REGONS_MASK) ==0x04)
{
return 0x24;
}
/* SMC_PMSTAT register only exist in Mode Controller 2 MCU versions */
if ((SMC_PMSTAT & SMC_PMSTAT_PMSTAT_MASK) == 0x04)
{
return SMC_PMSTAT;
}
/* //--- Set SIM setting
//---Set OSCERCLK setting
OSC_BWR_CR_ERCLKEN(OSC,false);
OSC_BWR_CR_EREFSTEN(OSC, false);
*/
return 0x14;
}
//---VLPS休眠模式
void PowerManager_EnterVLPS(void)
{
volatile unsigned int dummyread;
/* The PMPROT register may have already been written by init code
If so then this next write is not done since
PMPROT is write once after RESET
allows the MCU to enter the VLPR, VLPW, and VLPS modes.
If AVLP is already writen to 0
Stop is entered instead of VLPS*/
SMC_PMPROT = SMC_PMPROT_AVLP_MASK;
/* Set the STOPM field to 0b010 for VLPS mode */
SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK;
SMC_PMCTRL |= 0X02;//SMC_PMCTRL_STOPM(0x2);
/*wait for write to complete to SMC before stopping core */
// SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
SMC_STOPCTRL &= ~SMC_STOPCTRL_PSTOPO_MASK;
SMC_STOPCTRL &= ~SMC_STOPCTRL_LPOPO_MASK;
dummyread = SMC_PMCTRL;
dummyread++;
/* Now execute the stop instruction to go into VLPS */
asm("WFI");
}
|