你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【STM32电机培训】——5、任务3电机状态切换、正反转

[复制链接]
toofree 发布时间:2018-9-11 02:02
本帖最后由 toofree 于 2018-9-14 08:46 编辑

【STM32电机培训】——5、任务3电机状态切换、正反转



任务目标:


01.jpg




02.jpg


03.jpg




04.jpg




本实验源程序基于上一贴,做了适当修改。
【STM32电机培训】——4、任务2电机设定程序修改PI参数
https://www.stmcu.org.cn/module/forum/forum.php?mod=viewthread&tid=617433&fromuid=307297
(出处: 意法半导体STM32/STM8技术社区)



新增包含了头文件“"SystemNDriveParams.h",新增了外部变量声明“extern STM_Handle_t STM[NBR_OF_MOTORS]”,电机正、反转速度设定做成了宏定义“INVERT”、“NONINVT”。
10.jpg


用户主程序,可以分为5块。初始状态设定、出错处理(详见注释)、周期性正反转切换、时基控制(定时0.1s)、LED闪灯灯。现在唯一有疑问的就是,这个“错误状态”反馈怎么玩,反馈给谁?对于本实验的意义,是想知道详细出错信息吗?
11.jpg


下载程序到开发套件中。打开Workbench界面,并与目标板套件连接
19.jpg


“监控”窗口下,在打开“Plotter”绘图窗口。观察电机速度状态变化
20.jpg


局部放大,可以看到电机运行速度反馈丢失出错、清除错误、重启电机、重新建立速度反馈,正常工作。
21.jpg


Workbench界面观察电机状态变化,一共出现过5种状态:Run、Idle、Start、Fault Over、Unknow,但是Unknow时间太短,未能抓图捕获


Run状态
22.jpg


Idle状态
24.jpg

Start状态
23.jpg

Fault Over状态
25.jpg


