请选择 进入手机版 | 继续访问电脑版

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

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

[复制链接]
七哥 发布时间:2018-9-11 02:02
本帖最后由 toofree 于 2018-9-14 08:46 编辑 : P: J) y3 ~! x' K; I! i

- p' N% ]: Q, o& A6 [! I" O$ i. z【STM32电机培训】——5、任务3电机状态切换、正反转' U5 X6 ?# U! A  E/ G" {
9 G% D& L5 f' c/ t3 f  {
7 I1 S- Y1 r0 e" _. Y

' r9 H, P% O6 K6 ~7 I* y任务目标:' y/ d3 u% K: r' k! Y' J
5 g* [6 x) r2 f6 d  R+ I# h+ h( E

7 q! b% j2 S( ~5 a 01.jpg * b! I4 t  }9 r+ e$ M

7 ], U8 a8 p6 P6 A6 c2 L% ?4 \  l

; u7 J2 X) N) q! o8 k2 I- V: M' W' A2 I: e  R
/ B/ h/ }& E! D) y3 q
02.jpg
/ v# A" {" B  J4 V: s
: `  C- F0 l6 j8 _3 B  c  k

9 a/ y/ x1 j0 b" j7 s 03.jpg
# F. e! F0 {+ L5 `$ V1 j* A- b( w& ]3 S1 ^0 \# j( X7 R( j- V  e: m
8 \6 J; c' w1 j6 u6 w( J
( M" c: K, z3 F# [' D5 \

: h2 \% f8 Y- ]' H: z4 \* z- [ 04.jpg # y7 [* _& e: {" {- |

4 X% r: g+ `& H* ~2 I* x) A) u) K

2 W) D: X0 f' D3 W! H, u+ u" g
! D' G8 _% R( i( L

: }4 [8 `$ }5 j" g本实验源程序基于上一贴,做了适当修改。
/ ]" {7 I, P7 i) G( b+ l【STM32电机培训】——4、任务2电机设定程序修改PI参数9 V' `# I; m# l; Z" R; m
https://www.stmcu.org.cn/module/forum/forum.php?mod=viewthread&tid=617433&fromuid=3072973 s! O# `# @0 A/ k# _- O$ m
(出处: 意法半导体STM32/STM8技术社区)5 o2 Q3 H! _7 H, i- B1 d

" x9 _9 z7 z. M) n! {: e! K; z, O, b5 X/ ^

