xiaolinen 发表于 2024-7-6 22:05

全能小网关|CH32V208--第四篇:低功耗测试

<div class='showpostmsg'> 本帖最后由 xiaolinen 于 2024-7-6 22:03 编辑

<p><strong><span style="font-size:22px;">一:电路图修改</span></strong></p>

<p><span style="font-size:20px;">&nbsp; &nbsp; &nbsp; &nbsp; 将下图中的D1(LED灯)和R1电阻拆除,减少电流的耗损。</span></p>

<div style="text-align: center;"></div>

<div style="text-align: center;">&nbsp;</div>

<div><strong><span style="font-size:22px;">二:低功耗模式</span></strong></div>

<div><strong><span style="font-size:22px;">&nbsp; &nbsp; &nbsp; &nbsp; </span></strong><span style="font-size:22px;">2.1,CH32V208的低功耗模式包括:睡眠模式,停止模式,待机模式,具体如下图所示:</span></div>

<div>
<div style="text-align: center;"></div>

<p>&nbsp;</p>
</div>

<div><span style="font-size:20px;"><strong>&nbsp; &nbsp; &nbsp; &nbsp; </strong>2.1,active模式</span></div>

<div><span style="font-size:20px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CH32V208在正常运行工作状态的电流情况,如下图所示:</span></div>

<div>
<div style="text-align: center;"></div>

<div style="text-align: center;">&nbsp;</div>

<p><span style="font-size:20px;">&nbsp; &nbsp; &nbsp; &nbsp; 2.3,sleep模式</span></p>

<p><span style="font-size:20px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.3.1,PA0引脚输入低电平触发外部中断EXTI_Line0退出sleep睡眠模式,程序在唤醒后继续执行。</span></p>

<p><span style="font-size:20px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.3.2,重点代码,如下图所示:</span></p>

<pre>
<code class="language-cpp">/*********************************************************************
* @fn      EXTI0_INT_INIT
*
* <a href="home.php?mod=space&amp;uid=159083" target="_blank">@brief </a>   EXTI0中断配置,使PA0发生中断,唤醒sleep休眠
*
* <a href="home.php?mod=space&amp;uid=784970" target="_blank">@return </a>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_GPIOA, ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &amp;GPIO_InitStructure);

    /* GPIOA.0 ----&gt; EXTI_Line0 */
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
    EXTI_InitStructure.EXTI_Line = EXTI_Line0;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//下降沿
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&amp;EXTI_InitStructure);

    NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&amp;NVIC_InitStructure);
}

/*********************************************************************
* @fn      sleep_mode_enable
*
* @brief   使能sleep休眠模式
*
* @returnnone
*/
void sleep_mode_enable(void)
{
    __WFI();
}
</code></pre>

<p><span style="font-size:20px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.3.3,sleep模式下电流情况,如下图所示:</span></p>

<div style="text-align: center;"></div>

<div style="text-align: center;">&nbsp;</div>

<p><span style="font-size:20px;">&nbsp; &nbsp; &nbsp; &nbsp; 2.4,stop模式</span></p>

<p><span style="font-size:20px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.4.1,PA0引脚输入低电平触发外部中断EXTI_Line0退出stop睡眠模式,程序在唤醒后继续执行。</span></p>

<p><span style="font-size:20px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.4.2,重点代码,如下图所示:</span></p>

<pre>
<code class="language-cpp">/*********************************************************************
* @fn      EXTI0_INT_INIT
*
* @briefEXTI0中断配置,使PA0发生中断,唤醒sleep休眠
*
* @returnnone
*/
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_GPIOA, ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &amp;GPIO_InitStructure);

    /* GPIOA.0 ----&gt; EXTI_Line0 */
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
    EXTI_InitStructure.EXTI_Line = EXTI_Line0;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&amp;EXTI_InitStructure);

    NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&amp;NVIC_InitStructure);
}

/*********************************************************************
* @fn      stop_mode_enable
*
* @brief使能stop休眠模式
*
* @returnnone
*/
void stop_mode_enable(void)
{
    PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
}</code></pre>

