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

STM32步进电机程序  

[复制链接]
yanghappy 发布时间:2011-3-13 13:05
阅读主题, 点击返回1楼
收藏 7 评论1161 发布时间:2011-3-13 13:05
1161个回答
zhangyalei 回答时间:2014-4-2 19:54:14

回复:STM32步进电机程序

thankyou
pctongx 回答时间:2014-4-2 20:43:07

回复:STM32步进电机程序

谢谢楼主  学习一下
bananagg 回答时间:2014-4-3 20:59:31

RE:STM32步进电机程序

发大水法送方色任务是
champtech 回答时间:2014-4-4 10:21:16

回复:STM32步进电机程序

看看和我的算法是否一致
champtech 回答时间:2014-4-4 10:34:28

回复:STM32步进电机程序

太骗人了,都没有算法
一休 回答时间:2014-4-7 21:31:53

回复:STM32步进电机程序

不错,想学习下。
hbhdan 回答时间:2014-4-8 13:53:11

RE:STM32步进电机程序

re
LLU 回答时间:2014-4-8 20:29:43

RE:STM32步进电机程序

1
lihuanhuan19940 回答时间:2014-4-8 21:55:06

回复:STM32步进电机程序

 谢谢楼主
h32446975 回答时间:2014-4-8 23:09:47

RE:STM32步进电机程序

看看。看看。看看。看看。看看。
h32446975 回答时间:2014-4-8 23:13:05

RE:STM32步进电机程序

#include"stm32f10x_lib.h"
- l0 y" r; x" E* R% t% O  k& E6 _GPIO_InitTypeDef GPIO_InitStructure;. v3 I' |4 n  J3 i; R/ p$ K% t
ErrorStatus HSIStartUpStatus;* ?& N# m; j% G6 L# e
void NVIC_Configuration(void);" s! u3 m- e7 q
void RCC_Configuration(void);
2 D0 m0 j) |8 E2 r/ {* e# tvoid TIM2_Configuration(void);
: s$ I) x  c4 L$ Wvoid GPIO_Configuration(void);
$ P0 p, `" K  j# K#define VECT_TAB_RAM
+ @) b/ a  R3 [# bint main(void)
4 O( K! `9 S" q  u{' }% P  D  Q1 J
  #ifdef DEBUG
* c. S, e+ e  {/ I    debug();/*[初始化外围设备指针]*/" G" ?/ q% E4 _, Z8 q
  #endif
5 ]5 f4 ]4 f$ t; |( i+ q/ O0 n  RCC_Configuration(); //初始化时钟与复位  ) G0 \1 G5 V* [. h! `/ u
  NVIC_Configuration();//初始化中断嵌套) d4 f; o+ l: A/ H% D( y+ k
  TIM2_Configuration();//初始化定时器: K! m/ |9 E( G
  GPIO_Configuration();: t# F" H$ |/ |3 i) X$ F- r
  
% R0 D+ Y$ V: }8 m  GPIO_WriteBit(GPIOD, GPIO_Pin_7, (BitAction)(0));
6 y+ A& j" E5 y6 M  GPIO_WriteBit(GPIOD, GPIO_Pin_6, (BitAction)(0));  //DCY1 DCY2为00,即Normal %0 DECAY
2 B- D5 C) H8 u  
8 p7 T2 x1 O. q& t/ e  h5 H  GPIO_WriteBit(GPIOE, GPIO_Pin_7, (BitAction)(1));6 l  \% p, L. C9 C# F% V$ `+ K* N
  GPIO_WriteBit(GPIOB, GPIO_Pin_1, (BitAction)(0));  //M1M2为10,即1-2-phase
