当前位置:网站首页>A4988驱动步进电机「建议收藏」
A4988驱动步进电机「建议收藏」
2022-07-02 18:10:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
A4988一般用arduino来驱动,我是用STM32F103驱动的。
首先推一个网页,https://www.pololu.com/product/1182,上面有比较详细和专业的说明,还有一个关于限制电流使细分更精确的视频讲解,总之,专业。然后推一个datasheet,https://www.pololu.com/file/0J450/a4988_DMOS_microstepping_driver_with_translator.pdf
我用的是
驱动比较好写,首先要弄清楚接线方式。
代码:
motor.c
//IO初始化
void MOTOR_Init(void)
{
RCC->APB2ENR|=1<<3;
GPIOB->CRH&=0xff000000;
GPIOB->CRH|=0x00333333;
}
//细分
// x==1 全步
// x==2 半步
// x==4 1/4步
// x==8 1/8步
// x==16 1/16步
void Step_Micr(u16 x)
{
switch(x)
{
case 1:Full_step;break;
case 2:Half_step;break;
case 4:Quarter_step;break;
case 8:Eighth_step;break;
case 16:Sixteenth_step;break;
default:break;
}
}
//参数
// dir:FALSE 正转TRUE反转
// period 周期
// step 脉冲
void Step_Control(u8 dir,u16 period,u32 steps)
{
u32 i;
for(i=0; i <= steps;i++)
{
DIR = dir;
STEP = 1;
delay_us(1);
STEP = 0;
delay_us(period);//periodԽС£¬×ªËÙÔ½¿ì£¬²»ÒªÐ¡ÓÚ1000
}
}
//此函数可抱死
// 0 抱死
// 1 正常
void Step_Enable()
{
ENABLE = 0;
}
motor.h
#define STEP PBout(8) //step
#define DIR PBout(9) //dir
#define MS1 PBout(10)//MS1
#define MS2 PBout(11)//MS2
#define MS3 PBout(12)//MS3
#define ENABLE PBout(13)//ENABLE
//细分宏定义
#define Full_step {MS1 = 0;MS2 = 0;MS3 = 0;}
#define Half_step {MS1 = 1;MS2 = 0;MS3 = 0;}
#define Quarter_step {MS1 = 0;MS2 = 1;MS3 = 0;}
#define Eighth_step {MS1 = 1;MS2 = 1;MS3 = 0;}
#define Sixteenth_step {MS1 = 1;MS2 = 1;MS3 = 1;}
void MOTOR_Init(void);
void Step_Micr(u16 x);
void Step_Enable(void);
void Step_Control(u8 dir,u16 period,u32 steps);
main.c
int main(void)
{
int i=0;
Stm32_Clock_Init(9);
delay_init(72);
MOTOR_Init();
Step_Micr(1);//1/2/4/8/16
for(i=0;i<10;i++)
{
Step_Control(FALSE,1600,200);//正转
delay_ms(1000);
Step_Control(TRUE,1600,200);//反转
delay_ms(1000);
}
Step_Enable();//抱死
while(1)
{
}
}实现全步状态下正转一圈,反转一圈,持续一会儿后抱死。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/148605.html原文链接:https://javaforall.cn
边栏推荐
- 日期工具类(不定时更新)
- Golang concurrent programming goroutine, channel, sync
- Tutoriel (5.0) 10. Dépannage * fortiedr * fortinet Network Security expert NSE 5
- Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
- 2022 compilation principle final examination recall Edition
- 9D电影是怎样的?(+维度空间常识)
- Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
- Golang并发编程——goroutine、channel、sync
- 2022 software engineering final exam recall Edition
- Compile oglpg-9th-edition source code with clion
猜你喜欢
![27: Chapter 3: develop Passport Service: 10: [registration / login] interface: after the registration / login is OK, save the user session information (uid, utoken) to redis and cookies; (one main poi](/img/b9/2066a13b160252114c2881007094f8.png)
27: Chapter 3: develop Passport Service: 10: [registration / login] interface: after the registration / login is OK, save the user session information (uid, utoken) to redis and cookies; (one main poi

Why should we build an enterprise fixed asset management system and how can enterprises strengthen fixed asset management

中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖

Have you stepped on the nine common pits in the e-commerce system?

电商系统中常见的 9 大坑,你踩过没?

【JVM调优实战100例】01——JVM的介绍与程序计数器

The difference between SLC, MLC, TLC and QLC NAND SSD: which is better?

Transformation of thinking consciousness is the key to the success or failure of digital transformation of construction enterprises

仿京东放大镜效果(pink老师版)

Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent
随机推荐
Learn the knowledge points of eight part essay ~ ~ 1
Compile oglpg-9th-edition source code with clion
STM32G0 USB DFU 升级校验出错-2
消息队列消息丢失和消息重复发送的处理策略
数据降维——主成分分析
云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统
新加坡暑假旅遊攻略:一天玩轉新加坡聖淘沙島
Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent
codeforces每日5题(均1700)-第四天
论文导读 | 机器学习在数据库基数估计中的应用
学习八股文的知识点~~1
How performance testing creates business value
使用xml文件打印mybaties-log插件的方式
R language ggplot2 visual Facet: gganimate package is based on Transition_ Time function to create dynamic scatter animation (GIF)
reduce--遍历元素计算 具体的计算公式需要传入 结合BigDecimal
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
R language uses Cox of epidisplay package Display function obtains the summary statistical information of Cox regression model (risk rate HR, adjusted risk rate and its confidence interval, P value of
R语言dplyr包rowwise函数、mutate函数计算dataframe数据中多个数据列在每行的最大值、并生成行最大值对应的数据列(row maximum)
Golang concurrent programming goroutine, channel, sync
《病人家属,请来一下》读书笔记