常见泽1 发表于 2019-12-21 17:07

第五篇 GD32VF103C START PWM

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">先来看下</span>RISC-V GD<span style="font-family:宋体">的</span>103<span style="font-family:宋体">的定时器的总览</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">这次主要参考官方例程,使用</span>PWM<span style="font-family:宋体">模式</span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">在</span> PWM <span style="font-family:宋体">输出模式下(</span>PWM <span style="font-family:宋体">模式</span> 0 <span style="font-family:宋体">是配置</span> CHxCOMCTL <span style="font-family:宋体">为</span> 3<span style="font-family:宋体">&rsquo;</span>b110<span style="font-family:宋体">,</span> PWM <span style="font-family:宋体">模式</span> 1 <span style="font-family:宋体">是配置</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif">CHxCOMCTL <span style="font-family:宋体">为</span> 3<span style="font-family:宋体">&rsquo;</span>b111<span style="font-family:宋体">),通道根据</span> TIMERx_CAR <span style="font-family:宋体">寄存器和</span> TIMERx_CHxCV <span style="font-family:宋体">寄存器的值,</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">输出</span> PWM <span style="font-family:宋体">波形。</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">根据计数模式,可以分为两种</span> PWM <span style="font-family:宋体">波:</span>EAPWM(<span style="font-family:宋体">边沿对齐</span> PWM)<span style="font-family:宋体">和</span> CAPWM(<span style="font-family:宋体">中央对齐</span> PWM) </span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">参考</span>M3<span style="font-family:宋体">的</span>PMW<span style="font-family:宋体">描述,两者是差不多的</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">这里我们选用</span>PWM<span style="font-family:宋体">模式</span>0.</span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">下面代码开始配置</span>PWM<span style="font-family:宋体">的时钟、</span>GPIO<span style="font-family:宋体">、模式及参数</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">这里分频系数</span>119 <span style="font-family:宋体">周期</span>500 <span style="font-family:宋体">主频是</span>108M <span style="font-family:宋体">算下来要你管管是</span>1.8khz<span style="font-family:宋体">左右,占空比</span>50%</span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">其实和</span>M3<span style="font-family:宋体">真的很像</span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">看下</span></span></span></p>

<p style="text-align:justify"></p>

<p style="text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">基本一样,主要就是在通道参数配置那里略有不同,貌似多了两个函数</span></span></span></p>

<p style="text-align:justify">&nbsp;</p>

<p align="left" style="text-align:left"><span style="font-size:10.5pt"><span style="text-autospace:none"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-size:10.0pt"><span style="font-family:Consolas"><span style="color:black">&nbsp; timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_0, 250);</span></span></span></span></span></span></p>

<p style="text-indent:19.5pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span lang="EN-US" style="font-size:10.0pt"><span style="font-family:Consolas"><span style="color:black">timer_channel_output_mode_config(TIMER0, TIMER_CH_0, TIMER_OC_MODE_PWM0);</span></span></span></span></span></p>

<p style="text-indent:19.5pt; text-align:justify">&nbsp;</p>

<p style="text-indent:19.5pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-size:10.0pt"><span style="font-family:宋体"><span style="color:black">而</span></span></span><span lang="EN-US" style="font-size:10.0pt"><span style="font-family:Consolas"><span style="color:black">M3</span></span></span><span style="font-size:10.0pt"><span style="font-family:宋体"><span style="color:black">是由结构体完成初始化</span></span></span></span></span></p>

<p style="text-indent:19.5pt; text-align:justify"></p>

<p style="text-indent:19.5pt; text-align:justify">&nbsp;</p>

<p style="text-indent:19.5pt; text-align:justify"></p>

<p style="text-indent:19.5pt; text-align:justify"></p>

<p style="text-indent:19.5pt; text-align:justify">&nbsp;</p>

<p style="text-indent:19.5pt; text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"><span style="font-family:宋体">我们看下试验现象</span></span></span></p>

<p style="text-indent:19.5pt; text-align:justify">&nbsp;</p>

<p style="text-indent:19.5pt; text-align:justify"></p>

zeshoufx 发表于 2020-1-19 15:01

谢谢分享,,,,,学习一下,,,,
页: [1]
查看完整版本: 第五篇 GD32VF103C START PWM