Protues simulation design of stepper motor controlled by 51 single chip microcomputer

I. Overview

1.1 Introduction to stepping motor

Stepper Motor (Stepper Motor) is a motor that converts electrical signals into mechanical motion, and is a motor dedicated to precision control. Generally, stepper motors run stably and have high precision, so they are often used in precision instruments, automation equipment, robots and other equipment that require high precision.

The stepper motor is mainly driven by a magnet, and its rotation is controlled by an angle, and it rotates in a stepping manner. The inside of the motor includes a magnet as a rotating part, and the stationary part includes a coil and a reset sensor. Current drive causes the magnet to slowly attract the coil. When the magnetic field reaches a certain strength, the magnet moves to the corresponding position of the electromagnetic coil. When the coil current disappears, the magnet stops at the position determined in the previous step. Therefore, the rotation angle and direction of the motor can be controlled by controlling the rapid change of the coil current when the current is added.

The advantages of stepper motors are mainly reflected in their accuracy, stability, reliability and cost. Stepper motors are usually divided into 1.8 degrees, 0.9 degrees, 0.72 degrees, 0.36 degrees, etc. according to the step distance. As a result, stepper motor rotation steps can be accurate to sub-resolution, making it useful in areas requiring fine control, such as electronics manufacturing, automation, and aerospace.

Stepper motors are used in a wide range of applications. It is widely used in equipment such as printing machinery, woodworking machine tools, robots and computer peripherals. Widely used in office automation equipment, digital copiers, digital cameras, laser printers, medical equipment, vending machines, etc. It is used as a carrier for digital devices such as external hard drives, CD-ROM, DVD-ROM drives, and scanners.

In general, the operation control of stepper motors is convenient and precise, and at the same time, quietness, low vibration, low heat and low energy consumption are all advantages of stepper motors. With the further development of stepper motors, the continuous improvement of sensor technology and design improvements, the technical level of stepper motors will also increase accordingly. At the same time, with the development trend of industrial automation, stepper motors will be more and more widely used in daily life.

1.2 Design requirements

As shown in the figure below, the material handling electromechanical device, position 1---position 8, the interval between each position is 5mm, the pulse equivalent of the stepping motor combined with the mechanical transmission mechanism is 2.5 microns/pulse, and the thickness of the material itself is 2mm. The initial height from the initial position to the first material is 150mm, the distance in the x-axis direction is 100mm, and the distance in the y-axis direction is 80mm.

The device is driven by stepper driver + stepper motor, and the materials at position 1-position 4 are transported to position 8 (stacked). The control accuracy requirements are medium and there are no special requirements.

2. Hardware Design

This design uses STC89C52 single-chip microcomputer as the system controller unit, uses LED lights to indicate the state of object handling , and drives the stepper motor to perform corresponding actions through the driver ULN2003 . The entire hardware part is mainly composed of the minimum system of single-chip microcomputer, stepper motor driver , stepper motor, keyboard module, and LED indicator module . The hardware block diagram is shown in Figure 2-1 below.

3. Software Design

3.1 Stepping motor control method

The 51 single-chip microcomputer controls the ULN2003 driver through the IO port to drive the stepping motor to realize the corresponding action. By changing the power sequence of the stepper motor, its direction of motion can be changed. The power-on sequence when the stepper motor is rotating forward is A-AB-B-BC-C-CD-D-DA, and the power-on sequence when it is in reverse rotation is A-AB-B-BC-C-CD-D-DA. In addition, the purpose of speed regulation can be achieved by changing the frequency of the energizing pulse of the stepping motor.

3.2 Necessary data calculation

The pulse equivalent of the stepper motor combined with the mechanical transmission mechanism is 2.5 microns/pulse, which means that every time a pulse is received, the stepper motor will move a distance of 2.5 microns. It is known that the distance between each object is 5mm=5000μm, then 5000/2.5=2000 pulses are required between each object. It is known that the thickness of the material itself is 2mm, the initial height from the initial position to the first material is 150mm, the distance in the x-axis direction is 100mm, and the distance in the y-axis direction is 80mm. Then from the initial position to the object one x-axis needs 100000/2.5=40000 pulses, y-axis needs 80000/2.5=32000 pulses, z-axis needs (150000-2000)/2.5*5=57200 pulses. An object with a height of 2mm needs 2000/2.5=800 pulses.

3.3 Programming ideas

Press the start button, and the robotic arm will transport the objects at positions 1, 2, 3, and 4 to No. 8 in sequence. For example, when transporting No. 1, the robotic arm will move to the top of No. 1, go down after reaching the position, and turn on the electromagnet after reaching the position to absorb Objects, go up, and then move to above position No. 8, disconnect the electromagnet, release the objects and return to the initial state, and carry the subsequent objects in the same way.

The pulse signal of the stepping driver is realized through the for cycle. Whether the robot arm is in place is judged by the current value of the for loop. If the loop value is added to the preset value or decreased to 0, it means that the robot arm is in place, and the current step ends and the next step is performed.

3.3 System software flow chart

This design mainly uses Keil software to write and debug programs, and the program language is written in C language with higher readability and portability. The flow chart of the system operation is shown in the figure below.

