oxygen_sh 发表于 2022-2-13 23:12

【国民技术M4内核热销款N32G45XVL评估】第四篇 三相BLDC电机”六步”控制波形生成

<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">本实验是使用</font><font face="Calibri">TIM1</font><font face="宋体">产生三相</font><font face="Calibri">BLDC</font><font face="宋体">电机控制控制波形,也就是所谓的六步换向控制波形。</font></span></span></span></span></span></p>

<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">N32G45</font></span></span><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">的</font><font face="Calibri">TIM1</font><font face="宋体">输出信号及影像关系如下表。在</font></span></span><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">N32G45XVL</font></span></span><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">-STB</font><font face="宋体">板上选择最后一组端口映射来输出</font><font face="Calibri">PWM</font><font face="宋体">信号。</font></span></span></span></span></span></p>

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

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

<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">下面是实验代码:</font></span></span></span></span></span></p>

<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">端口配置</font></span></span></span></span></span></p>

<pre>
<code>void GPIO_Conf(void)
{
        GPIO_InitType GPIO_InitStructure;       
       
        RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | RCC_APB2_PERIPH_GPIOE, ENABLE);

        AFIO-&gt;RMP_CFG |= 0xC0;
       
        GPIO_InitStructure.Pin      = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 ;
    GPIO_InitStructure.GPIO_Mode= GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitPeripheral(GPIOE, &amp;GPIO_InitStructure);
       
        /* GPIOE Configuration: BKIN pin */
    GPIO_InitStructure.Pin       = GPIO_PIN_15;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitPeripheral(GPIOE, &amp;GPIO_InitStructure);
}</code></pre>

<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">TIM1 </font><font face="宋体">配置</font></span></span></span></span></span></p>

<pre>
<code>    /* Time Base configuration */
    TIM_TimeBaseStructure.Prescaler = 0;
    TIM_TimeBaseStructure.CntMode   = TIM_CNT_MODE_UP;
    TIM_TimeBaseStructure.Period    = 4095;
    TIM_TimeBaseStructure.ClkDiv    = 0;
    TIM_TimeBaseStructure.RepetCnt= 0;

    TIM_InitTimeBase(TIM1, &amp;TIM_TimeBaseStructure);

    /* Channel 1, 2,3 and 4 Configuration in PWM mode */
    TIM_OCInitStructure.OcMode       = TIM_OCMODE_TIMING;
    TIM_OCInitStructure.OutputState= TIM_OUTPUT_STATE_ENABLE;
    TIM_OCInitStructure.OutputNState = TIM_OUTPUT_NSTATE_ENABLE;
    TIM_OCInitStructure.Pulse      = 2047;
    TIM_OCInitStructure.OcPolarity   = TIM_OC_POLARITY_HIGH;
    TIM_OCInitStructure.OcNPolarity= TIM_OCN_POLARITY_HIGH;
    TIM_OCInitStructure.OcIdleState= TIM_OC_IDLE_STATE_SET;
    TIM_OCInitStructure.OcNIdleState = TIM_OCN_IDLE_STATE_SET;

    TIM_InitOc1(TIM1, &amp;TIM_OCInitStructure);

    TIM_OCInitStructure.Pulse = 1023;
    TIM_InitOc2(TIM1, &amp;TIM_OCInitStructure);

    TIM_OCInitStructure.Pulse = 511;
    TIM_InitOc3(TIM1, &amp;TIM_OCInitStructure);

    /* Automatic Output enable, Break, dead time and lock configuration*/
    TIM_BDTRInitStructure.OssrState       = TIM_OSSR_STATE_ENABLE;
    TIM_BDTRInitStructure.OssiState       = TIM_OSSI_STATE_ENABLE;
    TIM_BDTRInitStructure.LockLevel       = TIM_LOCK_LEVEL_OFF;
    TIM_BDTRInitStructure.DeadTime      = 1;
    TIM_BDTRInitStructure.Break         = TIM_BREAK_IN_DISABLE; // TIM_BREAK_IN_ENABLE;
    TIM_BDTRInitStructure.BreakPolarity   = TIM_BREAK_POLARITY_HIGH;
    TIM_BDTRInitStructure.AutomaticOutput = TIM_AUTO_OUTPUT_ENABLE;

    TIM_ConfigBkdt(TIM1, &amp;TIM_BDTRInitStructure);

    TIM_EnableCapCmpPreloadControl(TIM1, ENABLE);

    TIM_ConfigInt(TIM1, TIM_INT_COM, ENABLE);

    /* TIM1 counter enable */
    TIM_Enable(TIM1, ENABLE);

    /* Main Output Enable */
TIM_EnableCtrlPwmOutputs(TIM1, ENABLE);</code></pre>

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

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">运行后结果:</font></span></span></span></span></span></p>

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">CH1/2/3</font><font face="宋体">波形</font></span></span></span></span></span></p>

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

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">CH1/2N/3N</font><font face="宋体">波形</font></span></span></span></span></span></p>

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

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

<p align="justify" style="text-indent:21.0000pt; text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">波形满足要求,可以作为六步换向控制信号。</font></span></span></span></span></span></p>

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

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

<p>&nbsp;</p>

littleshrimp 发表于 2022-2-14 09:48

<p>代码有种和STM32兼容的感觉</p>

freebsder 发表于 2022-2-14 19:58

<p>这个波形看起来生成的还不错</p>

fxyc87 发表于 2022-2-22 10:45

赞,楼主只是单独生成波形?有电机实操么?学习中
页: [1]
查看完整版本: 【国民技术M4内核热销款N32G45XVL评估】第四篇 三相BLDC电机”六步”控制波形生成