PIC microcontroller stepper motor

Publisher:CelestialLightLatest update time:2020-02-04 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Hello everyone, through the previous study, we have learned and become familiar with the use and learning methods of ICD2 simulation burner and enhanced PIC experiment board, and learned how to use single chip microcomputer to control light-emitting tube, relay, buzzer, button, digital tube, RS232 serial port and other resources, and realized the ease of use and learning of the learning board. After reading the examples in the previous issues, you must be very excited and have a sense of accomplishment when your experiment is successful! Now we will strike while the iron is hot and take another step forward to learn the working principle and use of stepper motors. This is the beginning of our use of single chip microcomputer to control mechanical movement.


A stepper motor 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 (step angle) in the set direction. By controlling the number of pulses to control the angular displacement, accurate positioning can be achieved; at the same time, the speed and acceleration of the motor can be controlled by controlling the pulse frequency to achieve the purpose of speed regulation; the direction of rotation of the stepper motor can be controlled by changing the power-on sequence of each phase.


Characteristics of stepper motors


1. The angular displacement of the stepper motor is strictly proportional to the input pulse. Therefore, it has no cumulative error and has good followability.


2. The stepper motor has fast dynamic response and is easy to start and stop, reverse and change speed.


3. The speed can be smoothly adjusted within a fairly wide range, and a large torque can still be obtained at low speed. Therefore, the load can generally be driven directly without a reduction device.


4. The stepper motor can only operate by being powered by a pulse power supply. It cannot directly use AC power supply and DC power supply.


So how do we control the rotation of the stepper motor? For a DC motor, we just need to add voltage to the two poles of the motor, and the motor will rotate immediately, but this is not the case with a stepper motor. It is a digital control method, which converts electrical pulse signals into angular displacement, that is, when a pulse signal is given, the stepper motor rotates an angle, so it is very suitable for the control of a single-chip microcomputer.


Generally, a complete stepper motor control system includes three parts: controller, driver, and motor. The block diagram is shown in Figure 1:


Figure 1 Stepper motor control system


Figure 1 Stepper motor control system


Now, we take the reactive stepper motor as an example to introduce its basic principles and application methods. The reactive stepper motor can achieve large torque output, and the step angle is generally 1.5 degrees. The rotor magnetic circuit of the reactive stepper motor is made of soft magnetic material, and the stator has multi-phase excitation windings, which use the change of magnetic poles to generate torque. The actual object of the commonly used small stepper motor is shown in Figure 2. This stepper motor can be directly connected to our enhanced PIC experiment board to complete the stepper motor control experiment.


Figure 2 Physical picture of stepper motor


Figure 2 Physical picture of stepper motor


Excitation method of stepper motor.


The excitation modes of stepper motors are generally divided into 1-phase excitation, 2-phase excitation, and 1-2-phase excitation.


When the 1-phase excitation is used, the stepper motor is energized in a cyclic manner, and only one phase is energized at a time. The magnetic field rotates one circle and needs to be changed phase 4 times, and the rotor rotates one pitch angle. Its energization method is the simplest and has the smallest torque. See Table 1 for the excitation method.


Table 1 1-phase excitation mode


Table 1 1-phase excitation mode


When two phases are excited, each time two phases are energized at the same time, the magnetic field needs to be switched 4 times for one rotation, and the rotor rotates one pitch angle. In the double three-beat working mode, the power-on sequence for the forward rotation of the stepper motor is: ; the power-on sequence for the reverse rotation is:


The advantages of the double triple-beat working mode are:


It can generate a larger torque and is not prone to losing steps. See Table 2 for the excitation method.


Table 2 2-phase excitation method


Table 2 2-phase excitation method

1-2 phase excitation is a method of alternating 1-phase excitation and 2-phase excitation. The magnetic field needs to be changed 8 times for one rotation, and the rotor rotates through a step angle, which is a half-step method. That is to say, the step angle of 1-2 phase excitation is half of the step angle of the first two methods, so the step accuracy is doubled. See Table 3 for 1-2 phase excitation method.


Table 3 1-2 phase excitation mode


Table 3 1-2 phase excitation mode


Stepper motor application drive circuit


There are two types of stepper motor drive circuits: unipolar DC drive and H-bridge drive. The small stepper motor in this example uses the simplest unipolar DC drive circuit. The purpose is to verify the use of stepper motors. In formal industrial control, it is generally more complicated. The simple drive circuit is shown in Figure 3.


