STM32 使用IQmath实现SVPWM

IQMATH

TI的片子很香,做的也很好,但是成本相对ST会更高,电机控制方面,TI无疑是做的最好的方案之一,另外TI针对没有浮点运算器的定点DSP推出了IQMATH库,在使用Q格式对数据进行分析和处理的过程中,十分方便,代码也变得更加简洁,本文将使用TI的方案实现SVPWM,在这里感谢TI

测试平台参数:
硬件:stm32f103
软件:标准外设库3.5
IDE:MDK-ARM
STM32 使用IQmath实现SVPWM_第1张图片

添加IQmathLib到工程中

IQmathlib解压可以得到如下文件,其中包含各个平台下的静态库,本文使用STM32F1keil环境下进行开发,需要使用的是rvmdk-cm3
STM32 使用IQmath实现SVPWM_第2张图片
打开一个keil工程,在菜单界面点击如下图所示的图标进入project items
在这里插入图片描述
添加IQmath组,并添加rvmdk-cm3路径下的静态库,和头文件;
STM32 使用IQmath实现SVPWM_第3张图片
点击下图所示的图标进入工程熟悉的设置;
在这里插入图片描述
添加rvmdk-cm3静态库的路径,和头文件的包含路径,如下图所示;

STM32 使用IQmath实现SVPWM_第4张图片
STM32 使用IQmath实现SVPWM_第5张图片
最终,build整个工程即可。

测试部分程序

/**
  ******************************************************************************
  * @file    Project/STM32F10x_StdPeriph_Template/main.c 
  * @author  MCD Application Team
  * @version V3.5.0
  * @date    08-April-2011
  * @brief   Main program body
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * 

© COPYRIGHT 2011 STMicroelectronics

****************************************************************************** */
/* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h" #include #include #include "serial_scope.h" #include "common.h" #include "IQmathLib.h" #include "usart_driver.h" #include "clarke.h" #include "park.h" #include "svpwm.h" /** * @brief Main program. * @param None * @retval None */ sv_mod_t svpwm = SVGEN_DEFAULTS; #define CLARK 0 #define PARK 1 #define SVPWM 2 #define SVPWM_REG 3 int main(void) { int user_data[4] = { 0 }; static int16_t time_cnt = 0; Trig_Components a; Trig_Components b; _iq final_angle; usart_init(); while (1) { time_cnt-=32; clarke_parameter.As = _IQsinPU(time_cnt); clarke_parameter.Bs = _IQsinPU(time_cnt-0x5555); if(clarke_parameter.As > 32767){ clarke_parameter.As = 32767; } if(clarke_parameter.As < -32768){ clarke_parameter.As = -32768; } if(clarke_parameter.Bs > 32767){ clarke_parameter.Bs = 32767; } if(clarke_parameter.Bs < -32768){ clarke_parameter.Bs = -32768; } clarke_calc(&clarke_parameter); park_parameter.Alpha = clarke_parameter.Alpha; park_parameter.Beta = clarke_parameter.Beta; park_parameter.Sin = trig_functions(time_cnt).hsin; park_parameter.Cos = trig_functions(time_cnt).hcos; park_parameter.Angle = -time_cnt; park_calc(&park_parameter); svpwm.Ualpha = clarke_parameter.Alpha; svpwm.Ubeta = clarke_parameter.Beta; svpwm_calc(&svpwm); #define FOC_DEBUG SVPWM_REG #if (FOC_DEBUG == CLEAK) user_data[0] = clarke_parameter.As; user_data[1] = clarke_parameter.Bs; user_data[2] = clarke_parameter.Alpha; user_data[3] = clarke_parameter.Beta; #elif (FOC_DEBUG == PARK) user_data[0] = clarke_parameter.As; user_data[1] = clarke_parameter.Bs; user_data[2] = park_parameter.Ds; user_data[3] = park_parameter.Qs; #elif (FOC_DEBUG == SVPWM) user_data[0] = (uint16_t)svpwm.Ta; user_data[1] = (uint16_t)svpwm.Tb; user_data[2] = (uint16_t)svpwm.Tc; user_data[3] = svpwm.VecSector*5000; #elif (FOC_DEBUG == SVPWM_REG) //换算的CCRx寄存器的值 sv_regs_mod_t sv_regs = svpwm_get_regs_mod(7200,&svpwm); user_data[0] = sv_regs.ccr1; user_data[1] = sv_regs.ccr2; user_data[2] = sv_regs.ccr3; user_data[3] = svpwm.VecSector*1000; #endif SDS_OutPut_Data_INT(user_data); } return 0; } /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

你可能感兴趣的:(STM32,IQMath,stm32,定点运算,DSP,mdk)