The driver chip ULN2003 consists of 7 groups of Darlington circuits, each of which is connected in series with a 2.7K base resistor. Under the working voltage of 5V, it can be directly connected to TTL and CMOS circuits, and can directly process data that originally required standard logic buffers to process.
ULN2003 has high operating voltage, large operating current, sink current up to 500mA, and can withstand a voltage of 50V in the off state.
28BYJ-48 is a 4-phase 5-wire reduction stepper motor, it has 5 leads, VCC is connected to the center tap wire of the motor (usually red), and the other 4 are connected to the motor's A, B, C, and D phases. The motor has a diameter of 28mm, voltage: 5V, step angle: 5.625 x 1/64, and reduction ratio: 1/64.
Figure 2 Internal type and signal driving sequence
To control the rotation of the stepper motor, the pin connection relationship between it and the development board is as follows:
MA:PC7
MB:PE14
MC:PE12
MD:PC4
To output high and low levels, the pins are defined as:
#define MAH GPIO_SetPins(GPIO_PORT_C, GPIO_PIN_07)
#define MAL GPIO_ResetPins(GPIO_PORT_C, GPIO_PIN_07)
#define MBH GPIO_SetPins(GPIO_PORT_E, GPIO_PIN_14)
#define MBL GPIO_ResetPins(GPIO_PORT_E, GPIO_PIN_14)
#define MCH GPIO_SetPins(GPIO_PORT_E, GPIO_PIN_12)
#define MCL GPIO_ResetPins(GPIO_PORT_E, GPIO_PIN_12)
#define MDH GPIO_SetPins(GPIO_PORT_C, GPIO_PIN_04)
#define MDL GPIO_ResetPins(GPIO_PORT_C, GPIO_PIN_04)
The configuration function for the used pins is:
void Init_BJDJ(void)
{
stc_gpio_init_t stcGpioInit;
(void)GPIO_StructInit(&stcGpioInit);
stcGpioInit.u16PinState = PIN_STAT_RST;
stcGpioInit.u16PinDir = PIN_DIR_OUT;
(void)GPIO_Init(GPIO_PORT_C, GPIO_PIN_04, &stcGpioInit);
(void)GPIO_Init(GPIO_PORT_C, GPIO_PIN_07, &stcGpioInit);
(void)GPIO_Init(GPIO_PORT_E, GPIO_PIN_12, &stcGpioInit);
(void)GPIO_Init(GPIO_PORT_E, GPIO_PIN_14, &stcGpioInit);
}
The main program for testing the forward and reverse rotation of the stepper motor is:
int32_t main(void)
{
unsigned int X,Y;
LL_PERIPH_WE(LL_PERIPH_GPIO);
LED_Init();
Init_BJDJ();
LL_PERIPH_WP(LL_PERIPH_GPIO);
DDL_DelayMS(100);
MAL;
MBL;
MCL;
MDL;
// 转动
for(X=0;X<192;X++)
{
for(Y=0;Y<8;Y++)
{
MDL;
MAH; //A
delay (n);
MBH; //AB
delay (n);
MAL; //B
delay (n);
MCH; //BC
delay (n);
MBL; //C
delay (n);
MDH; //CD
delay (n);
MCL; //D
delay (n);
MAH; //DA
delay (n);
}
}
DDL_DelayMS(100);
// 换向
for(X=0;X<192;X++)
{
for(Y=0;Y<8;Y++)
{
MDH;
MAH; //DA
delay (n);
MAL; //D
delay (n);
MCH; //CD
delay (n);
MDL; //C
delay (n);
MBH; //BC
delay (n);
MCL; //B
delay (n);
MAH; //AB
delay (n);
MBL; //A
delay (n);
}
}
// 停止
MAL;
MBL;
MCL;
MDL;
for (;;) {
LED_G_TOGGLE();
DDL_DelayMS(DLY_MS);
}
}
After the program is compiled and downloaded, its running effects are shown in Figures 3 to 5.
Figure 1 Rotation state 1
Figure 2 Rotation state 2
Figure 3 Rotation state 3
When in use, the speed can also be changed by adjusting the delay value.
In addition, when using the buttons on the development board, the direction of the motor can be controlled in real time by pressing the buttons.
Video Demonstration: