步進電機是一種專門設計的電機,可按步進旋轉。步進電機的速度取決于施加在其上的電信號速率。不同的模式可以控制步進電機的方向和旋轉類型。主要有兩種類型的步進電機可供選擇,單極和雙極。單極更容易操作、控制,也更容易獲得。在本教程中,我們將步進電機與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
評論
查看更多