/ F9 I& ?2 P4 I1 z  
' A$ R! f6 J" T) E% c# I: ?  GPIO_WriteBit(GPIOA, GPIO_Pin_4, (BitAction)(0));  //正向旋转9 r6 S; F' }3 y% Q$ ]
    ~6 @8 I! s! u* z( d
  GPIO_WriteBit(GPIOB, GPIO_Pin_0, (BitAction)(0));$ L' z: J2 T, S2 c! M! k3 l5 {
  GPIO_WriteBit(GPIOC, GPIO_Pin_5, (BitAction)(1));  //TQ1 TQ2为01,即Current Ratio为50%* T) l2 Z7 B6 r
  GPIO_WriteBit(GPIOA, GPIO_Pin_7, (BitAction)(1));  //StepReset位
0 v; g% M9 `$ c2 `% Z  GPIO_WriteBit(GPIOC, GPIO_Pin_4, (BitAction)(1));  //StepEn 使能位  E8 R3 W8 x5 _7 z) b2 A! h( N
     
% d8 H4 m  n) ?* e, N" s  while(1)
# M) }) A% O3 ]6 O$ ]  {
- D& u6 s6 A7 V4 a% {$ ~  }2 j& `. Q5 ~0 x
}3 `0 h4 A8 b4 |! t- J) z# H9 D
void GPIO_Configuration(void)
) J( M4 x9 }: E  F: R" n; l& q{
* O1 y: H. ~/ c: u5 [3 j  GPIO_InitTypeDef GPIO_InitStructure;0 ?  k5 |: ?( {+ D9 V0 `, k7 o: y: a
  GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_7;   //PA的3.4.7接CLK,CW/CCW,StepReset
$ g9 `8 H$ `; `9 J: M  GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;3 L, ]& F; p3 k5 d) N; c* w2 W
  GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;; r: A  d* e6 E' Q! T
  GPIO_Init(GPIOA,&GPIO_InitStructure);
& {, x# p, B6 g0 _( }7 L  GPIO_InitStructure.GPIO_Pin= GPIO_Pin_5 | GPIO_Pin_6;   //PA的6.7接Protect和Mo
" K0 L* X: k; e, ^; _  GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
0 E- ~9 Q/ z' D* J% g- N! Q! U  GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;- w, }$ ~' n. p  P+ ~6 e- Q
  GPIO_Init(GPIOA,&GPIO_InitStructure);" m! r5 R& }: f
  GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4 | GPIO_Pin_5;   //PC的4.5接StepEn和TQ2 0 X7 I, T1 T: m" H% ?
  GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- R4 J* v* A% B8 {; E' t) E# z  GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
% `9 R( i# t7 y5 n  GPIO_Init(GPIOC,&GPIO_InitStructure);0 z$ {' _1 y6 v+ k- H. @
  GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0 | GPIO_Pin_1;   //PB的0.1接TQ1和M2' w# ^# U7 m; P) [* Q
  GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
' N0 v3 }0 K3 S4 C  GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;+ y% B& k2 i* l& x  {9 D* s4 q
  GPIO_Init(GPIOB,&GPIO_InitStructure);+ c0 }3 Y% {' E# ], t" i0 \* ?# n
  GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;   //PE7接M1
* }% m' R0 r) i) v2 i9 z  GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
$ Z, Z# |( Z' [- ^2 u  GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;. L  @% v, ~. s* F
  GPIO_Init(GPIOE,&GPIO_InitStructure);
/ J& N; o( @4 ?% [- J  
$ ?; d" z6 o3 s* h, D+ t0 |0 O  GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6 | GPIO_Pin_7;   //PD的67接DCY2和DCY1
9 ^) _) ~( f, C5 ~  GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
: T. N: a3 K! W8 C& P: d: Y0 m  GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;8 z9 f; B3 c! e; C& b& k
  GPIO_Init(GPIOD,&GPIO_InitStructure);
* I, j  G& {4 H} 7 q7 c/ B5 |; A! y* h: f; k2 P
void NVIC_Configuration(void)2 x* `6 N+ W0 @
{
- ~4 P3 C( \. E  NVIC_InitTypeDef NVIC_InitStructure;4 K  B- ^+ |) C
  
7 ^5 D! l2 {1 z' Q2 {3 U#ifdef  VECT_TAB_RAM   
% q# n7 d5 N4 p5 }' {9 H  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); & p( D% a4 {$ z, O  z" G
#else 5 d. a' U+ ^+ x  T
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
) D7 y) a. w" `) B! D+ o#endif
; q" \3 j% z1 ?6 [                                                     1 m, M* ^% ~; q& n2 P
  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;  //设置TIM2通道输入中断' V9 {" n: w" r1 M
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; /*配置优先级组*/! Q) [. ^$ I4 b$ @
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  2 c8 G- v- A* K6 _% R3 @$ I, l1 t" J
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;      /*允许TIM2全局中断*/8 g5 M! z5 Z( u) F; D. n
  NVIC_Init(&NVIC_InitStructure);2 i) I6 u' Z( P0 v7 F) u4 q; N
}1 I. R3 a1 c6 j; E. O7 f
void TIM2_Configuration(void)6 H/ `9 q) o. I7 t$ i  v% P
{ ' o1 ^2 _; ^/ P
  TIM_SetCounter( TIM2, 0x0000);" M8 R7 P0 i; h
  TIM_ClearFlag(TIM2, TIM_FLAG_Update);        /*清除更新标志位*/   i, s( J2 d: B2 {
  TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update); //清除TIM2等待中断更新中断标志位
  m1 r+ B; d% l  A+ S  TIM_ARRPreloadConfig(TIM2, ENABLE);        /*预装载寄存器的内容被立即传送到影子寄存器 */
- F' B! X" N! _0 B8 E! m  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); //使能TIM2的更新    8 w) X, @. w7 U% ~
  . C2 w& n' U& d4 s
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
( v) M5 X( v& |8 K( R, o  TIM_TimeBaseStructure.TIM_Period = 120;        //设定的最大计数值,计数值到则产生一次中断! F) Q3 r: e) J3 ]1 A
  TIM_TimeBaseStructure.TIM_Prescaler = 30;     //分频
- v% b( N  Y$ v! @  TIM_TimeBaseStructure.TIM_ClockDivision = 0;     // 时钟分割
  ^; {6 R) s- v$ `: c% F0 l  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //计数方向向上计数' H5 U  p8 c: D- U6 A/ H6 q
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
% z! Z2 ]8 k! w% F* H2 h  TIM_Cmd(TIM2, ENABLE);       //TIM2 enable counter
9 c; N3 x: ]0 h' l}
1 Z7 d: S# b2 K( M9 yvoid RCC_Configuration(void)
( Y4 _3 T/ c/ T/ O6 F{
+ i/ y  c; I( U0 s  v) f  Q  , b* X& E' ^9 |7 ^5 t7 U# O4 |( q
         
- r6 i* |7 R, }6 f( O8 C  RCC_DeInit();  U( x) R6 \5 x8 r
  RCC_HSICmd(ENABLE);
1 p" ~: P4 W& l" M$ e6 y& f* J3 H" E  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC
  k( I; ]8 H3 \1 [4 ~                                | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE,ENABLE); & p% q, _' A5 f3 ?( n  j
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //在开启时钟里一定要打开TIM2的时钟
- Q2 r0 b2 L$ ]; y( q* e, r}
jennyzhaojie 回答时间:2014-4-9 09:41:47

RE:STM32步进电机程序

学习一下,如果介绍再详细些就更好了.
bevingeng 回答时间:2014-4-9 10:16:20

RE:STM32步进电机程序

正在写这方面的程序,look
生命即燃烧 回答时间:2014-4-10 21:06:38

回复:STM32步进电机程序

正在学习中,看看
蓝雪001 回答时间:2014-4-11 11:09:21

RE:STM32步进电机程序

RE:STM32步进电机程序0 q! g0 g0 x8 s) ?5 A2 a4 n; c6 }3 d
xiexiela

所属标签

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