Application of FPGA in the position control of DC motor

In a DC motor control system, the controlled quantity is generally the speed of the motor, and the purpose of control is to keep the speed of the motor at the required fixed value. But in the actual production process, the performance of the motor driving the production machinery or other loads is not necessarily the speed, or it may cause the production machinery or its mechanism to produce a certain position change, then the required control amount is no longer the motor's The speed is the linear displacement of the control object, so the speed output of the motor needs to be converted into the displacement output of the motor. 1 Design of motor position control module

1.1 Method of DC motor position control

Here, using maxon DC motor, through the planetary gear box and magnetic encoder matched with it, the conversion from speed to displacement can be realized. Its working principle is as follows: When the motor rotates, the encoder starts to output feedback pulses, and the frequency of the feedback pulses is proportional to the speed of the motor, up to 20 kHz. Each time the motor shaft rotates, the encoder outputs 16 feedback pulses. Through calculation, each pulse represents a displacement of 0.006 14 mm generated by the load on the motor. In this way, the displacement to be controlled can be expressed by the number of feedback pulses, as the given value of the position control module in FPGA. When the motor rotates, the counter in FPGA will count and save the feedback pulses, and the position control module will keep reading Take the count value in the counter and compare it with the given value in the position control module. When they are equal, the position control module sends a stop signal to control the motor brake. After the motor stops moving, read the count value in the counter, compare it with the given value, and calculate the difference. If the difference is within the control accuracy range, then this control ends; if it is not within the range, the difference is used as the next control set value, and continue to control the motor movement until the required accuracy range is reached.

1.2 The composition of the position control module

The position control module is composed of 3 parts: the comparison module, the drive module and the delay module. The function of the comparison module is to compare the number of pulses fed back by the encoder with the given number of pulses, and when they are equal, a motor stop signal is given. The function of the drive module is to control the movement of the motor according to the input control signal. The function of the delay module is to prevent the loss of feedback pulses and ensure that the number of pulses feedback from the encoder is accurately read back. The following will focus on the specific implementation of each module.

1.2.1 Comparison module

data_in[15..O] is the given number of feedback pulses; EN is the motor work enable signal; inclk is the working clock; feedback[15..0] is the count value of the counter when the motor is running; stopinter is when the motor is stopped The internal transmission signal of the module; "O" means invalid, "1" means valid. The working principle of the comparison module is as follows: After the comparison module receives the given value, that is, the number of feedback pulses calculated according to the displacement to be controlled, is latched. Under the action of the working clock, the module will continuously check whether the EN signal is valid. If the EN signal is valid, the module will start to read the feedback count value and compare it with the given value; if it is equal, the module considers the movement of the load carried by the motor When the specified position is reached, the output stopinter signal is valid to control the motor brake; otherwise, the stopinter signal is invalid and the motor continues to move.

Suppose the given count value is 7. When the enable signal EN is valid, the module starts to read the value in port feedback[15..O] (the number of pulses fed back by the magnetic encoder when the motor is running), which is the same as the value given in data_in[15..0] Compare the number of pulses. When they are equal, it means that the load carried by the motor has moved to the specified position. At this time, the stopinter signal is valid, and the motor is controlled to brake and stop.

1.2.2 Drive module

derect[1..O] is the control input signal of the motor; EN is the motor work enable signal, "0" means invalid, "1" means valid; inclk is the working clock; stopinter is the internal transmission signal of the motor stop signal module; control_outA, control_outB are the output signals for controlling the motor. These two control signals are directly connected to the drive chip of the motor. The working principle of the drive module is as follows:

Under the action of the working clock, the drive module will continuously check whether the EN signal and the stopinter signal are valid. If: EN is valid and stopinter is invalid, the output of the module controi_outA, cont-orl_outB depends on the motor control input signal derect[1. .0], when derect[1..0] is "01", the output of control_outA is "0"; the output of control_outB is "1", indicating that the motor is controlled to reverse. When derect[1..0] is "10", the output of control_outA is "1"; the output of con-trol_outB is "O", indicating that the motor is controlled to rotate forward. Once the drive control module detects that the stop signal is valid, the outputs of control_outA and control_outB are both "O", indicating that the control motor brakes and stops. When both EN and stop signals are invalid, the output of control_outA and con-trol_outB are both "1", which means that no control is done on the motor.

When the EN and stopinter signals are both "0", the module's output control_outA and contorl_outB are both "1", and no control is performed on the motor. When the EN signal becomes "1", it means that the motor starts to move. The output control_outA of the module is "O" and Contorl_outB is "1", which is the same as the value "01" in direction [1..0]. turn. When the stopinter signal becomes "1", the module's output control_outA is "O"; contorl_outB is also "O", and the motor brakes and stops. When the EN signal is "1" and the stopinter signal is "0" again, the motor starts to move again, and the module's output control_outA is "1"; con-torl_outB is "0", and the value in direction[1..O] "10" is the same, at this time the motor reverses.

1.2.3 Delay module

EN is the delayed enable signal, which is the output signal stopinter of the counting comparison module; inclk is the working clock; stop is the output signal of the motor stop signal to the outside. The working principle of the delay module (as shown in Figure 5) is as follows: When the delay module detects the stopinter signal as "1", the counter in the module starts to work, and the counter clock is the working clock of the module at 10 kHz. After that, the module output signal is "1". When the delay module detects that the stopinter signal is "0", the counter in the module does not work, and the module output signal is "0".

When the motor brakes, due to the inertia, the motor will not stop immediately, and there will be a sliding process. During this process, the motor will still return feedback pulses through the magnetic encoder, but because the motor speed drops, the frequency of the feedback pulses is greatly increased. reduce. When the stopinter signal becomes "1", the motor starts to brake. If you immediately read the feedback pulse value on the feedback[15..O] port and calculate the position of the load on the motor, you will inevitably lose the coasting process. Feedback pulses in. This will cause the number of feedback pulses read back and the number of feedback pulses returned by the actual motor to be unequal, which seriously affects the control accuracy. Therefore, it is necessary to extend a period of time after the stopinter signal becomes "1" to ensure that the motor stops moving. , And then give the STOPTEST signal as an effective signal to read the feedback pulse value. At this time, it is accurate to calculate the actual position of the load with the feedback pulse value read back.

Through experiments, when the motor is running at the highest speed, the motor is braked, and the waveform of the feedback pulse is captured with a logic analyzer to find the period of time when the feedback pulse frequency starts to drop suddenly until the feedback pulse disappears, which is the required delay. Through repeated experiments, it is tested that this period of time is 30 ms, and the number of feedback pulses during this period is 20. Therefore, after converting the displacement to be controlled into the number of feedback pulses, subtracting 20 from this value as the set value of the comparison module can offset the 20 pulses added during the coasting process. In this way, the control of the motor can be achieved once, without re-adjustment. The simulation diagram of the delay module is shown in Figure 6.

2 Conclusion

Field Programmable Gate Array (FPGA) devices are small, fast, and highly integrated, and can use hardware circuits to implement algorithms. Using FPGA to control the motor can ensure the real-time and reliability of the control. As an effective digital control method, it will be widely accepted and used by people