ch32v003低功耗問題


功耗太高了,沒有外圍設(shè)備4Ma,耗電太快了,得加低功耗功能,代碼很簡(jiǎn)單,就是main里進(jìn)入待機(jī)(睡眠功耗也高),中斷觸發(fā)一次,main里繼續(xù)待機(jī),但是 中斷只觸了一次,一直在串口顯示一直在中斷,好奇怪,下面是在例程里改的


/**********************************?(C)?COPYRIGHT?*******************************
?*?File?Name??????????:?main.c
?*?Author?????????????:?WCH
?*?Version????????????:?V1.0.0
?*?Date???????????????:?2023/12/25
?*?Description????????:?Main?program?body.
?*********************************************************************************
?*?Copyright?(c)?2021?Nanjing?Qinheng?Microelectronics?Co.,?Ltd.
?*?Attention:?This?software?(modified?or?not)?and?binary?are?used?for
?*?microcontroller?manufactured?by?Nanjing?Qinheng?Microelectronics.
?*******************************************************************************/

/*
?*@Note
?*low?power,?sleep?mode?routine:
?*EXTI_Line0(PD0)
?*This?routine?demonstrates?that?WFI?enters?the?sleep?mode,?and?the?PD0?pin?input
?*low?level?triggers?the?external?interrupt?EXTI_Line0?to?exit?the?sleep?mode,
?*Program?execution?continues?after?wake-up.
?*
?*/

#include?"debug.h"

/*?Global?define?*/

/*?Global?Variable?*/

/*********************************************************************
?*?@fn??????EXTI0_INT_INIT
?*
?*?@brief???Initializes?EXTI0?collection.
?*
?*?@return??none
?*/
void?EXTI0_INT_INIT(void)
{
????GPIO_InitTypeDef?GPIO_InitStructure?=?{0};
????EXTI_InitTypeDef?EXTI_InitStructure?=?{0};
????NVIC_InitTypeDef?NVIC_InitStructure?=?{0};

????RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO?|?RCC_APB2Periph_GPIOC,?ENABLE);
????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_1;
????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IPU;
????GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
????GPIO_Init(GPIOC,?&GPIO_InitStructure);

????/*?GPIOA.0?---->?EXTI_Line0?*/
????GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,?GPIO_PinSource1);
????EXTI_InitStructure.EXTI_Line?=?EXTI_Line1;
????EXTI_InitStructure.EXTI_Mode?=?EXTI_Mode_Interrupt;
????EXTI_InitStructure.EXTI_Trigger?=?EXTI_Trigger_Rising_Falling;
????EXTI_InitStructure.EXTI_LineCmd?=?ENABLE;
????EXTI_Init(&EXTI_InitStructure);

????NVIC_InitStructure.NVIC_IRQChannel?=?EXTI7_0_IRQn;
????NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority?=?0;
????NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?1;
????NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE;
????NVIC_Init(&NVIC_InitStructure);
}


/*********************************************************************
?*?@fn??????main
?*
?*?@brief???Main?program.
?*
?*?@return??none
?*/
int?main(void)
{
????NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
????SystemCoreClockUpdate();
????Delay_Init();
????Delay_Ms(1000);
????Delay_Ms(1000);
#if?(SDI_PRINT?==?SDI_PR_OPEN)
????SDI_Printf_Enable();
#else
????USART_Printf_Init(115200);
#endif
????printf("SystemClk:%d\r\n",?SystemCoreClock);
????printf(?"ChipID:%08x\r\n",?DBGMCU_GetCHIPID()?);

????printf("Sleep?Mode?Test\r\n");
????EXTI0_INT_INIT();

????printf("\r\n?**********?\r\n");
????__WFE();
????printf("\r\n?##########?\r\n");

????while(1)
????{
????????Delay_Ms(1000);
????????printf("Run?in?PWR_STANDBYEntry_WFI??main\r\n");
????????PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFE);
????}
}


void?EXTI7_0_IRQHandler(void)?__attribute__((interrupt("WCH-Interrupt-fast")));

/*********************************************************************
?*?@fn??????EXTI0_IRQHandler
?*
?*?@brief???This?function?handles?EXTI0?Handler.
?*
?*?@return??none
?*/
void?EXTI7_0_IRQHandler(void)
{
????if(EXTI_GetITStatus(EXTI_Line1)!=RESET)
????{
????????printf("EXTI7_0_IRQHandler?EXTI0?Wake_up\r\n");
????????EXTI_ClearITPendingBit(EXTI_Line0);?????/*?Clear?Flag?*/
//????????Delay_Ms(2000);
//????????PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFI);


//????????__WFE();

????}
}


{3861-x-151767689362759}.png

