[STM32] 为啥我的步进电机不转呀

[复制链接]
7084|8
 楼主| 鞨谷歌由于该 发表于 2024-11-23 20:31 | 显示全部楼层 |阅读模式
以下是proteus仿真图,看起来电没从ULN2003输出的感觉

以下是主要的代码,挺简单的逻辑
  1. void step(int dir)
  2. {
  3.     if(dir == 0)    // 正转
  4.     {
  5.         GPIO_SetBits(GPIOB, IN1_PIN);
  6.         GPIO_ResetBits(GPIOB, IN2_PIN);
  7.         GPIO_ResetBits(GPIOB, IN3_PIN);
  8.         GPIO_ResetBits(GPIOB, IN4_PIN);
  9.         delay_ms(5);
  10.         
  11.         GPIO_ResetBits(GPIOB, IN1_PIN);
  12.         GPIO_SetBits(GPIOB, IN2_PIN);
  13.         GPIO_ResetBits(GPIOB, IN3_PIN);
  14.         GPIO_ResetBits(GPIOB, IN4_PIN);
  15.         delay_ms(5);
  16.         
  17.         GPIO_ResetBits(GPIOB, IN1_PIN);
  18.         GPIO_ResetBits(GPIOB, IN2_PIN);
  19.         GPIO_SetBits(GPIOB, IN3_PIN);
  20.         GPIO_ResetBits(GPIOB, IN4_PIN);
  21.         delay_ms(5);
  22.         
  23.         GPIO_ResetBits(GPIOB, IN1_PIN);
  24.         GPIO_ResetBits(GPIOB, IN2_PIN);
  25.         GPIO_ResetBits(GPIOB, IN3_PIN);
  26.         GPIO_SetBits(GPIOB, IN4_PIN);
  27.         delay_ms(5);
  28.     }
  29.     else if(dir == 1)   // 反转
  30.     {
  31.         GPIO_ResetBits(GPIOB, IN1_PIN);
  32.         GPIO_ResetBits(GPIOB, IN2_PIN);
  33.         GPIO_ResetBits(GPIOB, IN3_PIN);
  34.         GPIO_SetBits(GPIOB, IN4_PIN);
  35.         delay_ms(5);
  36.         
  37.         GPIO_ResetBits(GPIOB, IN1_PIN);
  38.         GPIO_ResetBits(GPIOB, IN2_PIN);
  39.         GPIO_SetBits(GPIOB, IN3_PIN);
  40.         GPIO_ResetBits(GPIOB, IN4_PIN);
  41.         delay_ms(5);

  42.         GPIO_ResetBits(GPIOB, IN1_PIN);
  43.         GPIO_SetBits(GPIOB, IN2_PIN);
  44.         GPIO_ResetBits(GPIOB, IN3_PIN);
  45.         GPIO_ResetBits(GPIOB, IN4_PIN);
  46.         delay_ms(5);

  47.         GPIO_SetBits(GPIOB, IN1_PIN);
  48.         GPIO_ResetBits(GPIOB, IN2_PIN);
  49.         GPIO_ResetBits(GPIOB, IN3_PIN);
  50.         GPIO_ResetBits(GPIOB, IN4_PIN);
  51.         delay_ms(5);

  52.     }

  53. }
  54. void StepMotor()
  55. {
  56.                                         SystemInit();
  57.                                         StepMotor_Init();
  58.                                         step(0);  // 正转
  59.                                         step(0);
  60.                                         step(0);
  61.                                         step(0);

  62.                                         delay_ms(500);

  63.                                         step(1);  // 反转
  64.                                         step(1);
  65.                                         step(1);
  66.                                         step(1);

  67.                                         delay_ms(500);
  68. }


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×

评论

xch
能不能听见电机动静?  发表于 2024-11-25 12:16
qintian0303 发表于 2024-11-24 09:03 | 显示全部楼层
供电非常重要的,有的步进电机是有供电需要的,例如5V、9V、12V/24V 等等
20062516 发表于 2024-11-25 11:23 | 显示全部楼层
没供电吧,驱动步进电机的电流哪里来的
xch 发表于 2024-11-25 12:06 | 显示全部楼层
电机内部啥电路怎么连接6根线
xch 发表于 2024-11-25 12:18 | 显示全部楼层
这几个电源符号接哪里去了?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
cooldog123pp 发表于 2024-11-25 13:46 | 显示全部楼层
proteus的 VCC和VDD都是要设置电压多少的,你就写VCCVDD系统也不知道你多少啊,改一下。

评论

解决了,忘了是啥问题了  发表于 2025-1-14 16:32
 楼主| 鞨谷歌由于该 发表于 2025-1-14 16:34 | 显示全部楼层
解决了,谢谢大家
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

6

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部