如何使用PIC微控制器旋转步进电机

步进电机是一种专门设计的电机,可按步进旋转。步进电机的速度取决于施加在其上的电信号速率。不同的模式可以控制步进电机的方向和旋转类型。主要有两种类型的步进电机可供选择,单极和双极。单极更容易操作、控制,也更容易获得。在本教程中,我们将步进电机与pic微控制器pic16f877a连接。
我们正在为这个项目使用28byj-48步进电机,价格便宜且易于获得。它是5v直流单极步进电机。我们还使用该电机提供的模块,该模块由uln2003步进电机驱动器ic组成。uln2003是达林顿对阵列,可用于驱动该电机,因为 pic 微控制器无法提供足够的电流来驱动。uln2003a能够以 600ma 的峰值电流驱动500ma的负载。
步进电机:
让我们从数据表中查看28byj-48 步进电机的规格。
如何旋转步进电机:
如果我们看到数据表,我们将看到引脚。
电机内部有两个中心抽头线圈可用。红线是两者的通用线,将连接到vcc或5v。
其他 4 根线粉红色、红色、黄色和蓝色将根据电信号控制旋转。此外,根据运动的不同,该电机可以使用 3 个步骤进行控制。全驱动模式、半驱动模式和波浪驱动模式。
步进电机的三种驱动模式:
全驱动:如果两个定子电磁铁同时通电,电机将以全扭矩运行,称为全驱动顺序模式。
步 蓝 粉红色 黄色 橙
1 1 1 0 0
2 0 1 1 0
3 0 0 1 1
4 1 0 0 1
半驱动:当一相和两相通电时,电机将以半驱动模式运行。它用于增加角度分辨率。缺点是这种运动产生的扭矩较小。
步 蓝 粉红色 黄色 橙
1 1 0 0 0
2 1 1 0 0
3 0 1 0 0
4 0 1 1 0
5 0 0 1 1
6 0 0 0 1
7 1 0 0 1
8 1 0 0 0
波浪驱动:在这种模式下,一个定子电磁铁被打开。它遵循与全驱动器模式相同的 4 个步骤。它消耗低功率和低扭矩。
步 蓝 粉红色 黄色 橙
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
uln2003 步进电机驱动器:
让我们了解由uln2003 ic组成的分线板。了解引脚输出很重要。
黄色部分用于连接电机,红色部分显示跳线,放置跳线很重要,因为它将为电机启用续流二极管保护。粉红色输入用于微控制器连接。
我们将以顺时针方向以全驱动模式旋转电机,并以逆时针方向以波浪驱动模式再次旋转电机。
必需组件
图16f877a
编程套件
面包板
20兆赫晶体
33pf 圆盘电容器 – 2 个
4.7k 电阻
伯格线和引脚
uln2003a 分线板和 28byj-48 步进电机。
要连接的其他电线
5v 电源单元或墙上适配器,额定电流为 500ma
电路图及说明
在电路图中,左侧显示 pic16f877a,右侧显示 uln2003a 连接。uln2003 和步进电机部分位于分线板内。
从分线板到微控制器单元的连接将是-
a.in1 =>引脚33
b.in2 => 引脚34
c.in3 =>引脚35
d.in4 => 引脚36
我连接了所有组件和您的硬件来旋转步进电机与pic微控制器已准备就绪。
如果您不熟悉 pic 微控制器,请按照我们的 pic 微控制器教程进行操作,说明 pic 微控制器入门。
代码说明
与往常一样,首先,我们需要在 pic 微控制器中设置配置位,然后从 void main 函数开始。
这些是微控制器单元和库头文件的配置位的宏。
#define _xtal_freq 200000000 //crystal frequency, used in delay
#define speed 1 // speed range 10 to 1  10 = lowest , 1 = highest
#define steps 250 // how much step it will take
#define clockwise 0 // clockwise direction macro
#define anti_clockwise 1 // anti clockwise direction macro
在第一行中,我们定义了延迟例程所需的晶体频率。其他宏用于定义与用户相关的选项。
如果您看到代码,则定义了三个函数,用于以顺时针和逆时针方向的三种模式驱动电机。以下是三个功能:
1.空隙full_drive(字符方向)
2.空隙half_drive(字符方向)
3.空隙wave_drive(字符方向)
在下面给出的完整代码中检查这些函数的定义:
现在在 void main 功能中,我们根据步骤使用全驱动模式顺时针驱动电机,几秒钟后,我们再次使用波浪驱动模式逆时针旋转电机。
void main(void)
{
system_init();   
while(1){
/* drive the motor in full drive mode clockwise */
for(int i=0;i
{
full_drive(clockwise);
}
ms_delay(1000);
/* drive the motor in wave drive mode anti-clockwise */
for(int i=0;i
{
wave_drive(anti_clockwise);
//full_drive(anti_clockwise);
}                                                              
ms_delay(1000);
}
}
这就是我们如何使用pic微控制器旋转步进电机。步进电机在数控机床、机器人和其他嵌入式应用中非常有用。
/*
* file:   main.c
* author: sourav gupta
* by:- circuitdigest.com
* created on may 10, 2018, 1:26 pm
* this program will drive a servo motor.
*/
// pic16f877a configuration bit settings
// 'c' source line config statements
// config
#pragma config fosc = hs        // oscillator selection bits (hs oscillator)
#pragma config wdte = off       // watchdog timer enable bit (wdt disabled)
#pragma config pwrte = off      // power-up timer enable bit (pwrt disabled)
#pragma config boren = on       // brown-out reset enable bit (bor enabled)
#pragma config lvp = off        // low-voltage (single-supply) in-circuit serial programming enable bit (rb3/pgm pin has pgm function; low-voltage programming enabled)
#pragma config cpd = off        // data eeprom memory code protection bit (data eeprom code protection off)
#pragma config wrt = off        // flash program memory write enable bits (write protection off; all program memory may be written to by eecon control)
#pragma config cp = off         // flash program memory code protection bit (code protection off)
#include
#include
/*
hardware related definition
*/
#define _xtal_freq 200000000 //crystal frequency, used in delay
#define speed 1 // speed range 10 to 1  10 = lowest , 1 = highest
#define steps 250 // how much step it will take
#define clockwise 0 // clockwise direction macro
#define anti_clockwise 1 // anti clockwise direction macro
/*
*application related function and definition
*/
void system_init (void); // this function will initialise the ports.
void full_drive (char direction); // this function will drive the motor in full drive mode
void half_drive (char direction); // this function will drive the motor in full drive mode
void wave_drive (char direction); // this function will drive the motor in full drive mode
void ms_delay(unsigned int val);
/*
* main function starts here
*/
void main(void)
{
system_init();
while(1){
/* drive the motor in full drive mode clockwise */
for(int i=0;i

大团队日趋“中庸化”,“颠覆性”创新还要看小团队?
郭光灿:中国量子计算技术正从实验室走向产业化
家用保险丝怎么换图解(三种保险丝的更换方法)
揭秘什么是电机绕组针式绕线技术
Maxim打造新款SerDes芯片组,将电缆及互联成本降低50%
如何使用PIC微控制器旋转步进电机
将引发移动、消费电子和联网设备的创新?ReRAM真正已经来临
HDMI接口的噪声抑制方法
Zip Slip 漏洞影响重要企业数千个项目
保护板规格参数含义是什么
2021年OPPO开发者大会:赋能开发者
ACM32 MCU安全特性概述
微弱电流信号放大芯片应用
基于Vivado设计的第三方仿真器版本说明
宏碁新蜂鸟Swift 3上架 售价5499元起
74ls148应用电路图大全(优先编码器\抢答器)
颠覆认知:智能手表竟然也能配对电动车遥控器
自动驾驶欲“抛弃”激光雷达?窄线宽半导体激光器来救场
MAX7219的典型应用及多片级联方法
2021年7月份芯片市场行情如何