jixulifu2 发表于 2024-8-10 15:20

【中科昊芯HXS320F28025C】PWM实现;死区设置。

<div class='showpostmsg'><p><span style="font-size:22px;">EPWM模块</span></p>

<p><span style="font-size:22px;">&nbsp; &nbsp; PWM是一种脉宽调制技术,广泛应用于电机控制、LED亮度调节、音频放大等领域。PWM的基本原理是通过改变脉冲信号的宽度来调节输出功率,从而实现对负载的有效控制。大部分MCU都内置了PWM功能(如STM32,ARDUINO等),可以直接通过专用的定时器或外围设备来生成PWM信号。这些MCU的PWM功能通常只能提供较为一般的功能。中科昊芯HXS320F28025C内置了增强型脉宽调制器(ePWM),相比市面常见的MCU,功能更加强,配置更灵活,安全保护更完善。更适合越来越复杂的电力电子与电机控制。</span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;中科昊芯HXS320F28025C的增强型脉宽调制器(ePWM)有以下几个子模块:</span></p>

<p><span style="font-size:20px;">&nbsp;&nbsp; &nbsp;&bull;时基子模块 Time-Base</span></p>

<p><span style="font-size:20px;">&nbsp;&nbsp;&nbsp; &bull;计数器比较子模块Counter Compare </span></p>

<p><span style="font-size:20px;">&nbsp; &nbsp;&nbsp;&bull;动作限定子模块Action Qualifier </span></p>

<p><span style="font-size:20px;">&nbsp; &nbsp;&nbsp;&bull;死区发生器子模块Dead-Band Generator</span></p>

<p><span style="font-size:20px;">&nbsp; &nbsp; &bull;PWM斩波器(PC)子模块 PWM Chopper </span></p>

<p><span style="font-size:20px;">&nbsp; &nbsp;&nbsp;&bull;错误联防子模块Trip Zone</span></p>

<p><span style="font-size:20px;">&nbsp;&nbsp; &nbsp;&bull;事件触发子模块Event Trigger </span></p>

<p><span style="font-size:20px;">&nbsp; &nbsp;&nbsp;&bull;数字比较子模块Digital Compare</span></p>

<p>&nbsp;</p>

<p><span style="font-size:22px;">&nbsp; &nbsp; 每个ePWM模块都支持以下功能: </span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&bull;带周期和频率控制的专用16位时基计数器 </span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&bull;两个PWM输出(EPWMxA和EPWMxB),可配置为: </span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ndash;两个独立的PWM输出,单边操作 </span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ndash;两个独立的PWM输出,双边对称模式 </span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&ndash;一个独立的PWM输出,双边不对称模式 </span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&bull;通过软件对PWM信号进行异步超驰控制。</span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&bull;对于其他ePWM模块的可编程的相位控制(滞后或超前)。 </span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&bull;逐周期地进行硬件锁定(同步)的相位关系。</span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&bull;具有独立的上升沿和下降沿延迟控制的死区功能。</span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&bull;在错误联防情况下,可编程的逐周期错误联防和单次错误联防。</span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&bull;错误联防条件下,可强制PWM输出高、低或高阻状态逻辑电平。</span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&bull;所有事件均可触发CPU中断和ADC转换开始(SOC)</span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&bull;可编程的事件预分频可最大程度地减少中断时的CPU开销。</span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;&bull;通过高频载波信号进行PWM斩波,用于脉冲变压器栅极驱动</span></p>

<p><span style="font-size:22px;">&nbsp; &nbsp; 内部框图如下:</span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;</span></p>

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

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

<div>&nbsp;</div>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;更多关于中科昊芯HXS320F28025C的EPWM的信息,可以自行查阅datasheet。</span></p>

<p><span style="font-size:22px;">&nbsp;&nbsp;&nbsp;&nbsp;PWM信号由一系列周期性的脉冲组成,每个脉冲都有固定的周期T,脉冲的宽度(即高电平持续的时间)可以根据需要进行调节。脉冲的宽度与周期的比例称为占空比(Duty Cycle),占空比决定了输出信号的平均电压值。例如,如果脉冲宽度为周期的一半,则占空比为50%,输出信号的平均电压为电源电压的一半。我们配置输出一个1khz,占空比50%的PWM信号。</span></p>

<p><span style="font-size:22px;">F28025C主频160Mhz,预分频16,高速分频10,160Mhz/16/10 = 1Mhz.</span></p>

<p><span style="font-size:22px;">设置时基周期,500, 1M/(500*2)=1KHz = 1ms一个周期</span></p>

<p><span style="font-size: 22px;">占空比设置为50%</span></p>

<p><span style="font-size: 22px;">EPWM1设置在IO0.0和0.1上输出互补信号</span></p>

