Computer Digital

How to realize the positive and negative rotation of the stepper motor?

The stepper motor is a discrete value control motor that converts the electric pulse excitation signal into the corresponding angular displacement or linear displacement. This kind of motor moves one step every time an electric pulse is input, so it is also called a pulse motor.

A stepping motor is a micro motor that converts electrical pulse signals into angular displacement to control the rotation of the rotor. It is used as an actuator in an automatic control device. Every time a pulse signal is input, the stepping motor advances one step, so it is also called a pulse motor. Stepper motors are mostly used in peripheral equipment of digital computers, as well as devices such as printers, plotters, and disks. The driving power of the stepping motor is composed of a variable frequency pulse signal source, a pulse distributor and a pulse amplifier, so that the driving power supplies pulse current to the motor winding.

The operating performance of a stepping motor depends on the good cooperation between the motor and the driving power supply. The advantages of stepping motors are no cumulative error, simple structure, convenient use and maintenance, low manufacturing cost, and the ability of stepping motors to drive load inertia is large. It is suitable for small and medium-sized machine tools and places where speed accuracy is not high. The disadvantage is that the efficiency is low , high fever, sometimes “out of step”. Stepper motors are divided into three basic types: electromechanical, magnetoelectric and linear.

Electromechanical stepping motor The electromechanical stepping motor is composed of iron core, coil, gear mechanism and so on. When the solenoid coil is energized, it will generate magnetic force to push its iron core to move, and the output shaft will rotate an angle through the gear mechanism, and the output shaft will be kept at a new working position through the anti-rotation gear; when the coil is energized again, the shaft will rotate an angle again, Step by step motion.

Magnetoelectric stepping motor Magnetoelectric stepping motor has simple structure, high reliability, low price and wide application. There are mainly permanent magnet, reluctance and hybrid.

(1) Permanent magnet stepping motor.

The basic principle of the permanent magnet stepping motor is that the rotor has the magnetic poles of the permanent magnets, which generate an alternating polarity magnetic field in the air gap, and the stator is composed of four-phase windings (see figure). When the phase A winding is energized, the rotor will turn to the direction of the magnetic field determined by that phase winding. When phase A is de-energized and phase B winding is energized and excited, a new magnetic field direction is generated. At this time, the rotor rotates an angle and is located in the new magnetic field direction. The sequence of excited phases determines the direction of rotation of the rotor.

If the change of the stator excitation is too fast, the rotor will not be consistent with the change of the stator magnetic field direction, and the rotor will be out of step. The low starting frequency and running frequency are a disadvantage of permanent magnet stepper motors. However, the permanent magnet stepper motor consumes less power and has higher efficiency. In the early 1980s, a permanent disc stepping motor with a disc rotor appeared, which made the step angle and operating frequency reach the level of the reluctance stepping motor.

(2) Reluctance stepping motor.

The inner and outer surfaces of the stator and rotor cores are provided with similar cogs distributed according to a certain rule, and the change of the relative position of the stator and rotor core cogs causes the change of the reluctance of the magnetic circuit, thereby generating torque. The rotor core is made of silicon steel sheets or soft magnetic materials. When a certain phase of the stator is excited, the rotor will turn to the position where the magnetic resistance of the magnetic circuit is the smallest. When the other phase is excited and the rotor turns to another position to minimize the reluctance of the magnetic circuit, the motor stops. At this time, the rotor rotates through a step angle θb, that is, in the formula, N is the number of beats for the rotor to rotate through a tooth pitch; ZR is the number of rotor teeth. There are many structural forms of reluctance stepping motors. There are single-stage and multi-stage stator cores; radial and axial magnetic circuits; three-phase, four-phase, and five-phase winding phases. The step angle of reluctance stepping motor can be 1°~15°, or even smaller, the accuracy is easy to guarantee, the starting and running frequency is high, but the power consumption is large and the efficiency is low.

(3) Hybrid stepping motor.

Its stator and rotor core structure is similar to that of a reluctance stepping motor. The rotor has permanent magnets that generate a unipolar magnetic field in the air gap, and this magnetic field is also modulated by the cogging of the soft magnetic material on the rotor. The hybrid stepping motor has the advantages of both the permanent magnet stepping motor and the reluctance stepping motor. The motor step angle is small, the precision is high, the working frequency is high, and the power consumption is small and the efficiency is high.

Stepper motor forward and reverse control mode:

1. The stepper motor has four-phase windings A, B, C, and D. When one winding is energized, N-S poles are formed inside the motor to generate a magnetic field. When the energized phase changes, the magnetic field rotates. Under the action of the magnetic field, the rotor Will rotate, if the stepping motor works by the double four beat mode.

/2. The sequence of input pulses on A, B, C, and D four-phase windings is AB → BC → CD → DA → AB, and the stepper motor rotates clockwise, that is, forward rotation; if in A, B, C , D input pulse AB→DA→CD→BC→AB in turn on the four-phase winding; the stepper motor will rotate counterclockwise, that is, reverse. The internal data parameters of the motor are the initial ones, no need to modify them.

Results of the overall procedure:

(1) Turn forward one circle first, wait for one second and then reverse one circle. In this process, you can modify the program by yourself and remove it, that is, the front part of the while loop of the overall main function will only be executed once.

while(1)

{

(2) Press button 1, and the whole motor starts to rotate forward for N circles. When the detection button is pressed all the time, the whole motor continues to rotate forward. When other buttons are detected, immediately jump to the program corresponding to other buttons.

(3) Press button 2, opposite to button 1.

(4) Button 3 stops the whole motor from working.

}