To achieve the above functional requirements, the software program block diagram of the system is shown in Figure 4-1 below. Firstly, system initialization is carried out, which includes external interrupt initialization configuration and LED indicator status initialization. Then judge whether the start button is pressed, if pressed, enter the main program loop, otherwise wait for the start button to be pressed. In the main program cycle system, the X, Y, and Z three-axis stepping motors perform the corresponding actions in order to carry each material. Use the for loop to realize the given pulse rotation of the stepper motor, and change its direction of motion by changing the power-on sequence of the stepper motor. The power-on sequence when the stepper motor is rotating forward is A-AB-B-BC-C-CD-D-DA, and the power-on sequence when it is in reverse rotation is A-AB-B-BC-C-CD-D-DA. In addition, the purpose of speed regulation can be achieved by changing the frequency of the energizing pulse of the stepping motor. Every time the material is moved to position 8, it is necessary to perform a reset action, return to the initial position, and then carry out the next material handling. After the four materials are transported, the program execution is completed once here. The flow chart of the overall software design is listed below, as shown in the figure below:

4. Simulation results

Press the start button to start transporting No. 1 material, at this time the white light is on, as shown in the figure below    

After the No. 1 material is transported, start to transport the No. 2 material. At this time, the green light is on, as shown in the figure below.

After the No. 2 material is transported, start to transport the No. 3 material. At this time, the blue light is on, as shown in the figure below.

After the No. 3 material is transported, start to transport the No. 4 material. At this time, the yellow light is on, as shown in Figure 5-5 below.

 5. Some program descriptions

void axis_for(long axis_f)  //沿X轴正方向前进给定脉冲
{
	unsigned char i=0;
	for(i=0;i<axis_f;i++)
	{
		P0=stepper[i%8];
		delay_var(var);
	}
}
void axis_neg(long axis_n)  //沿x轴负方向前进给定脉冲
{
	 unsigned char i=0;
	 for(i=axis_n;i>0;i--)
	 {
		 P0=stepper[i%8];
		 delay_var(var);
	 }
}

The above two sub-functions are the running programs of the X-axis stepping motor. The number of input pulses is a long integer, which corresponds to the pulses required by the X-axis stepping driver. The for loop corresponds to the generation of a given pulse. For example, the x-axis corresponds to the pulse output and needs to be changed Power-on array index value, every time a pulse is generated, the array index value needs to be increased by 1. After the array index value is added to 8, it means that the stepping motor completes a circle of rotation, and the index value continues to start from zero, and it goes back and forth in turn, and the Y and Z axes step The motor operation procedure is similar to that of the X axis.

void HandMaterials(void)
{
	//搬运第一个物料 
	led_w = 1;led_b = 0;led_g = 0;led_y = 0; //白灯亮
	MotorAccOrDec(40000,32000,57200); //从初始位置前往第一个物料位置取物料
	MotorAccOrDec(2000,6000,0); //从第一个物料位置前往第八个物料位置卸物料
	MotorAccOrDec(-42000,-38000,-57200); //从第八个物料位置回到初始位置
	
	//搬运第二个物料
	led_w = 0;led_b = 0;led_g = 1;led_y = 0;//蓝灯亮
	MotorAccOrDec(42000,32000,57200); //从初始位置前往第二个物料位置取物料
	MotorAccOrDec(0,6000,-800); //从第二个物料位置前往第八个物料位置卸物料
	MotorAccOrDec(-42000,-38000,-56400); //从第八个物料位置回到初始位置
	
	//搬运第三个物料
	led_w = 0;led_b = 1;led_g = 0;led_y = 0;//绿灯亮
	MotorAccOrDec(40000,34000,57200); //从初始位置前往第三个物料位置
	MotorAccOrDec(2000,4000,-1600); //从第二个物料位置前往第八个物料位置卸物料
	MotorAccOrDec(-42000,-38000,-55600); //从第八个物料位置回到初始位置
	
	//搬运第四个物料
	led_w = 0;led_b = 0;led_g = 0;led_y = 1;//黄灯亮
	MotorAccOrDec(42000,34000,57200); //从初始位置前往第四个物料位置
	MotorAccOrDec(0,4000,-2400); //从第四个物料位置前往第八个物料位置卸物料
	MotorAccOrDec(-42000,-38000,-54800); //从第八个物料位置回到初始位置
}

The above sub-function is the procedure for moving materials 1~4, and it takes 3 steps to move one material to position 8. Take the material handling No. 1 as an example. In the first step, by controlling the X, Y, and Z-axis stepping motors, the mechanical arm is controlled from the initial position to the No. 1 material position to pick up the material; the second step is at the No. 1 material position, Continue to control the X, Y, and Z-axis stepping motors from the No. 1 material position to the No. 8 material position to unload materials; the third step is to control the X, Y, and Z-axis stepping motors from the No. 8 material position to return to the initial position, so that Continue to move the next material.

It should be noted that, from the initial position to the material position to pick up the material, from the material position to the No. The number is different, still taking the first material as an example, MotorAccOrDec(40000,32000,57200) indicates that the X-axis stepper motor rotates 40000 pulses, the Y-axis stepper motor rotates 32000 pulses, and the X-axis stepper motor Rotate 572,000 pulses to reach the No. 1 material position, and from the original position to the No. 2 material position, the X-axis stepping motor rotates 42,000 pulses, the Y-axis stepping motor rotates 32,000 pulses, and the X-axis stepping motor rotates 572,000 pulses. Other situations are similar.

postscript

This design is a Protues simulation based on the actual object. The material handling pulse data is large, and the simulation takes a long time. If you want to get the simulation results completely, please modify the corresponding pulse number yourself. For simulation, program, and design reports, please see the following Baidu network disk link: https://pan.baidu.com/s/10PVMmP65qBv9TScfgYPc1A 
Extraction code: 26s5 

Guess you like

Origin blog.csdn.net/weixin_53402301/article/details/130737030