<pre>
<code class="language-cpp">/*设置时钟分频 时钟分频/16,高速时钟分频/10,160M/16/10=1M*/
    EPWM_setClockPrescaler(myEPWM1_BASE, EPWM_CLOCK_DIVIDER_16, EPWM_HSCLOCK_DIVIDER_10);
    /*设置时基周期,500, 1M/(500*2)=1KHz*/
    EPWM_setTimeBasePeriod(myEPWM1_BASE, 500);
    EPWM_setTimeBaseCounter(myEPWM1_BASE, 0);
    /*设置时基计数模式,上下计数*/
    EPWM_setTimeBaseCounterMode(myEPWM1_BASE, EPWM_COUNTER_MODE_UP_DOWN);
    EPWM_disablePhaseShiftLoad(myEPWM1_BASE);
    EPWM_setPhaseShift(myEPWM1_BASE, 0);
    /*设置计数器比较值,COMPARE_A,500*/
    EPWM_setCounterCompareValue(myEPWM1_BASE, EPWM_COUNTER_COMPARE_A, 250);
    EPWM_setCounterCompareShadowLoadMode(myEPWM1_BASE, EPWM_COUNTER_COMPARE_A, EPWM_COMP_LOAD_ON_CNTR_ZERO);
    /*设置计数器比较值,COMPARE_B,1500*/
    EPWM_setCounterCompareValue(myEPWM1_BASE, EPWM_COUNTER_COMPARE_B, 250);
    EPWM_setCounterCompareShadowLoadMode(myEPWM1_BASE, EPWM_COUNTER_COMPARE_B, EPWM_COMP_LOAD_ON_CNTR_ZERO);
    /*ePWM1A,输出引脚置低,时基计数器等于0*/
    EPWM_setActionQualifierAction(myEPWM1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
    EPWM_setActionQualifierAction(myEPWM1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
    /*ePWM1A,输出引脚置高,时基计数器上升时等于CMPA*/
    EPWM_setActionQualifierAction(myEPWM1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
    /*ePWM1A,输出引脚置低,时基计数器下降时等于CMPA*/
    EPWM_setActionQualifierAction(myEPWM1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
    EPWM_setActionQualifierAction(myEPWM1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);
    EPWM_setActionQualifierAction(myEPWM1_BASE, EPWM_AQ_OUTPUT_A, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPB);
    /*ePWM1B,输出引脚置低,时基计数器等于0*/
    EPWM_setActionQualifierAction(myEPWM1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_ZERO);
    EPWM_setActionQualifierAction(myEPWM1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_PERIOD);
    EPWM_setActionQualifierAction(myEPWM1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPA);
    EPWM_setActionQualifierAction(myEPWM1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_NO_CHANGE, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPA);
    /*ePWM1B,输出引脚置高,时基计数器上升时等于CMPA*/
    EPWM_setActionQualifierAction(myEPWM1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_HIGH, EPWM_AQ_OUTPUT_ON_TIMEBASE_UP_CMPB);
    /*ePWM1B,输出引脚置低,时基计数器下降时等于CMPA*/
    EPWM_setActionQualifierAction(myEPWM1_BASE, EPWM_AQ_OUTPUT_B, EPWM_AQ_OUTPUT_LOW, EPWM_AQ_OUTPUT_ON_TIMEBASE_DOWN_CMPB);</code></pre>

<p>更改GPIO功能与开启时钟代码:</p>

<pre>
<code class="language-cpp">GPIO_setPinConfig(GPIO_0_EPWM1_A);
GPIO_setPinConfig(GPIO_1_EPWM1_B);
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);

</code></pre>

<p>同时开启一个板载LED灯闪烁,可以观察程序是否在运行。</p>

<pre>
<code> GPIO_setPinConfig(GPIO_31_GPIO31);
GPIO_setDirectionMode(31, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(31, GPIO_PIN_TYPE_PULLUP);
GPIO_setQualificationMode(31, GPIO_QUAL_SYNC);
GPIO_writePin(31,1);
for(;;)
{
   GPIO_togglePin(31);
   for(number = 0; number &lt; 500; number ++)
   DEVICE_DELAY_US(1000);
}
</code></pre>

<div><span style="font-size:20px;">程序写好后点击DOWNLOAD,可以看到开发板板载红灯闪烁,证明程序已经正常运行,接上示波器查看IO00和IO01波形。</span></div>

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

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

<p style="text-align: left;"><span style="font-size:20px;">可以看到正常输出1khz的占空比50%的波形。</span></p>

<p style="text-align: left;"><span style="font-size:22px;">死区的概念:<br />
简单解释:通常,大功率电机、变频器,末端都是由大功率管、IGBT等原件组成的<br />
H桥或3湘桥,每个桥的上半桥和下半桥是绝对不能相同的,但高速的PWM驱动信号在达到功率元件的控制基时,往往会由于各种各样的原因产生延迟的效果,造成某个半桥原件在应该关断时没有关断,造成功率元件烧毁<br />
死区就是在上半桥关断后,延迟一段时间在打开下半桥或在下半桥关断后,延迟一段时间再打开上半桥,从而避免功率元件烧毁,这段延迟时间就是死区</span></p>

<p style="text-align: left;"><span style="font-size:22px;">中科昊芯HXS320F28025C自带死区产生模块</span></p>

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

<div style="text-align: left;">
<pre>
<code class="language-cpp">       /*设置死区延时极性,死区下降沿,极性反向*/
    EPWM_setDeadBandDelayPolarity(myEPWM1_BASE, EPWM_DB_FED, EPWM_DB_POLARITY_ACTIVE_LOW);
       /*设置死区延时模式,死区上升沿延时,开启*/
    EPWM_setDeadBandDelayMode(myEPWM1_BASE, EPWM_DB_RED, true);
       /*设置死区上升沿延时数,*/
    EPWM_setRisingEdgeDelayCount(myEPWM1_BASE, 100);
       /*设置死区延时模式,死区下降沿延时,开启*/
    EPWM_setDeadBandDelayMode(myEPWM1_BASE, EPWM_DB_FED, true);
       /*设置死区下降沿延时数,*/
    EPWM_setFallingEdgeDelayCount(myEPWM1_BASE, 100);
</code></pre>

<p><span style="font-size:22px;">再次查看波形</span></p>
</div>

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

<div style="text-align: left;"><span style="font-size:22px;">图中红线框内的时间差即为死区时间,可以有效防止MOS管频繁开关导致的损坏。</span></div>
</div>
</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>
页: [1]
查看完整版本: 【中科昊芯HXS320F28025C】PWM实现;死区设置。