Figure 3 Unipolar DC drive circuit for stepper motor


Figure 3 Unipolar DC drive circuit for stepper motor


In practical applications, there are usually more than one drive path. The discrete circuit shown in Figure 3 is large in size and the consistency of parameters of each path is difficult to guarantee. It is best to use a ready-made integrated circuit as a multi-path driver. Commonly used small stepper motor drive circuits can use ULN2003 or ULN2803. ULN2003 is used on our experimental board. ULN2003 is a series of high-voltage and high-current Darlington transistor array products with high current gain, high operating voltage, wide temperature range, strong load capacity, etc., and is suitable for various systems requiring high-speed and high-power drive.


ULN2003A consists of 7 groups of Darlington transistor arrays and corresponding resistor networks and clamping diode networks. In this example, only 4 groups are actually used. The internal structure of ULN2003 is shown in Figure 4, and the equivalent circuit diagram of Darlington transistor is shown in Figure 5.


Figure 4 ULN2003 internal structure diagram


Figure 4 ULN2003 internal structure diagram


Figure 5 Darlington transistor equivalent circuit diagram


Figure 5 Darlington transistor equivalent circuit diagram




The typical application circuit block diagram of the ULN2003A high-voltage and high-current Darlington transistor array circuit is shown in Figure 6. The clamping diode is used to protect the back electromotive force from breaking through the integrated circuit when the coil is turned on and off. It can be seen that the circuit is much simpler than discrete components after applying ULN2003.



Through the introduction of the principle in the previous article, we have a general understanding of the characteristics and working principles of stepper motors, but when we get a stepper motor, we still don’t know how to use it correctly. For example, what should we do if we want to control the motor to rotate forward, reverse, high-speed, or low-speed? To control the forward and reverse rotation of a stepper motor is not as simple as a DC motor. It is not as simple as adding a positive and negative power supply to both ends of the motor. Instead, it is controlled by outputting "forward and reverse" timing pulses with different rules. Now, let's take a look at how to control the forward and reverse rotation and rotation speed of a stepper motor. Through an example, I believe it will give you a perceptual understanding.


First, let's take a look at the stepper motor control circuit on the enhanced PIC experiment board, because we need to combine software and hardware to consider how to program. The circuit schematic of the stepper motor control part is shown in Figure 7. The RD0~RD3 of the PIC microcontroller is the motor pulse output pin, which drives the small stepper motor through the ULN2003 integrated chip. We just need to plug the plug of the stepper motor directly into the J3 socket of the board. Jumper J4 is the stepper motor intelligent power supply jumper designed for the experiment board, so that the experiment board can be applied to stepper motors with different working voltages. When the jumper jumps to the VCC end, the stepper motor is provided with VCC +5V power supply. The working voltage of the stepper motor used in our experiment is 5V, so we can set the jumper to the VCC end. If the user uses his own stepper motor voltage that is not 5V, then the jumper can be jumped to the VIN end, that is, the user's external power supply is provided to the stepper motor working voltage.



For the programming of the microcontroller software, we use MPLab IDE software for C language programming, which is our programming environment. At the same time, we can use the ICD2 simulation burner and the enhanced PIC experimental board to connect the program for simulation debugging and burning steps. We have already made detailed descriptions and introductions of the specific operation steps in previous issues, so we will not repeat them here. Readers can refer to previous articles or log in to our website directly to view the information. Now we can enter the program code for debugging. We create a new project in MPLabIDE software, add source code, and select the chip model and set the configuration bit. The chip model used in our experiment is PIC16F877A. The program code written is as follows:


/* Stepper motor demonstration program */


#include


#define key RB0


void delay(void)


{


int k;


for(k=0;k<2000;k++);


}




void main()


{


TRISD=0x00; //Set RD as output port


TRISB=0xFE;


// Set RB0 as output port, RB1~RB7 as input port


PORTD=0x00; // Initialize RD output low level


key=1; //Set the button to input state


while(1) // Main loop


{


if (key == 1) // If no key is pressed, the motor will rotate forward


{


PORTD=0xFC; //1100


delay();


PORTD=0xF6; //0110


delay();


PORTD=0xF3; //0011


delay();


PORTD=0xF9; //1001

[1] [2]
Reference address:PIC microcontroller stepper motor

Previous article:PIC microcontroller I2C bus
Next article:Temperature acquisition of PIC microcontroller

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号