【STM32电机培训】4 修改代码控制电机运转
通过参加电机培训,对STM32控制无刷电机控制技术有了进一步的理解。本次就针对STSW-STM32100\STM32CubeExpansion_SPN7_V1.1.0演示代码进行修改,达到让电机按照自己的要求运转。
首先先关闭电位器调速功能。在MC_SixSetup_param.h文件中的“BASIC PARAMETERS”有对电机基本控制参数的定义,将#define POTENTIOMETER 从1 改成0.
MC_SixSetup_param.h
- <font size="3">/* ****************************************************************************
- ==============================================================================
- ###### BASIC PARAMETERS ######
- ==============================================================================
- **************************************************************************** */
- #define NUM_POLE_PAIRS 7 /*!< Number of Motor Pole pairs */
- #define DIRECTION 0 /*!< Set motor direction CW = 0 and CCW = 1*/
- #define TARGET_SPEED 3000 /*!< Target speed in closed loop control */
- #define POTENTIOMETER 0 /*!< Enable (1)/Disable (0) the potentiometer */
- /* **************************************************************************** </font>
复制代码
接着在main_F302.c的主循环中添加代码,让电机以500转速运行5秒停止5秒,再以6000转速运行5秒。对电机的控制方法ST 官方在注释中写得非常清楚,改变电机运行参数很方便。
main_F302.c
- <font size="3">/* ****************************************************************************
- ==============================================================================
- ###### BASIC PARAMETERS ######
- ==============================================================================
- **************************************************************************** */
- #define NUM_POLE_PAIRS 7 /*!< Number of Motor Pole pairs */
- #define DIRECTION 0 /*!< Set motor direction CW = 0 and CCW = 1*/
- #define TARGET_SPEED 3000 /*!< Target speed in closed loop control */
- #define POTENTIOMETER 0 /*!< Enable (1)/Disable (0) the potentiometer */
- /* ****************************************************************************
- ==============================================================================
- ###### How to use the 6Step FW Example project ######
- ==============================================================================
- This workspace contains the middleware layer with Motor Control library to drive
- a motor connected on X-Nucleo board performing a 6-step control algorithm
- allowing the motor speed regulation through a potentiometer. The 6-step algorithm
- is based on 1shunt current sensing mode and sensorless algorithm for bEmf detection.
- The workspace is provided for STM32Fxx-Nucleo in four different configurations,
- normal, demo, comm mode, boot mode. The "normal" mode waits the blue button event
- to start the motor, the "demo" mode starts and stop the motor automatically, the
- "comm" mode enables the communication protocol with external PC terminal and the
- "boot" mode enables the FW for external boot loader.
-
- A list of APIs is provided to send command to 6Step lib, for instance:
-
- (#) MC_StartMotor() -> Start the motor
-
- (#) MC_StoptMotor() -> Stop the motor
-
- (#) MC_Set_Speed(...) -> Set the new motor speed
-
- The MC_SixStep_param.h contains the full list of MC parameters
-
- ==============================================================================
- ###### USER SPACE ######
- ==============================================================================
- *****************************************************************************/
-
-
- /****************************************************************************/
- //添加的代码
- HAL_Delay(2000);
- MC_Set_Speed(500);
- MC_StartMotor();
- HAL_Delay(5000);
- MC_StopMotor();
- MC_Set_Speed(6000);
- </font>
复制代码
本次实验是6步梯形模式,按照要求对IHM07M1板子上的条线进行相应设置。编译下载,通电运行,电机已经能够按照预定参数正确运行了。
http://player.youku.com/player.php/sid/XMjk4NDc1OTkyOA==/v.swf
|
谢谢! 这个我看过了,我手上没有ST的Noclude板子,有别的无刷驱动板,想要用ST的电机库配置一个适合自己的模板,现在这个文档里面没有教怎么使用 Workbench, 自己不会配。 不知道楼主有没有资料了,关于使用Workbench
举个例子,数控线切割机床就是步进电机控制,每给一个脉冲,电机就转动1个角度。楼上应该去参阅步进电机相关资料,比如数控机床控制等等。本人也是门外汉。
楼主,你用的电机是STM32F302吗?我这边想用STM32F302+IHM07M1驱动板上的电位器进行控制速度,我看您这个功能可能跟我这个有点相关,不知道您这边可以加个QQ交流一下吗?我的是625212098
都是ST 官方的:
谢谢
只能用于ST官网的板子么?? 我手里有一块 无刷驱动板,MOS管的引脚连接的是TIM1的6个通道,和ST的驱动板子是不一样的,,不知道能不能用 这个程序 了???
https://www.stmcu.org.cn/document/detail/index/id-218177
ST官方的电机培训资料,你可以参考
楼主你这个工程是用的STM32CubeMX生成的工程吗?
我也只是班门弄斧而已。工程不是CubeMX生成的,是ST官方下载的。
https://www.stmcu.org.cn/module/forum/thread-613011-1-1.html
步进电机每给一个脉冲转动一个角度,与无刷电机应该还是有区别的。
那么 就精准度来说,哪种电机更好一点呢