<p><span style="font-size:20px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.4.3,stop模式下电流情况,如下图所示:</span></p>

<div style="text-align: center;"></div>

<div style="text-align: center;">&nbsp;</div>

<p><span style="font-size:20px;">&nbsp; &nbsp; &nbsp; &nbsp; 2.5,standby模式</span></p>

<p><span style="font-size:20px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2.5.1,WKUP (PA0)引脚的上升沿退出待机模式,唤醒后程序复位。</span></p>

<p><span style="font-size:20px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.5.2,重点代码,如下图所示:</span></p>

<pre>
<code class="language-cpp">/*********************************************************************
* @fn      gpio_init
*
* @brief   GPIO初始化
*
* @returnnone
*/
void gpio_init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure = {0};

      /* To reduce power consumption, unused GPIOs need to be set as pull-down inputs */
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|
                RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE, ENABLE);
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

      GPIO_Init(GPIOA, &amp;GPIO_InitStructure);
      GPIO_Init(GPIOB, &amp;GPIO_InitStructure);
      GPIO_Init(GPIOC, &amp;GPIO_InitStructure);
      GPIO_Init(GPIOD, &amp;GPIO_InitStructure);
      GPIO_Init(GPIOE, &amp;GPIO_InitStructure);
}


/*********************************************************************
* @fn      PWR_WakeUpPinCmd
*
* @brief   Enables or disables the WakeUp Pin functionality.
*
* @param   NewState - new state of the WakeUp Pin functionality
*      (ENABLE or DISABLE).
*
* @returnnone
*/
void PWR_WakeUpPinCmd(FunctionalState NewState)
{
    if(NewState)
    {
      PWR-&gt;CSR |= (1 &lt;&lt; 8);
    }
    else
    {
      PWR-&gt;CSR &amp;= ~(1 &lt;&lt; 8);
    }
}

/*********************************************************************
* @fn      PWR_EnterSTANDBYMode
*
* @brief   Enters STANDBY mode.
*
* @returnnone
*/
void PWR_EnterSTANDBYMode(void)
{
    PWR-&gt;CTLR |= PWR_CTLR_CWUF;
    PWR-&gt;CTLR |= PWR_CTLR_PDDS;
    NVIC-&gt;SCTLR |= (1 &lt;&lt; 2);

    __WFI();
}</code></pre>

<p><span style="font-size:20px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.5.3,standby</span><span style="font-size:20px;">模式下电流情况,如下图所示:</span></p>

<div style="text-align: center;"></div>

<p>&nbsp;</p>
</div>

<p><strong><span style="font-size:22px;">三:声明</span></strong></p>

<p><span style="font-size:20px;">&nbsp; &nbsp; &nbsp; &nbsp; 本次记录的实验,主要是为了熟悉芯片各种低功耗模式的进入和退出方法,所记录的电流情况,并不是各个低功耗模式下的最低情况。</span></p>
</div><script>                                        var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;"   style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
                                       
                                        if(parseInt(discuz_uid)==0){
                                                                                                (function($){
                                                        var postHeight = getTextHeight(400);
                                                        $(".showpostmsg").html($(".showpostmsg").html());
                                                        $(".showpostmsg").after(loginstr);
                                                        $(".showpostmsg").css({height:postHeight,overflow:"hidden"});
                                                })(jQuery);
                                        }                </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>

Jacktang 发表于 2024-7-7 09:24

<p>主要是为了熟悉芯片各种低功耗模式的进入和退出方法,所记录的电流情况,并不是各个低功耗模式下的最低情况。</p>

<p>明白,就是为了熟悉</p>

xiaolinen 发表于 2024-7-7 14:13

Jacktang 发表于 2024-7-7 09:24
主要是为了熟悉芯片各种低功耗模式的进入和退出方法,所记录的电流情况,并不是各个低功耗模式下的最低情况 ...

<p>不要这么理解,不要这么理解,只是为后续进一步使用做一下铺垫<img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/lol.gif" width="48" /></p>
页: [1]
查看完整版本: 全能小网关|CH32V208--第四篇:低功耗测试