Teach you step by step how to use stepper motors (detailed explanation of stepper motors)

Description: While I’m at work fishing, I’ll write an operating guide on stepper motors, hehehehe. This is the third article in the "Hand-in-Hand" series . The response to the first two articles has been very good. Thank you for your love! This article will also follow the writing style of the previous two articles. The purpose is to help students who are new to hardware learn how to use stepper motors in the shortest possible time.

Note: If you have any questions, you are welcome to leave a message for discussion! You can also chat with me privately! Be sure to reply when you have time! Without further ado, let’s get started!


What is a stepper motor? What are its usage scenarios?

     Popular understanding of stepper motors

        A stepper motor can be understood as: it is a "small machine" that moves at a fixed pace, and the so-called "step, step" means step by step! . It is different from ordinary motors in that ordinary motors can continue to rotate, while stepper motors move according to a specific number of steps or angles. It can only move a certain distance or rotate a certain angle each time, and the movement is more like walking step by step at a fixed pace. This characteristic makes stepper motors very useful in scenarios that require precise control of position and speed, such as printers, robots, CNC machine tools, etc.

     Applicable scenarios (which projects can be used?)

        Stepper motors have the following three characteristics: One is precise positioning. Stepper motors can accurately control position and are suitable for applications that require precise control of position and speed. The second is Fixed Step, which moves in fixed steps, making it useful in applications that require deterministic movement. High Torque at Low Speed : Stepper motors excel at low speed and high torque, making them useful in scenarios that require high torque but not high speed rotation.

        So based on the above three characteristics, which projects can be used? Let me give you a few projects that I have used stepper motors in! Students can use their imagination hahaha...

        ① Curtain power source in smart home projects

        ② The power source of the switch controller in the smart lock project

        ③ The power source of the robotic arm joint of the library book-retrieval robot

     Common types of stepper motors

              Common stepper motors in laboratories: 28BYJ48 five-wire four-phase stepper motor

                

                As shown in the picture, the common laboratory " 28BYJ48 five-wire four-phase stepper motor " module looks like this. Do you see the two driver boards? It's just a blue one and a green one. Just choose one of these driver boards and use it. Students may have two questions about this! One is why does a stepper motor need a driver board? The second is what does the so-called "five wires and four phases" of a stepper motor mean?

        Question 1: Why does a stepper motor need a driver board?

        Answer: Control of a stepper motor requires activating coils in a specific sequence to produce rotation. The driver board acts as a controller, providing the correct current and sequence to activate the various coils of the stepper motor so that it operates as expected. The control of stepper motors requires precise current control and timing activation, and the driver board can provide this control, allowing the stepper motor to move accurately according to the set number of steps or angles. To explain in layman's terms, a stepper motor is a machine without a "brain". It requires a chip (ULN2003) to convert the electrical information sent by the microcontroller into a pulse signal that the stepper motor can "process" and process it accordingly.

       Question 2: What does "five lines and four phases" mean?

        Answer: Five lines and four phases refer to its number of lines and phases. In this 28BYJ48 stepper motor, there are five wires for connection, and the four phases mean that it has four sets of coils, and each coil can be controlled independently. It doesn’t matter if we don’t understand it now. I’ll explain it in detail later when the principles are explained.

              Common stepper motors in industry (only for understanding, not for introduction)

 1. In automobiles, stepper motors are widely used to control various mechanical components of automobiles, such as engine valves, braking systems, electric windows, sunroofs, etc.

2. If you want to know more, go explore it yourself. Saonian (manual dog head) will leave you a wonderful website.

wonderful website

How should stepper motors be used? (Use 51 chip and stm32 to control stepper motor)

I think through the above introduction, students have already had a preliminary understanding of the characteristics and appearance of stepper motors, so how to operate them through a microcontroller? (Here I will take a 32 control 28BYJ48 stepper motor engineering project as an example to tell you how to operate and give you a personal understanding to help you understand the stepper motor from a practical perspective)