剛才在研究ch32v003fun里面的例子時(shí),找到了一個(gè)問題EXTI_Line0沒改EXTI_Line1,測(cè)試ok了,

EXTI_ClearITPendingBit(EXTI_Line0);

?功耗問題還是不理想,正常工作4ma,我用了測(cè)試了這四個(gè)寫法,電流最低在1ma左右,還能不能降?還有什么寫法推薦一下

int?main(void)
{
????NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
????SystemCoreClockUpdate();
????Delay_Init();
????Delay_Ms(1000);
????Delay_Ms(1000);
#if?(SDI_PRINT?==?SDI_PR_OPEN)
????SDI_Printf_Enable();
#else
????USART_Printf_Init(115200);
#endif
????printf("SystemClk:%d\r\n",?SystemCoreClock);
????printf(?"ChipID:%08x\r\n",?DBGMCU_GetCHIPID()?);

????printf("Sleep?Mode?Test\r\n");
????EXTI0_INT_INIT();

????printf("\r\n?**********?\r\n");
//????__WFI();
//????__WFE();
//????PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFI);
????PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFE);
????printf("\r\n?##########?\r\n");

????while(1)
????{
????????Delay_Ms(1000);
????????printf("Run?in?PWR_STANDBYEntry_WFI??main\r\n");

//????????__WFI();
//????????__WFE();
//????????PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFI);
????????PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFE);
????}
}



你好,功耗高可參考此篇博客:https://www.cnblogs.com/wchmcu/p/17091766.html?


只有PWR_EnterSTANDBYMode,

PWR_EnterSTOPMode已經(jīng)沒有了

{3861-x-325119210231189}.png


您好,CH32V003的低功耗模式只有睡眠模式和待機(jī)模式,沒有停止模式,具體可看CH32V003應(yīng)用手冊(cè),如下圖,手冊(cè)下載鏈接如下:

http://www.findthetime.net/downloads/CH32V003RM_PDF.html

image.png


我想問的是最低功耗是多少?
功耗問題還是不理想,正常工作4ma,2樓我測(cè)試了這四個(gè)寫法,電流最低在1ma左右,還能不能降?還有什么寫法推薦一下


您好,CH32V003運(yùn)行模式下電流最低也就在1mA左右,睡眠模式下電流最低在0.4mA左右,待機(jī)模式下電流最低在9uA左右。具體數(shù)據(jù)在CH32V003數(shù)據(jù)手冊(cè)有介紹,手冊(cè)下載鏈接如下。目前低功耗模式下軟件方面注意事項(xiàng)基本就是3樓帖子提到的,將不用的IO設(shè)置成下拉輸入模式,開啟PWR時(shí)鐘等。后續(xù)若有問題,可郵箱(lzs@wch.cn)溝通。

http://www.findthetime.net/downloads/CH32V003DS0_PDF.html

?


我今天按三樓的改,cc表測(cè)試還是900UA,就C1接了一個(gè)紅外中斷喚醒,intoLowPowerMode寫的有問題么?

/**********************************?(C)?COPYRIGHT?*******************************
?*?File?Name??????????:?main.c
?*?Author?????????????:?WCH
?*?Version????????????:?V1.0.0
?*?Date???????????????:?2023/12/25
?*?Description????????:?Main?program?body.
?*********************************************************************************
?*?Copyright?(c)?2021?Nanjing?Qinheng?Microelectronics?Co.,?Ltd.
?*?Attention:?This?software?(modified?or?not)?and?binary?are?used?for
?*?microcontroller?manufactured?by?Nanjing?Qinheng?Microelectronics.
?*******************************************************************************/

/*
?*@Note
?*low?power,?sleep?mode?routine:
?*EXTI_Line0(PD0)
?*This?routine?demonstrates?that?WFI?enters?the?sleep?mode,?and?the?PD0?pin?input
?*low?level?triggers?the?external?interrupt?EXTI_Line0?to?exit?the?sleep?mode,
?*Program?execution?continues?after?wake-up.
?*
?*/

#include?"debug.h"

/*?Global?define?*/

/*?Global?Variable?*/

/*********************************************************************
?*?@fn??????EXTI0_INT_INIT
?*
?*?@brief???Initializes?EXTI0?collection.
?*
?*?@return??none
?*/
void?EXTI0_INT_INIT(void)
{
????GPIO_InitTypeDef?GPIO_InitStructure?=?{0};
????EXTI_InitTypeDef?EXTI_InitStructure?=?{0};
????NVIC_InitTypeDef?NVIC_InitStructure?=?{0};

????RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO?|?RCC_APB2Periph_GPIOC,?ENABLE);
????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_1;
????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IPU;
????GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
????GPIO_Init(GPIOC,?&GPIO_InitStructure);

