freeelectron 发表于 2022-3-16 13:39

【BLE 5.3无线MCU CH582】6、pwm呼吸灯

<p>系列文章:</p>

<p><a href="https://bbs.eeworld.com.cn/thread-1195192-1-1.html" target="_blank">【BLE 5.3无线MCU CH582】1、初识CH582开发板(开箱)</a></p>

<p><a href="https://bbs.eeworld.com.cn/thread-1195464-1-1.html" target="_blank">【BLE 5.3无线MCU CH582】2、MounRiver IDE初体验</a></p>

<p><a href="https://bbs.eeworld.com.cn/thread-1196099-1-1.html#pid3126477" target="_blank">【BLE 5.3无线MCU CH582】3、非阻塞方式点灯</a></p>

<p><a href="https://bbs.eeworld.com.cn/thread-1196188-1-1.html" target="_blank">【BLE 5.3无线MCU CH582】4、串口不定长数据接收</a></p>

<p><a href="https://bbs.eeworld.com.cn/thread-1196777-1-1.html" target="_blank">【BLE 5.3无线MCU CH582】5、硬件I2C驱动0.96吋OLED</a></p>

<p>&nbsp;</p>

<p><span style="font-size:20px;">1、关于CH582的PWM</span></p>

<p><span style="font-size:16px;">CH582除了定时器可以产生pwm之外,还提供了专门的pwm外设,独立于定时器。</span></p>

<p></p>

<p><span style="font-size:24px;">2、PWM通道</span></p>

<p><span style="font-size:16px;">引脚信息上标有PWMX的即就是pwm通道,从<span style="font-family:黑体"><span style="color:#000000">PWM4到PWM11,PWM0到PWM3是定时器的pwm通道。</span></span></span></p>

<p> &nbsp;</p>

<p><span style="font-size:24px;">3、代码实现</span></p>

<pre>
<code class="language-cpp">void PwmInit(void)
{
    GPIOA_ModeCfg( GPIO_Pin_12, GPIO_ModeOut_PP_5mA );    // PA12 - PWM4
    GPIOA_ModeCfg( GPIO_Pin_13, GPIO_ModeOut_PP_5mA );    // PA13 - PWM5

    PWMX_CLKCfg( 2 );                  // cycle = Fsys/2
    PWMX_CycleCfg( PWMX_Cycle_31 );      // 周期 = cycle/31
    PWMX_ACTOUT( CH_PWM4, (UINT8)((31/100.0 )* 10), High_Level, ENABLE );
    PWMX_ACTOUT( CH_PWM5, (UINT8)((31/100.0 )* 10), High_Level, ENABLE );
}


void PwmOut(void)
{
    static uint32_t tick=0;

    staticuint8_t out=0;

    if(SystemGetTick()-tick&gt;100)
    {
      tick=SystemGetTick();

      out=out+5;

      if(out&gt;100)
      {
            out=0;
      }
      PWMX_ACTOUT( CH_PWM4, (UINT8)((31/100.0 )* out), High_Level, ENABLE );
      PWMX_ACTOUT( CH_PWM5, (UINT8)((31/100.0 )* out), High_Level, ENABLE );
    }
}
</code></pre>

<p><span style="font-size:24px;">4、现象</span></p>

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

<p>&nbsp;</p>

<p>&nbsp;</p>

TTTTT大王 发表于 2023-3-18 15:28

<p>搞测试的表示一头雾水</p>
页: [1]
查看完整版本: 【BLE 5.3无线MCU CH582】6、pwm呼吸灯