Engineering code link: 28BYJ48 control engineering code

Code:

main function

int main(void)
{
	vu8 key = 0;
	uint8_t time = 0;
	delay_init(); //延时函数初始化
	LED_Init();	  //初始化与LED连接的硬件接口
	BEEP_Init();  //初始化蜂鸣器端口
	KEY_Init();	  //初始化与按键连接的硬件接口
	Step_Motor_GPIO_Init();
	
	LED0 = 0;
	BEEP = 0;
	
	while (1)
	{
		key = KEY_Scan(0); //得到键值
		if (key)
		{
			switch (key)
			{
				case WKUP_PRES: // 翻转LED1,电机正转半圈
					LED1 = !LED1;
					/*
						功能:转1/64圈
						步距角5.625 360/5.625=64 减速比1/64
						故64*64个脉冲转一圈
						n 圈数
						direction 方向 1正转 非1反转
						delay delay时长ms >= 2
					*/
					motor_circle(64, 1, 2);
					break;
				case KEY1_PRES: // 翻转LED1,电机正转1圈
					LED1 = !LED1;
					motor_circle(8, 1, 2);
					break;
				case KEY0_PRES: // 翻转LED1,电机反转1圈
					LED1 = !LED1;
					motor_circle(8, 0, 2);
					break;
			}
		}		
		time++;
		if(time % 100 == 0){
			LED0 = !LED0;
		}	
		delay_ms(10);
	}
}

motor_circle method:

/*
	功能:转1/64圈
	步距角5.625 360/5.625=64 减速比1/64
	故64*64个脉冲转一圈
	n 圈数
	direction 方向 1正转 非1反转
	delay delay时长ms >= 2
*/
void motor_circle(int n, int direction, int delay)
{
    int i, j;
    for(i = 0; i < n * 8; i++){
		for(j = 0; j < 4; j++){
			if(1 == direction){
				SetMotor(0x00);
				SetMotor(forward[j]);
			}
			else{
				SetMotor(0x00);
				SetMotor(reverse[j]);
            }
			
			delay_ms(delay > 2 ? delay : 2);
		}
    }
}

Configuration code: 

u8 forward[4] = {0x03,0x06,0x0c,0x09}; // 正转
u8 reverse[4]= {0x03,0x09,0x0c,0x06}; // 反转

//引脚初始化
void Step_Motor_GPIO_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_3|GPIO_Pin_2|GPIO_Pin_1;
    GPIO_Init(GPIOF, &GPIO_InitStructure);
}

//引脚映射
void SetMotor(unsigned char InputData)
{
	if(InputData == 0x03)
	{
		GPIO_SetBits(GPIOF,GPIO_Pin_1);
		GPIO_SetBits(GPIOF,GPIO_Pin_2);
		GPIO_ResetBits(GPIOF,GPIO_Pin_3);
		GPIO_ResetBits(GPIOF,GPIO_Pin_4);
	}
	else if(InputData == 0x06)
	{
		GPIO_ResetBits(GPIOF,GPIO_Pin_1);
		GPIO_SetBits(GPIOF,GPIO_Pin_2);
		GPIO_SetBits(GPIOF,GPIO_Pin_3);
		GPIO_ResetBits(GPIOF,GPIO_Pin_4);
	}
	else if(InputData == 0x09)
	{
		GPIO_SetBits(GPIOF,GPIO_Pin_1);
		GPIO_ResetBits(GPIOF,GPIO_Pin_2);
		GPIO_ResetBits(GPIOF,GPIO_Pin_3);
		GPIO_SetBits(GPIOF,GPIO_Pin_4);
	}
	else if(InputData == 0x0c)
	{	
		GPIO_ResetBits(GPIOF,GPIO_Pin_1);
		GPIO_ResetBits(GPIOF,GPIO_Pin_2);
		GPIO_SetBits(GPIOF,GPIO_Pin_3);
		GPIO_SetBits(GPIOF,GPIO_Pin_4);
	}
	else if(InputData == 0x00)
	{
		GPIO_ResetBits(GPIOF,GPIO_Pin_1);
		GPIO_ResetBits(GPIOF,GPIO_Pin_2);
		GPIO_ResetBits(GPIOF,GPIO_Pin_3);
		GPIO_ResetBits(GPIOF,GPIO_Pin_4);
	}
}

 Code description:

