当前位置:网站首页>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
- 高级性能测试系列《24. 通过jdbc执行sql脚本》
- The R language dplyr package rowwise function and mutate function calculate the maximum value of multiple data columns in each row in the dataframe data, and generate the data column (row maximum) cor
- Excel finds the same value in a column, deletes the row or replaces it with a blank value
- In pytorch function__ call__ And forward functions
- PHP-Parser羽毛球预约小程序开发require线上系统
- codeforces每日5题(均1700)-第四天
- 消息队列消息丢失和消息重复发送的处理策略
- MySQL advanced learning summary 8: overview of InnoDB data storage structure page, internal structure of page, row format
- PHP非对称加密方法私钥及公钥加密解密的方法
猜你喜欢
Looking for innocence in New York -- a beautiful day at the discovery center of Legoland, New Jersey
How to copy and paste interlaced in Excel
性能测试如何创造业务价值
ICDE 2023|TKDE Poster Session(CFP)
Yunna | why use the fixed asset management system and how to enable it
Markdown基础语法
思维意识转变是施工企业数字化转型成败的关键
[0701] [paper reading] allowing data imbalance issue with perforated input during influence
[0701] [论文阅读] Alleviating Data Imbalance Issue with Perturbed Input During Inference
Novice must see, click two buttons to switch to different content
随机推荐
R language uses lrtest function of epidisplay package to perform likelihood ratio test on multiple GLM models (logisti regression). Compare whether the performance of the two models is different, and
机器学习笔记 - 时间序列预测研究:法国香槟的月销量
Learn the knowledge points of eight part essay ~ ~ 1
仿京东放大镜效果(pink老师版)
Golang concurrent programming goroutine, channel, sync
R language ggplot2 visualization: gganimate package creates dynamic histogram animation (GIF) and uses transition_ The States function displays a histogram step by step along a given dimension in the
[fluent] dart data type (VaR data type | object data type)
Preprocessing and preprocessing macros
Singapore summer tourism strategy: play Singapore Sentosa Island in one day
Tutoriel (5.0) 10. Dépannage * fortiedr * fortinet Network Security expert NSE 5
全志A33使用主线U-Boot
日期工具类(不定时更新)
横向越权与纵向越权[通俗易懂]
STM32G0 USB DFU 升级校验出错-2
QT中的QPropertyAnimation使用和toast案列
[test development] software testing - concept
9D电影是怎样的?(+维度空间常识)
新手必看,点击两个按钮切换至不同的内容
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 網絡安全專家 NSE 5
数字滚动带动画