# J0 f3 o& m. P: I) \新增包含了头文件“"SystemNDriveParams.h",新增了外部变量声明“extern STM_Handle_t STM[NBR_OF_MOTORS]”,电机正、反转速度设定做成了宏定义“INVERT”、“NONINVT”。/ K5 J; ]4 }) v% n* h& K
10.jpg
! y3 L' M* \/ r: k$ K: E& U/ h
, B0 D) {$ R' G! @: {7 ^: @
$ T- h- ?% _4 e7 b+ |, R
用户主程序,可以分为5块。初始状态设定、出错处理(详见注释)、周期性正反转切换、时基控制(定时0.1s)、LED闪灯灯。现在唯一有疑问的就是,这个“错误状态”反馈怎么玩,反馈给谁?对于本实验的意义,是想知道详细出错信息吗?; |" E( c0 @3 m5 P3 f" u( V
11.jpg : @: a4 |7 g* x

$ L9 {# |) Q; _4 |  A, ]) S
/ T& w" x- Q0 y
下载程序到开发套件中。打开Workbench界面,并与目标板套件连接9 w+ L' i# t9 O- t! i5 L
19.jpg
) ]7 B* `! e6 e" B  y# W8 X/ K' n  }* M4 I) w5 ^# B, W
+ ]; z1 W- D" Z8 x  |% ~
“监控”窗口下,在打开“Plotter”绘图窗口。观察电机速度状态变化
& h, {" C& k. M; | 20.jpg
: |! R2 @: q9 M. o9 P! `% _+ x+ r0 |" k& t  h

* Z/ u$ E2 H7 \$ m4 G" [9 {局部放大,可以看到电机运行速度反馈丢失出错、清除错误、重启电机、重新建立速度反馈,正常工作。
/ c; ~+ w1 w1 O7 r 21.jpg
3 s9 F4 E3 ?  X; k3 `" z# Z. s# N0 Q9 w* k& ^: q9 m

2 c3 V' i9 h% l/ S) |' A$ X& U/ wWorkbench界面观察电机状态变化,一共出现过5种状态:Run、Idle、Start、Fault Over、Unknow,但是Unknow时间太短,未能抓图捕获& l5 e. h. M6 x, _- h

% m8 Z& D: p# H0 N& Y3 z

/ R; L& I" ?5 Z7 HRun状态, c: V& i: l2 K; X& @
22.jpg
4 J0 z1 m4 |7 s1 h, v+ x# R' S+ z: G: }
" m; j6 w6 h7 w+ J) J
Idle状态' x3 H$ o0 }8 D( X: [: r# i. E
24.jpg 5 b: U) P& h# I7 ]+ g
: m$ m5 s, O! k" I# V8 s
Start状态) y4 }. j! P# }. l/ _) S) y
23.jpg
* w6 u; J( H- D8 ~

. q; {; D4 B* k$ V$ V, PFault Over状态
& Q2 X/ }; q) Z 25.jpg
+ [. R: r9 l4 W6 {  M' A
& u) T1 p- T# R; ]! p
4 u# t; _3 c7 g
从State_t的枚举类型定义来看,状态还有好多种。如果要搞明白,需要进一步研究。
" O# g9 P: [& `, T: t  m
  1. typedef enum3 q; e2 L8 C: O- Z: ^: m
  2. {
    " I; z6 e3 M0 P. o+ B
  3. ICLWAIT = 12,         /*!< Persistent state, the system is waiting for ICL
      U- M% [& F* p; T8 A
  4.                            deactivation. Is not possible to run the motor if 0 O8 U. a2 P( c7 ]
  5.                            ICL is active. Until the ICL is active the state is
    - ]# o3 z: M+ `7 A
  6.                            forced to ICLWAIT, when ICL become inactive the state
    8 T+ Z2 l/ k# u, f
  7.                            is moved to IDLE */1 {7 ]3 J# l  H8 b8 Q; X: l; D
  8. IDLE = 0,             /*!< Persistent state, following state can be IDLE_START % M( V5 q9 O1 [: I* H
  9.                            if a start motor command has been given or
    : @. J1 y3 g: `1 f7 B* B6 ~
  10.                            IDLE_ALIGNMENT if a start alignment command has been + \- o" w( x0 G( n0 h/ B
  11.                            given */
    ' D1 J! ~" ~2 a, \
  12. IDLE_ALIGNMENT = 1,   /*!< "Pass-through" state containg the code to be executed 5 d2 {( x% J& P
  13.                            only once after encoder alignment command. % e: {. b( _0 f% ~
  14.                            Next states can be ALIGN_CHARGE_BOOT_CAP or
    " Y. x9 \9 n- n0 _4 t" Q5 {( c% T
  15.                            ALIGN_OFFSET_CALIB according the configuration. It
    3 g9 A! B  _" c; k$ V7 S
  16.                            can also be ANY_STOP if a stop motor command has been
    % J; ~1 u" u2 @- b; a/ n
  17.                            given. */
    : \4 L# E- A, s
  18. ALIGN_CHARGE_BOOT_CAP = 13,/*!< Persistent state where the gate driver boot ' [( H8 P" `" C
  19.                            capacitors will be charged. Next states will be . j; a) t+ ?7 r  [' D( ]& l
  20.                            ALIGN_OFFSET_CALIB. It can also be ANY_STOP if a stop   _2 W0 n, M% ?3 ~+ x  h
  21.                            motor command has been given. */3 C5 n7 T0 v$ k+ o: b% f- Y
  22. ALIGN_OFFSET_CALIB = 14,/*!< Persistent state where the offset of motor currents 5 O" v+ r" b6 \- Y1 n
  23.                            measurements will be calibrated. Next state will be
    6 X% G  q! l9 B- @& I0 k+ {4 }
  24.                            ALIGN_CLEAR. It can also be ANY_STOP if a stop motor 3 b! k: {  t4 z" n
  25.                            command has been given. */
    5 D; r6 F9 e; }) b6 P! A7 f
  26. ALIGN_CLEAR = 15,     /*!< "Pass-through" state in which object is cleared and
    & \: F( z+ z) O  }, D
  27.                            set for the startup.% Q5 W9 j: s2 e. j( \$ F5 _1 [* F
  28.                            Next state will be ALIGNMENT. It can also be ANY_STOP 7 D( ^: T: g( C; G
  29.                            if a stop motor command has been given. */
    . ^. h" C+ \: q6 B  [
  30. ALIGNMENT = 2,        /*!< Persistent state in which the encoder are properly
    . \1 d; `9 N/ _
  31.                            aligned to set mechanical angle, following state can ' a: x2 d$ O3 Q& G: D+ T5 {
  32.                            only be ANY_STOP */* o4 B+ X0 D1 l
  33. IDLE_START = 3,       /*!< "Pass-through" state containg the code to be executed1 `1 R* }1 ~  n' B# t4 `/ Y
  34.                            only once after start motor command.
    7 V7 y; u9 e  C+ u! X
  35.                            Next states can be CHARGE_BOOT_CAP or OFFSET_CALIB 9 x( o1 e) u/ X! y$ E0 g  N( r
  36.                            according the configuration. It can also be ANY_STOP
    ' Y: W/ n) Y; ]( C" t
  37.                            if a stop motor command has been given. */2 I  j% e6 j) R, {! b" N/ o
  38. CHARGE_BOOT_CAP = 16, /*!< Persistent state where the gate driver boot
    / g9 I  F# x0 F, |, F
  39.                            capacitors will be charged. Next states will be 7 I% K/ P; w, y
  40.                            OFFSET_CALIB. It can also be ANY_STOP if a stop motor
    ! P# u2 g+ q* D% z  d  H
  41.                            command has been given. *// D1 y" E+ G' w0 {/ c
  42. OFFSET_CALIB = 17,    /*!< Persistent state where the offset of motor currents
    5 d+ T/ v$ J" b7 e  b  t5 o) o/ L
  43.                            measurements will be calibrated. Next state will be # P, Z7 V% T0 x
  44.                            CLEAR. It can also be ANY_STOP if a stop motor & T4 F! Y5 Z, ?5 \$ M3 N% H1 u8 J
  45.                            command has been given. */
    % Y' p7 ~% Q6 B* J; Z2 Z' ~8 i9 T  v
  46. CLEAR = 18,           /*!< "Pass-through" state in which object is cleared and " y, A( S1 `$ o3 M* A8 ~, N
  47.                            set for the startup.
    ' F4 a& W2 h" w' W. o! e
  48.                            Next state will be START. It can also be ANY_STOP if 1 E* r5 |4 r" V. q: J
  49.                            a stop motor command has been given. */- i0 [, L7 K1 r2 J
  50. START = 4,            /*!< Persistent state where the motor start-up is intended * ~& }& X0 `+ Y7 o4 P$ `
  51.                            to be executed. The following state is normally
    * V7 A3 J( F! K- H# {! F) L% s
  52.                            START_RUN as soon as first validated speed is # r7 X- R7 k" L7 E$ a
  53.                            detected. Another possible following state is
    - A* i% A6 ^& v8 v
  54.                            ANY_STOP if a stop motor command has been executed */- o. ^/ U0 o0 ^( O: A! p8 J
  55. START_RUN = 5,        /*!< "Pass-through" state, the code to be executed only
    ' K) Q2 A9 Y5 m; G3 |7 z8 a
  56.                            once between START and RUN states it’s intended to be 2 b$ `" {9 o+ s( \# q4 A6 B0 l: w  u/ E
  57.                            here executed. Following state is normally  RUN but
    2 H: Q) Y1 C, P# C0 n+ f0 \6 v
  58.                            it can also be ANY_STOP  if a stop motor command has 6 `  r" h8 l& x9 @+ u
  59.                            been given */
    # M: |7 [6 z6 c: m: `
  60. RUN = 6,              /*!< Persistent state with running motor. The following $ o4 D7 p5 E' I8 p: c
  61.                            state is normally ANY_STOP when a stop motor command
    2 U; V2 W5 V/ j$ ]% {3 s
  62.                            has been executed */
    9 W3 ?* W  |: T" H
  63. ANY_STOP = 7,         /*!< "Pass-through" state, the code to be executed only 3 }+ ~2 l7 O! w1 Z+ l1 x
  64.                            once between any state and STOP it’s intended to be 2 o" h) y0 A/ d) M. K, W: I
  65.                            here executed. Following state is normally STOP */
    3 W' I' X& H1 ~# [) j- u
  66. STOP = 8,             /*!< Persistent state. Following state is normally
    " q& G% W" [9 x$ |" P% q% y( v% U
  67.                            STOP_IDLE as soon as conditions for moving state
    : g+ z- A1 P5 i% z) r
  68.                            machine are detected */# U( h- W. R8 I5 c0 N  f7 w
  69. STOP_IDLE = 9,        /*!< "Pass-through" state, the code to be executed only3 `9 @: M% _: `. i0 T* U4 v. I
  70.                            once between STOP and IDLE it’s intended to be here + k) }$ \1 }; P  ^" X
  71.                            executed. Following state is normally IDLE */
    / D' a/ @9 P) ~) Z
  72. FAULT_NOW = 10,       /*!< Persistent state, the state machine can be moved from2 |% w& o( A5 Y6 o# m
  73.                            any condition directly to this state by
    6 a$ f! d) }5 y4 R% j0 A) o8 ~  J
  74.                            STM_FaultProcessing method. This method also manage
    " a- L8 n/ t% e6 `" d5 n
  75.                            the passage to the only allowed following state that
    0 ?" M1 u7 l3 F% @7 A
  76.                            is FAULT_OVER */
    2 H+ y3 A) @  Y: q/ z
  77. FAULT_OVER = 11       /*!< Persistent state where the application is intended to
    4 o! j  D6 J2 ]4 D2 w
  78.                           stay when the fault conditions disappeared. Following
    - [3 b) P5 Z- Q+ Z
  79.                           state is normally STOP_IDLE, state machine is moved as
    9 C) j) i7 d/ U, ~# ~
  80.                           soon as the user has acknowledged the fault condition.
      X7 V/ a' S; {$ V! _' m4 w
  81.                       */
    / S/ q% G" [9 ^
  82. } State_t;  # o4 o0 R$ }- r& R  Y" b
复制代码
9 e  l1 P" q6 I- b+ b  l& l! S( f! U
, o6 [9 G+ f# g

8 j6 \$ ~8 ~6 E7 G# |0 X" f  n
好了,本贴任务3完成。- H: c  E  b5 R
" N. I3 d. z& K0 W5 j! r# v
按照惯例,程序附上:
4 U" U# j  Z! g- r& l% d3 L P-NUCLEO-IHM001_ zhengfan.rar (8.99 MB, 下载次数: 58)
收藏 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
2 b8 V8 f& l( [$ z2 Q正好有块板子,等着慢慢学习
) B" T7 X# z  l1 u* F( W1 K
多谢捧场
- t* h% }, r& H& ~* L羡慕你的HP3457和吉时利2000
STM1024 回答时间:2018-9-11 13:08:26
我也想知道,这个肯定是采用的串口通讯,但是格式具体是怎样的,ST似乎并没有公布,在代码中看不到

所属标签

相似分享

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版