First of all, I would like to explain that I will not explain too much about the first two code blocks. I think students can understand them. And the configuration file is the focus of what I want to talk about!

The students’ first doubt should be: What are 0x03 (0011), 0x06 (0110), 0x0c (1100), and 0x09 (1001)? Let’s look at the picture first (I’m not good at writing, but I’ve tried my best to write it, so I’ll just look at it!)

Blind student! Have you found Huadian? Let me explain (if you don’t understand here, please slow down. At least you need to know that our code is written in a bi-phase excitation stepping method . You can study the principle later). The "0x03" here and so on are in hexadecimal. In computer language, we use GPIO_ResetBits to pull the pin potential low, and GPIO_SetBits to pull the pin potential high. When we loop through the forward/reverse array 64*64 times, we achieve a 360° rotation

Wiring (note that abcd is the pin port on the driver board)

How does a stepper motor work?

Confused or not? For students who have never been in contact with it, I suggest you practice it first, hahaha! What follows is the essence of this article ( quietly, I’m copying someone else’s ). You must read it carefully. I will help you understand and help you learn based on the original text. I hope that after reading it, all students will feel like "Sodarsne", hahaha!

The following principles are derived from: Principles


Concept: A stepper motor, also known as a pulse motor, is based on the most basic electromagnet principle. It is an electromagnet that can rotate freely. Its operating principle relies on changes in air gap magnetic conductance to generate electromagnetic torque. Generally, microcontrollers control stepper motors through software to better tap the potential of the motor. Under the condition of not overloading, the motor speed and stop position only depend on the frequency and quantity of the pulse signal; and the pulse of the stepper motor is proportional to the angle of the step rotation, and the frequency of the pulse is proportional to the step speed, so it can It controls the signal output very well from the source; and the stepper motor only has periodic errors, making it very simple to use stepper motors to control speed, position and other control fields. The disassembly diagram is as follows:

working principle 

Usually the rotor of a stepper motor is a permanent magnet. When current flows through the stator winding, the stator winding generates a vector magnetic field. The magnetic field will drive the rotor to rotate at a certain angle, so that the direction of the magnetic field of the rotor is consistent with the direction of the magnetic field of the stator. When the vector magnetic field of the stator rotates by an angle. The rotor also rotates step angle with this magnetic field. Each time an electrical pulse is input, the motor rotates at an angle and moves forward one step. The angular displacement it outputs is proportional to the number of input pulses, and the rotational speed is proportional to the pulse frequency. Change the order in which the windings are energized and the motor will reverse direction. Therefore, the rotation of the stepper motor can be controlled by controlling the number of pulses, frequency and the energization sequence of each phase winding of the motor. Cross-sectional screenshot of stepper motor:

Analysis of bipolar stepper motor driving principle ( 28BYJ48 is bipolar ): 

Single-phase excitation step: It can be understood that there is only one phase that generates magnetism each time power is supplied, either phase A or phase B.

The step sequence is as follows. In the first step: energize phase A, according to the electromagnet principle, magnetism is generated, and because opposite poles attract each other, the magnetic field fixes the rotor in the position of the first step; Step 2: When phase A is closed and phase B is energized , the rotor will rotate 90°; Step 3: Phase B is closed and phase A is energized, but the polarity is opposite to step 1, which prompts the rotor to rotate 90° again. In the fourth step: Phase A is closed, phase B is energized, and the polarity is opposite to that in step 2. Repeating this sequence causes the rotor to rotate clockwise in steps of 90°.

