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

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

[复制链接]
七哥 发布时间:2018-9-11 02:02
本帖最后由 toofree 于 2018-9-14 08:46 编辑 * r: ^3 B# n) d6 j4 B( Z& c
* S# H; z$ j" ~
【STM32电机培训】——5、任务3电机状态切换、正反转0 j7 {: k  R9 ^" D; `8 `

* F0 ^- L; F( S: J! r; {! T( D+ }1 i" a3 o* e" b

' ]' R% n4 a& k# o' C) v任务目标:9 g4 W- \- d8 p) @; j

" g+ w' K3 E2 y  a) Y5 [4 ]! t

/ A1 ^( k# o3 m0 ~6 N 01.jpg * o0 Z! E6 [$ j" t- A8 S. e! w  u4 p

7 ~. I4 Z' V& G+ `) P$ d8 v

+ s1 B, @& k3 }: X( A3 `2 K# \3 O2 x, Q, [
, A; F' r( [  J% W4 z
02.jpg
6 |% `0 B* d9 M( B6 U, C" s0 ?4 Q( u: ]( ^1 b5 ?
0 |2 q4 ^7 ?. T: ^
03.jpg 5 A" s& m2 E) ~: z/ J7 Q

5 q6 F. b' k2 l. j- S, {) o5 p

: t% ^* L8 X6 m4 C/ v' P9 S. i, ^5 ]" F9 L+ W

3 ]# x1 R% [: | 04.jpg
6 O" h* O" E* u, X  k1 ?5 [. L' {8 p6 m
! I: O5 @3 G* |- i, E* v
$ q/ H. G6 K. p( H5 p

, E3 \' Y4 O# }- ~0 F4 c* H

1 n0 K& l: Z0 k' t( e, ]本实验源程序基于上一贴,做了适当修改。9 _$ Z2 z( Q8 A" y4 I1 n3 s. o
【STM32电机培训】——4、任务2电机设定程序修改PI参数  W4 O& |4 f* X* R# [9 l
https://www.stmcu.org.cn/module/forum/forum.php?mod=viewthread&tid=617433&fromuid=307297
& U7 d3 S& b2 s3 j' s% E(出处: 意法半导体STM32/STM8技术社区)
9 U7 u9 Y: c- @1 t
& _3 [5 G5 d  P+ x; J1 A. _
  ~6 @3 j8 H" }2 ?
- m  I6 N; e" p6 N* s
新增包含了头文件“"SystemNDriveParams.h",新增了外部变量声明“extern STM_Handle_t STM[NBR_OF_MOTORS]”,电机正、反转速度设定做成了宏定义“INVERT”、“NONINVT”。
% S6 ]6 f% J2 G0 L  { 10.jpg 9 J" Q% b: ]5 e2 t, h
- [+ c3 r1 T3 I- v7 d

! j0 E& J, w, j: d- \: s用户主程序,可以分为5块。初始状态设定、出错处理(详见注释)、周期性正反转切换、时基控制(定时0.1s)、LED闪灯灯。现在唯一有疑问的就是,这个“错误状态”反馈怎么玩,反馈给谁?对于本实验的意义,是想知道详细出错信息吗?: P5 V0 d  A3 P) n; j8 p% D/ q0 b
11.jpg
( m; ?6 C- j1 a5 L) _- a6 t% E& d

2 o7 \) k/ M" @* J下载程序到开发套件中。打开Workbench界面,并与目标板套件连接
, i) q. R6 [* e' g1 C 19.jpg
& a! a( [' d) K$ z" x- s7 q* o4 w7 z; h$ O  ?; K
0 O9 x) [( i/ a( |
在“监控”窗口下,在打开“Plotter”绘图窗口。观察电机速度状态变化: m+ [! O/ R1 |$ A3 e
20.jpg ( |- a0 |  e7 A: ~, O
8 U+ B: V! N5 N  X, q( b5 Z' N
+ v0 a+ q! \/ \/ w4 Z5 V  k
局部放大,可以看到电机运行速度反馈丢失出错、清除错误、重启电机、重新建立速度反馈,正常工作。7 d3 Y' h& l. x$ E! [6 W
21.jpg
) R; K/ }$ l: Y& C9 u) O9 {
+ U# V6 [6 M( w/ _; J

2 c* F9 s% v$ G, N+ h1 b& G在Workbench界面观察电机状态变化,一共出现过5种状态:Run、Idle、Start、Fault Over、Unknow,但是Unknow时间太短,未能抓图捕获。
) s2 b& P- V- e" o; j% y
& I9 ?2 Y0 E$ k& E
3 j, L9 x( p- y, U
Run状态
( z/ J* O) m# M" u* N 22.jpg
" o3 X* H$ l, r2 y% h
8 s$ @: O4 G* d' v
* J9 P, Z3 |% N- E- w$ V
Idle状态
- x) N4 V2 G- N: O3 t+ b- g 24.jpg
- [  r; Q. Y1 \9 p

/ b* u% k. t& z0 G2 e. Z1 lStart状态
8 j/ Q( k- e, y4 e 23.jpg & D& f7 J6 C6 \/ [" }, D3 x; {9 M

( J$ D7 J" f# f; {! m/ p( HFault Over状态
# I, n2 z" O! }3 v! ?: U% g 25.jpg
, d* ^5 k6 U. m8 L3 Y. t$ u6 H1 p. F! l5 c% o$ ?5 N) I+ c
0 A3 d' V& q* T* D* I7 E( b2 d- e5 ?
从State_t的枚举类型定义来看,状态还有好多种。如果要搞明白,需要进一步研究。4 A  Y" [, F9 I4 _4 ?- q
  1. typedef enum7 b3 X0 ~5 D8 R( U1 F- f  k8 G
  2. {) b, ]" u5 r) k$ W7 ^5 T& j% E
  3. ICLWAIT = 12,         /*!< Persistent state, the system is waiting for ICL
    0 g  v8 A6 z" u0 `& [
  4.                            deactivation. Is not possible to run the motor if ( M1 {. x) R: J" }6 u
  5.                            ICL is active. Until the ICL is active the state is : G' D; ]/ K( Y& ^6 ?2 @
  6.                            forced to ICLWAIT, when ICL become inactive the state ' D, z1 L% U4 e8 P' X. w! |% g
  7.                            is moved to IDLE */- g9 t) Y' z1 Z( n8 q' U
  8. IDLE = 0,             /*!< Persistent state, following state can be IDLE_START
    / B5 c. M$ Y, l' t' ?$ q3 A6 ^
  9.                            if a start motor command has been given or
    : L( D+ v/ C! n) g/ x  K' ?2 s, d
  10.                            IDLE_ALIGNMENT if a start alignment command has been
    4 x# @; F  c( o( K
  11.                            given */
    ' F0 `' d& I& U$ x2 w
  12. IDLE_ALIGNMENT = 1,   /*!< "Pass-through" state containg the code to be executed / w5 t+ `4 {: i' P3 l4 J& k
  13.                            only once after encoder alignment command.
    + n( D( V. X- T3 r6 S" m0 ]5 r
  14.                            Next states can be ALIGN_CHARGE_BOOT_CAP or
    ; a6 U8 R( t( Q( d2 I# n
  15.                            ALIGN_OFFSET_CALIB according the configuration. It % g/ `" \! D# T
  16.                            can also be ANY_STOP if a stop motor command has been 5 A# K6 a) D1 {1 d8 I
  17.                            given. */
    6 }+ h5 ]4 w% w- |5 B: }
  18. ALIGN_CHARGE_BOOT_CAP = 13,/*!< Persistent state where the gate driver boot $ z. c) B6 {+ ^( T! H6 E$ E
  19.                            capacitors will be charged. Next states will be + N. |) `3 t' e( y( U
  20.                            ALIGN_OFFSET_CALIB. It can also be ANY_STOP if a stop - X8 g* @: j: Q; P! Q& \
  21.                            motor command has been given. */
    . a7 B  ]1 e3 n( s% j# J
  22. ALIGN_OFFSET_CALIB = 14,/*!< Persistent state where the offset of motor currents
    . H4 M, U8 q$ `  I
  23.                            measurements will be calibrated. Next state will be 5 Y( g- y, p' H- V: L6 d$ ~2 t
  24.                            ALIGN_CLEAR. It can also be ANY_STOP if a stop motor 5 p$ K9 j5 N# z" G9 F& |% [
  25.                            command has been given. */5 a/ B) m# x  }& a! d! K9 v1 ?
  26. ALIGN_CLEAR = 15,     /*!< "Pass-through" state in which object is cleared and
    - f8 E/ U8 \% ]* N9 v; _/ K
  27.                            set for the startup.
    " e+ k' \, d* L, Z( s2 [' a+ n
  28.                            Next state will be ALIGNMENT. It can also be ANY_STOP
    + _& f& _8 t+ ]! G
  29.                            if a stop motor command has been given. */6 M1 t- c* F) V0 @6 y
  30. ALIGNMENT = 2,        /*!< Persistent state in which the encoder are properly
    & y) U5 R+ C, _6 F
  31.                            aligned to set mechanical angle, following state can
    7 k8 U, o& v1 y2 z: E7 y
  32.                            only be ANY_STOP */  f5 c1 q& m- e9 K
  33. IDLE_START = 3,       /*!< "Pass-through" state containg the code to be executed
    % w9 W8 u, w2 `7 p% J; b! ^
  34.                            only once after start motor command.   `( k9 M7 W7 `4 P: ~
  35.                            Next states can be CHARGE_BOOT_CAP or OFFSET_CALIB
    ' ^: b" c6 D6 k" M
  36.                            according the configuration. It can also be ANY_STOP / V9 F. t+ X$ Y" E/ Z' p- c, ^( m
  37.                            if a stop motor command has been given. */8 U" K8 W/ l3 S
  38. CHARGE_BOOT_CAP = 16, /*!< Persistent state where the gate driver boot 2 L, A+ o- m8 N' f# l8 z! C
  39.                            capacitors will be charged. Next states will be , E  ]7 G7 P$ c+ u# D  W) z
  40.                            OFFSET_CALIB. It can also be ANY_STOP if a stop motor
    7 L3 g8 k8 I) g7 f7 L  @! A
  41.                            command has been given. */# K& _. q0 g+ D$ Y( r3 ?
  42. OFFSET_CALIB = 17,    /*!< Persistent state where the offset of motor currents 8 k0 s3 u& j5 F6 s3 o
  43.                            measurements will be calibrated. Next state will be
    7 w" L  }) I/ ?5 R' }8 b1 I" t1 U
  44.                            CLEAR. It can also be ANY_STOP if a stop motor
    % U" C# z* O  w# U. N
  45.                            command has been given. */% }( ]- K! W/ c
  46. CLEAR = 18,           /*!< "Pass-through" state in which object is cleared and 4 \7 O5 h* w( n3 e& |# l9 K
  47.                            set for the startup.
    * N* A" h: w. N3 D1 g4 `
  48.                            Next state will be START. It can also be ANY_STOP if $ X, h7 l9 H$ O' r& Z
  49.                            a stop motor command has been given. */  q+ q* X/ y% y. N3 a
  50. START = 4,            /*!< Persistent state where the motor start-up is intended
    7 I( P% m: f$ A! E7 A
  51.                            to be executed. The following state is normally
    0 s+ J8 j& C3 v7 J0 e- G. `
  52.                            START_RUN as soon as first validated speed is
    + b# L& p( I# ?  a5 b2 Y# [" X
  53.                            detected. Another possible following state is
    2 E; I' w3 y* _1 G! ?( x
  54.                            ANY_STOP if a stop motor command has been executed */7 x% z/ N- g  ~/ C! t& M2 f
  55. START_RUN = 5,        /*!< "Pass-through" state, the code to be executed only # `8 a. r4 K" t" E: d" d
  56.                            once between START and RUN states it’s intended to be 6 @' b  O. Z6 x3 d
  57.                            here executed. Following state is normally  RUN but ! O+ n% y# N; S: w
  58.                            it can also be ANY_STOP  if a stop motor command has
    4 T8 {4 t$ {# ?- j. ^: }/ E
  59.                            been given */. V+ Q; E1 f. S1 x
  60. RUN = 6,              /*!< Persistent state with running motor. The following ; M% g& g& e. T* u) \  b+ g
  61.                            state is normally ANY_STOP when a stop motor command $ t/ ]7 C8 K& `, s7 ~( [1 v$ g4 O9 y
  62.                            has been executed */0 L) S. ^6 Q5 F, |) D4 N" }
  63. ANY_STOP = 7,         /*!< "Pass-through" state, the code to be executed only 1 |" j2 D$ `1 h
  64.                            once between any state and STOP it’s intended to be
    7 e4 N/ K" `: [. l; w' z, C
  65.                            here executed. Following state is normally STOP */
    ) w6 P" u* [( \. Q/ M! _
  66. STOP = 8,             /*!< Persistent state. Following state is normally   |, p- R, ]  ^6 c. }
  67.                            STOP_IDLE as soon as conditions for moving state
    3 D; I1 \/ {9 {& ]$ y. ^
  68.                            machine are detected */0 t9 O6 v/ O" B) X/ f5 R3 Z- R
  69. STOP_IDLE = 9,        /*!< "Pass-through" state, the code to be executed only5 m- b. L+ p% w. T, c6 z
  70.                            once between STOP and IDLE it’s intended to be here
    0 A, {' V. l* s. w4 Z
  71.                            executed. Following state is normally IDLE */, O0 p' g, J" b+ ~. t
  72. FAULT_NOW = 10,       /*!< Persistent state, the state machine can be moved from
    % D: A# q4 p  M% Y# Q3 q5 R
  73.                            any condition directly to this state by
      X3 U4 p2 z+ a  `6 T- `( n' W2 x, P
  74.                            STM_FaultProcessing method. This method also manage
    ! I! k. m. C4 c
  75.                            the passage to the only allowed following state that
    1 K1 y7 @( a4 Z& _. }# ?) x. L
  76.                            is FAULT_OVER */+ Y, T( u2 |/ g7 v! v
  77. FAULT_OVER = 11       /*!< Persistent state where the application is intended to
    9 o/ f- Q" R+ h, z3 C
  78.                           stay when the fault conditions disappeared. Following
    + P1 R( Y* E' t) R+ B) x% L
  79.                           state is normally STOP_IDLE, state machine is moved as , K6 d9 ^' c; Y
  80.                           soon as the user has acknowledged the fault condition.
    7 J- V$ R0 O* o, Z# @
  81.                       */5 F# p* c5 R/ V; }, \  D
  82. } State_t;  
    % X/ W+ W/ y, K
复制代码

- K* P- A$ s% |( q

/ ?* k% _7 k* n- N4 e* C9 M
7 n5 G5 y. c4 ]0 c! h0 T6 h
好了,本贴任务3完成。
6 ^0 k, W0 l0 V/ j% p' c1 M1 a& p% }9 L1 x5 H4 t
按照惯例,程序附上:; Q9 L3 X. ]! u; Y% `
P-NUCLEO-IHM001_ zhengfan.rar (8.99 MB, 下载次数: 60)
赞 收藏 1 评论3 发布时间:2018-9-11 02:02

举报

3个回答
ersha4877 回答时间:2018-9-11 09:46:04
正好有块板子,等着慢慢学习
七哥 回答时间:2018-9-11 10:09:58
ersha4877 发表于 2018-9-11 09:46" j$ H& Q/ W( e
正好有块板子,等着慢慢学习

, h1 r9 ~1 r. Z9 }) ]多谢捧场
0 r3 ?- i1 r+ W  ]7 c# x羡慕你的HP3457和吉时利2000
STM1024 回答时间:2018-9-11 13:08:26
我也想知道,这个肯定是采用的串口通讯,但是格式具体是怎样的,ST似乎并没有公布,在代码中看不到
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版