Parts 2, 3, and 4 above are always cyclically scanned and detected.

#include

#include

unsigned char code z[]={0x02,0x06,0x04,0x0c,0x08,0x09,0x01,0x03//315,270,225…360(0)

};//eight beats

unsigned char code f[]={0x01,0x09,0x08,0x0c,0x04,0x06,0x02,0x03//45,90,145…360(0)

};

sbit K1 = P3^0;//Define the forward rotation button

sbit K2 = P3^1;//Define the reverse button

sbit K3 = P3^2;//Define the stop button

void zz(unsigned char n);

void fz(unsigned char n);

void delay();

void step();

void main()

{

unsigned char N = 1;//Because the data of one revolution is set, N is set here as the number of revolutions.

TMOD=0X10;

TL1=0XF0;

TH1=0XD8;

EA=0;

ET1=0;//The timer interrupt is not used here, only the timing function of the timer is used here.

zz(N);

delay();

fz(N);

while(1)

{

if(K1 == 0)

{

while(1)

{

P0 = 0xfe;

zz(N);

if(K3 == 0||K2==0) break;

}

}

else if(K2 == 0)

{

while(1)

{

P0 = 0xfd;

fz(N);

if(K3 == 0||K1==0) break;

}

}

else

{

P0 = 0xfb;

P1 = 0x03;

}

}

}

void zz(unsigned char n)//forward rotation

{

unsigned char i,j;

for(i=0;i

{

for(j=0;j<8;j++)//The entire for loop, rotates forward by one step angle, because the four-phase eight beats, so it is half a step angle, that is, half a step.

{

if(K3 == 0) break;

P1 = z[j];

step();

}

}

}

void fz(unsigned char n)//reverse

{

unsigned char i,j;

for(i=0;i

{

for(j=0;j<8;j++)

{

if(K3 == 0) break;

P1 = f[j];

step();

}

}

}

void delay()//definition 1s

{

unsigned char i,j,k;

_nop_();

i=8;

j=154;

k=122;

do

{

do

{

while(–k);

}while(–j);

}while(–i);

}

void step()//timer timing 10ms

{

TF1=0;

TR1=1;

while(TF1==0);

TR1=0;

TL1=0XF0;

TH1=0XD8;

}

1. The delay used in the program, according to your own habits, you can write the corresponding function delay, but due to the delay in the process of motor rotation, the timing in the for loop in my above is 10ms, this is based on It is adjusted according to the actual situation. In theory, the motor delay using proteus simulation is at least 1ms. If it is lower than 1ms, you will not see the ideal result of writing your own code.

2. The step angle is different, so if you want the motor to rotate a circle, the parameters for executing the zz or fz function must be different. Take my program above as an example.

Eight beats turn a cycle, turn 360 degrees, and the step angle is 90 degrees.

Then when the step angle is 45°, if you want to turn 360°, you need 16 beats.

Here you need to modify the program to experiment by yourself, here is only a reminder. If it exceeds 256 shots, then unsigned char is not enough for you to play, you need unsigned int.

A stepper motor driver is an actuator that converts electrical pulses into angular displacement. When the stepper driver receives a pulse signal, it drives the stepper motor to rotate a fixed angle (called “step angle”) in the set direction, and its rotation runs step by step at a fixed angle. The angular displacement can be controlled by controlling the number of pulses, so as to achieve the purpose of accurate positioning. Next, let me explain in detail how the stepper driver controls the direction and how the stepper driver sets the forward and reverse directions of the motor.

How to realize the positive and negative rotation of the stepper motor?

Pulse control, because the number of pulses is conducive to precise control. Therefore, the direction of the stepper motor is controlled by pulses.

How to control: Generally, high level controls one direction, and low level controls the other direction.

There are also two-way pulse control. That is, the high level of one pulse controls one direction, and the high level of the other pulse controls the other direction.

As long as the sequence of input pulses on the four-phase winding is controlled, the forward/reverse rotation of the motor can be controlled. (The speed can be controlled by controlling the delay.)

The direction level signal DIR is used to control the rotation direction of the stepper motor. When the end is high, the motor turns in one direction, and when the end is low, the motor turns in the other direction. Motor commutation must be performed after the motor is stopped, and the commutation signal must be sent after the last CP pulse in the previous direction and before the first CP pulse in the next direction.

If the controller (host) sends double pulses (such as positive and negative pulses) or the amplitude of the pulse signal does not match, you need to use a signal module to convert it into a 5v single pulse (pulse). Chinese plus directions)).

1. The input is a single pulse

The DIP switch of the signal module should be set to the “single pulse” position. If there is a pulse output, the motor will rotate. Changing the high level and low level of the direction signal can change the direction of rotation. See the signal module manual for specific timing.

2. The input is double pulse

The DIP switch of the signal module should be placed in the ? double mic: middle? position. Sending a positive pulse will cause the motor to spin in the forward direction, while sending a negative pulse will cause the motor to rotate in reverse. The positive pulse and negative pulse cannot be given at the same time, please refer to the signal module manual for the specific timing.

The direction of operation of the stepper motor is opposite to that required. How should I adjust? The technical engineer of Shanshe Motor proposed two ways to realize it:

One way is to change the direction signal of the control system.

Another way is to change the direction by adjusting the wiring of the stepper motor. The specific method is as follows:

For a two phase motor, just switch one of the motor wires to a stepper motor driver like A+ and A swap.

For a three-phase motor, one of the motor wires cannot be replaced, but two phases must be replaced in sequence, such as exchanging A+ and B+.

A- and B- are interchanged.