当前位置:网站首页>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
边栏推荐
- Installation of thingsboard, an open source IOT platform
- Talk about the design of red envelope activities in e-commerce system
- How to play when you travel to Bangkok for the first time? Please keep this money saving strategy
- 使用CLion编译OGLPG-9th-Edition源码
- [daily question] first day
- 横向越权与纵向越权[通俗易懂]
- M2dgr: slam data set of multi-source and multi scene ground robot (ICRA 2022)
- 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
- 以太网PHY层芯片LAN8720A简介
- GMapping代码解析[通俗易懂]
猜你喜欢
使用CLion编译OGLPG-9th-Edition源码
Deep learning mathematics foundation
How can retail enterprises open the second growth curve under the full link digital transformation
ICDE 2023|TKDE Poster Session(CFP)
Mysql高级篇学习总结7:Mysql数据结构-Hash索引、AVL树、B树、B+树的对比
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
开发固定资产管理系统,开发固定资产管理系统用什么语音
[daily question] first day
潇洒郎:彻底解决Markdown图片问题——无需上传图片——无需网络——转发给他人图片无缺失
Use cheat engine to modify money, life and stars in Kingdom rush
随机推荐
Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent
【测试开发】一文带你了解什么是软件测试
The difference between SLC, MLC, TLC and QLC NAND SSD: which is better?
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
Develop fixed asset management system, what voice is used to develop fixed asset management system
Kubernetes three open interfaces first sight
[test development] takes you to know what software testing is
Markdown basic grammar
日期工具类(不定时更新)
MySQL advanced learning summary 8: overview of InnoDB data storage structure page, internal structure of page, row format
Installation of thingsboard, an open source IOT platform
论文导读 | 关于将预训练语言模型作为知识库的分析与批评
juypter notebook 修改默认打开文件夹以及默认浏览器
How to enable the run dashboard function of idea
2022.7.1-----leetcode.241
预处理和预处理宏
电脑使用哪个录制视频软件比较好
R语言ggplot2可视化分面图(facet):gganimate包基于transition_time函数创建动态散点图动画(gif)
新加坡暑假旅遊攻略:一天玩轉新加坡聖淘沙島
数据降维——主成分分析