????/*?GPIOA.0?---->?EXTI_Line0?*/
????GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,?GPIO_PinSource1);
????EXTI_InitStructure.EXTI_Line?=?EXTI_Line1;
????EXTI_InitStructure.EXTI_Mode?=?EXTI_Mode_Interrupt;
????EXTI_InitStructure.EXTI_Trigger?=?EXTI_Trigger_Rising_Falling;
????EXTI_InitStructure.EXTI_LineCmd?=?ENABLE;
????EXTI_Init(&EXTI_InitStructure);

????NVIC_InitStructure.NVIC_IRQChannel?=?EXTI7_0_IRQn;
????NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority?=?0;
????NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?1;
????NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE;
????NVIC_Init(&NVIC_InitStructure);
}


void?intoLowPowerMode(void){

	//開啟PWR時(shí)鐘,目的是將內(nèi)部調(diào)壓器調(diào)成低功耗模式
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
	RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD,ENABLE);
	//所有IO口需要設(shè)置成下拉輸入,目的是將芯片IO固定電平狀態(tài),防止芯片IO懸空漏電
????GPIO_InitTypeDef?GPIO_InitStructure?=?{0};
	GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_All;
	GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IPU;
	GPIO_Init(GPIOA,?&GPIO_InitStructure);
	GPIO_Init(GPIOC,?&GPIO_InitStructure);
	GPIO_Init(GPIOD,?&GPIO_InitStructure);

//????????__WFI();
//????????__WFE();
????????PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFI);
//	PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFE);
}


/*********************************************************************
?*?@fn??????main
?*
?*?@brief???Main?program.
?*
?*?@return??none
?*/
int?main(void)
{
????NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
????SystemCoreClockUpdate();
????Delay_Init();
????Delay_Ms(1000);
????Delay_Ms(1000);
#if?(SDI_PRINT?==?SDI_PR_OPEN)
????SDI_Printf_Enable();
#else
????USART_Printf_Init(115200);
#endif
????printf("SystemClk:%d\r\n",?SystemCoreClock);
????printf(?"ChipID:%08x\r\n",?DBGMCU_GetCHIPID()?);

????printf("Sleep?Mode?Test\r\n");
????EXTI0_INT_INIT();

????printf("\r\n?**********?\r\n");
????intoLowPowerMode();
????printf("\r\n?##########?\r\n");

????while(1)
????{
????????Delay_Ms(1000);
????????printf("Run?in?PWR_STANDBYEntry_WFI??main\r\n");

????????intoLowPowerMode();
????????PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFE);
????}
}


void?EXTI7_0_IRQHandler(void)?__attribute__((interrupt("WCH-Interrupt-fast")));

/*********************************************************************
?*?@fn??????EXTI0_IRQHandler
?*
?*?@brief???This?function?handles?EXTI0?Handler.
?*
?*?@return??none
?*/
void?EXTI7_0_IRQHandler(void)
{
????if(EXTI_GetITStatus(EXTI_Line1)!=RESET)
????{
????????printf("EXTI7_0_IRQHandler?EXTI0?Wake_up\r\n");
????????EXTI_ClearITPendingBit(EXTI_Line1);?????/*?Clear?Flag?*/
//????????Delay_Ms(2000);
//????????PWR_EnterSTANDBYMode(PWR_STANDBYEntry_WFI);


//????????__WFE();

????}
}



面包板應(yīng)該沒問題吧
dfc2315a124868bba99f3a1c7e9340eb.jpg


您好,不用的IO建議設(shè)置成下拉輸入,下圖標(biāo)記處建議做一下修改。此外,在CH32V003 EVT中有待機(jī)模式的例程,你可以直接使用EVT例程測(cè)試一下,EVT下載鏈接如下:

http://www.findthetime.net/downloads/CH32V003EVT_ZIP.html?

image.png


突然發(fā)現(xiàn)電壓我用的5V 我用18650電池試了一下,現(xiàn)在電流520uA了,還有降的空間



面包板沒動(dòng),EVT中待機(jī)模式的例程 4V測(cè)試 300uA

?我自己用8樓的代碼測(cè)試? GPIO_Mode_IPD,GPIO_Mode_IPU感覺差別不大,都是500uA/490uA左右



用18650電池 cc表顯示的是4V


有圖有真相

2f66a8ff0ebd5e8d88598b87a8be7bb1.jpg


您好,如下圖,我這邊測(cè)試大概在13uA左右,注意系統(tǒng)主頻配置使用內(nèi)部晶振,EVT例程帶有喚醒的,要把喚醒那部分注釋掉。若有萬用表,可以用萬用表測(cè)試一下看看image.png


收到了。剛才測(cè)試把紅外電源線拔了就9uA了


只有登錄才能回復(fù),可以選擇微信賬號(hào)登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频