当前位置:网站首页>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
边栏推荐
- 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
- Tutoriel (5.0) 10. Dépannage * fortiedr * fortinet Network Security expert NSE 5
- 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
- Mini Golf Course: a good place for leisure and tourism in London
- 消息队列消息丢失和消息重复发送的处理策略
- Golang并发编程——goroutine、channel、sync
- 预处理和预处理宏
- How can retail enterprises open the second growth curve under the full link digital transformation
- 高级性能测试系列《24. 通过jdbc执行sql脚本》
- 2022 compilation principle final examination recall Edition
猜你喜欢

新手必看,点击两个按钮切换至不同的内容

How performance testing creates business value

yolov3 训练自己的数据集之生成train.txt

消息队列消息丢失和消息重复发送的处理策略

Markdown basic grammar

What is 9D movie like? (+ common sense of dimension space)

Learning summary of MySQL advanced 6: concept and understanding of index, detailed explanation of b+ tree generation process, comparison between MyISAM and InnoDB

Compile oglpg-9th-edition source code with clion

Stratégie touristique d'été de Singapour: un jour pour visiter l'île de San taosha à Singapour

How can retail enterprises open the second growth curve under the full link digital transformation
随机推荐
2022 software engineering final exam recall Edition
The difference between interceptor and filter
医院在线问诊源码 医院视频问诊源码 医院小程序源码
《病人家属,请来一下》读书笔记
2022.7.1-----leetcode.241
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
Installation of thingsboard, an open source IOT platform
数字滚动带动画
MySQL advanced learning summary 7: MySQL data structure - Comparison of hash index, AVL tree, B tree and b+ tree
2022 compilation principle final examination recall Edition
[test development] software testing - concept
【JVM调优实战100例】01——JVM的介绍与程序计数器
[0701] [paper reading] allowing data imbalance issue with perforated input during influence
How to delete the border of links in IE? [repeat] - how to remove borders around links in IE? [duplicate]
Have you stepped on the nine common pits in the e-commerce system?
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 網絡安全專家 NSE 5
Transformation of thinking consciousness is the key to the success or failure of digital transformation of construction enterprises
Tutorial (5.0) 09 Restful API * fortiedr * Fortinet network security expert NSE 5
以太网PHY层芯片LAN8720A简介
Why should we build an enterprise fixed asset management system and how can enterprises strengthen fixed asset management