Bi-Phase Excitation Stepping: When switching, only one phase can be commutated at a time

The more commonly used stepper motor driving method is different from single-phase excitation in that the single-phase is fixed at the polarity of the winding facing the stator after energization. However, when dual-phase excitation is performed simultaneously, the rotor is fixed at the two windings. The polarity of the resistor is in the middle ; at this time, the power-on sequence becomes AB-phase power-on at the same time.

"Merge" incentive step-by-step method:

In the process of bi-phase excitation, you can also add a phase-off state when changing phases to produce a half-step phenomenon , which divides the entire step angle of the stepper motor into two, for example, a 90° The stepper motor will move 45° every half step, see the figure below for details.

Step sequence:

  1. Phase A is energized, phase B is not energized

  2. Phases A and B are all energized, and the currents are the same, producing the same magnetism.

  3. Phase B is powered on, phase A is powered off

  4. Phase B is energized, phase A is energized, and the currents are equal, producing the same magnetism.

  5. Phase A is powered on, phase B is powered off

  6. Phases A and B are all energized, and the currents are the same, producing the same magnetism.

  7. Phase B is powered on, phase A is powered off

  8. Phase B is energized, phase A is energized, and the currents are equal, producing the same magnetism.

       

Summary of terms: 

  • Number of phases: The number of pairs of excitation coils that produce magnetic fields of different opposite poles N and S. It can also be understood as the number of coil groups in a stepper motor. The step angle of a two-phase stepper motor is 1.8°, and the step angle of a three-phase stepper motor is 1.8°. The pitch angle is 1.5°. The more phases a stepper motor has, the smaller its step angle will be.

  • Number of beats: The number of pulses or conductive state required to complete a periodic change in the magnetic field is represented by n, or refers to the number of pulses required for the motor to rotate through a pitch angle. Taking a four-phase motor as an example, there is a four-phase four-beat operating mode, namely AB -BC-CD-DA-AB, the four-phase and eight-beat operation mode is A-AB-B-BC-C-CD-D-DA-A.

  • Step angle: The angle of motor rotation corresponding to a pulse signal. It can be simply understood as the angle driven by a pulse signal. It is written on the motor. Generally, the step angle of a 42 stepper motor is 1.8°.

  • Positioning torque: The locking torque of the motor rotor itself when the motor is not energized (caused by the harmonics of the magnetic field tooth shape and mechanical errors).

  • Static torque: The locking torque of the motor shaft when the motor does not rotate under the action of the rated static voltage. This torque is a measure of motor volume and has nothing to do with drive voltage, drive power supply, etc.

  • Step angle accuracy: the error between the theoretical value and the actual value of a step angle when the stepper motor rotates. Expressed as a percentage: error/step angle*100%.

  • Out-of-step: The number of steps when the motor is running is not equal to the theoretical number of steps. It can also be called lost steps, usually due to too large a load or too fast frequency.

  • Misalignment angle: The angle at which the axis of the rotor teeth deviates from the axis of the stator teeth. There must be a misalignment angle when the motor is running. The error caused by the misalignment angle cannot be solved by using subdivision drive.

  • Maximum no-load starting frequency: the maximum frequency that can be started directly without adding load.

  • Maximum no-load operating frequency: the maximum speed frequency of the motor without load.

  • Running torque characteristics: The dynamic torque of the motor depends on the average current when the motor is running (not the static current). The greater the average current, the greater the motor output torque, that is, the harder the frequency characteristics of the motor are.

  • Motor forward and reverse control: Change the forward and reverse rotation of the motor by changing the power-on sequence.

Popular Science: What are the other common motors?

I have used brushless DC motors to control drones; coding motors to make balancing cars; DC motors (ordinary motors) to make the power system of wireless charging cars, etc. I won’t list this anymore. I’ll talk to you again when I get the chance!

Guess you like

Origin blog.csdn.net/Uncoverlove/article/details/135425277