从State_t的枚举类型定义来看,状态还有好多种。如果要搞明白,需要进一步研究。
  1. typedef enum
  2. {
  3. ICLWAIT = 12,         /*!< Persistent state, the system is waiting for ICL
  4.                            deactivation. Is not possible to run the motor if
  5.                            ICL is active. Until the ICL is active the state is
  6.                            forced to ICLWAIT, when ICL become inactive the state
  7.                            is moved to IDLE */
  8. IDLE = 0,             /*!< Persistent state, following state can be IDLE_START
  9.                            if a start motor command has been given or
  10.                            IDLE_ALIGNMENT if a start alignment command has been
  11.                            given */
  12. IDLE_ALIGNMENT = 1,   /*!< "Pass-through" state containg the code to be executed
  13.                            only once after encoder alignment command.
  14.                            Next states can be ALIGN_CHARGE_BOOT_CAP or
  15.                            ALIGN_OFFSET_CALIB according the configuration. It
  16.                            can also be ANY_STOP if a stop motor command has been
  17.                            given. */
  18. ALIGN_CHARGE_BOOT_CAP = 13,/*!< Persistent state where the gate driver boot
  19.                            capacitors will be charged. Next states will be
  20.                            ALIGN_OFFSET_CALIB. It can also be ANY_STOP if a stop
  21.                            motor command has been given. */
  22. ALIGN_OFFSET_CALIB = 14,/*!< Persistent state where the offset of motor currents
  23.                            measurements will be calibrated. Next state will be
  24.                            ALIGN_CLEAR. It can also be ANY_STOP if a stop motor
  25.                            command has been given. */
  26. ALIGN_CLEAR = 15,     /*!< "Pass-through" state in which object is cleared and
  27.                            set for the startup.
  28.                            Next state will be ALIGNMENT. It can also be ANY_STOP
  29.                            if a stop motor command has been given. */
  30. ALIGNMENT = 2,        /*!< Persistent state in which the encoder are properly
  31.                            aligned to set mechanical angle, following state can
  32.                            only be ANY_STOP */
  33. IDLE_START = 3,       /*!< "Pass-through" state containg the code to be executed
  34.                            only once after start motor command.
  35.                            Next states can be CHARGE_BOOT_CAP or OFFSET_CALIB
  36.                            according the configuration. It can also be ANY_STOP
  37.                            if a stop motor command has been given. */
  38. CHARGE_BOOT_CAP = 16, /*!< Persistent state where the gate driver boot
  39.                            capacitors will be charged. Next states will be
  40.                            OFFSET_CALIB. It can also be ANY_STOP if a stop motor
  41.                            command has been given. */
  42. OFFSET_CALIB = 17,    /*!< Persistent state where the offset of motor currents
  43.                            measurements will be calibrated. Next state will be
  44.                            CLEAR. It can also be ANY_STOP if a stop motor
  45.                            command has been given. */
  46. CLEAR = 18,           /*!< "Pass-through" state in which object is cleared and
  47.                            set for the startup.
  48.                            Next state will be START. It can also be ANY_STOP if
  49.                            a stop motor command has been given. */
  50. START = 4,            /*!< Persistent state where the motor start-up is intended
  51.                            to be executed. The following state is normally
  52.                            START_RUN as soon as first validated speed is
  53.                            detected. Another possible following state is
  54.                            ANY_STOP if a stop motor command has been executed */
  55. START_RUN = 5,        /*!< "Pass-through" state, the code to be executed only
  56.                            once between START and RUN states it’s intended to be
  57.                            here executed. Following state is normally  RUN but
  58.                            it can also be ANY_STOP  if a stop motor command has
  59.                            been given */
  60. RUN = 6,              /*!< Persistent state with running motor. The following
  61.                            state is normally ANY_STOP when a stop motor command
  62.                            has been executed */
  63. ANY_STOP = 7,         /*!< "Pass-through" state, the code to be executed only
  64.                            once between any state and STOP it’s intended to be
  65.                            here executed. Following state is normally STOP */
  66. STOP = 8,             /*!< Persistent state. Following state is normally
  67.                            STOP_IDLE as soon as conditions for moving state
  68.                            machine are detected */
  69. STOP_IDLE = 9,        /*!< "Pass-through" state, the code to be executed only
  70.                            once between STOP and IDLE it’s intended to be here
  71.                            executed. Following state is normally IDLE */
  72. FAULT_NOW = 10,       /*!< Persistent state, the state machine can be moved from
  73.                            any condition directly to this state by
  74.                            STM_FaultProcessing method. This method also manage
  75.                            the passage to the only allowed following state that
  76.                            is FAULT_OVER */
  77. FAULT_OVER = 11       /*!< Persistent state where the application is intended to
  78.                           stay when the fault conditions disappeared. Following
  79.                           state is normally STOP_IDLE, state machine is moved as
  80.                           soon as the user has acknowledged the fault condition.
  81.                       */
  82. } State_t;  
复制代码



好了,本贴任务3完成。

按照惯例,程序附上:
P-NUCLEO-IHM001_ zhengfan.rar (8.99 MB, 下载次数: 55)
收藏 评论3 发布时间:2018-9-11 02:02

举报

3个回答
ersha4877 回答时间:2018-9-11 09:46:04
正好有块板子,等着慢慢学习
toofree 回答时间:2018-9-11 10:09:58
ersha4877 发表于 2018-9-11 09:46
正好有块板子,等着慢慢学习

多谢捧场
羡慕你的HP3457和吉时利2000
stm1024 回答时间:2018-9-11 13:08:26
我也想知道,这个肯定是采用的串口通讯,但是格式具体是怎样的,ST似乎并没有公布,在代码中看不到

所属标签

STM32团队

意法半导体微控制器和微处理器拥有广泛的产品线,包含低成本的8位单片机和基于ARM® Cortex®-M0、M0+、M3、M4、M33、M7及A7内核并具备丰富外设选择的32位微控制器及微处理器


最新内容

相似分享

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版