In this paper, a motion controller based on STM32 is proposed. The hardware circuit design of the controller is analyzed and the algorithm of data sampling and interpolation used by the controller is briefly introduced.
The application in a simple experimental motion platform shows that the controller meets the design requirements. With the rapid development of science and technology, motion control technology plays an increasingly important role in industrial robots, automation equipment and other fields. At present, most of the motion controllers on the market use ARM/DSP FPGA architecture, which is more complex and expensive to develop.
In fact, most of the time, there is no strict requirement for the motion accuracy of the motion control system. In this case, a motion controller based on STM32 is proposed. Because of its low cost, the controller is widely used in simple experimental motion platform. The controller uses STM32F103x single chip computer as the core. The controller is designed with three axes and can control up to three motors.
It can realize the functions of point position, continuity and linkage. At the same time, the controller uses RS232 and 485 to communicate with the host computer, so as to get the control signal and send the running state of the controller. The controller has 12 inputs and 15 outputs, and the input and output are separated by optocoupler chips.
The motor interface unit of the controller uses differential output mode to output. The overall scheme is shown in Figure 1. Main control unit circuit design. Microcontroller STM32F103x with Cortex-M3 processing core. The processor is a 32-bit processor with 72 MHz core frequency and 1.25DMips/MHz processing capability. It has 16 programmable priority interrupts, 256K byte storage and 64K SRAM. It has two advanced timers and six basic timers. The controller uses the output comparison of the timer and the input capture to realize the output of the pulse PWM and the count of the encoder. Its I/O ports are all connected with two peripheral buses. At the same time, the microcontroller has rich peripherals, such as USART interface.
This paper mainly uses USART peripherals to communicate with the host computer. In the design of simulation interface, the main control circuit adopts SWM mode.
It only needs four wires to download and debug the program online. Compared with the traditional JTAG debugging, it can reduce the size of the controller while ensuring reliability. The main control unit circuit is shown in Figure 2. Design of other modules.
The controller uses DC24V input, because the power supply voltage of the main control chip is 3.3V. Therefore, DC24V to DC5V power supply isolation module is used.
The power supply module is 18V-36V wide voltage input, while achieving the isolation between the main board power supply and external power supply. The 5V voltage is output from the power module and then the 3.3V voltage used in STM32 is obtained by using AMS117 power chip to reduce the voltage. The input interface of the controller mainly receives the back-to-origin signal of the motion device and some position signals.
At present, most of the input signals are 24V. Because of the bit 3.3V voltage used in the controller chip, EL357 optocoupler isolation chip is used in the design to isolate the input signal from the internal signal. The output signal mainly controls some pneumatic coil devices. In order to improve the output capability, we use the optocoupler isolation chip to output with the transistor. The optocoupler isolates the output, and the transistor improves the driving capability of the output. The communication interface of the controller is 232 communication and 485 communication. In the circuit design, SP32332 chip is used to realize 232 communication, and sp485 chip is used to realize 485 communication.
232 communication is mainly used in the control of a single controller. And 485 communication is mainly used for the convenience of expansion. In some large machine devices, because the number of motors is relatively large, it requires multiple controllers to work at the same time to meet the control requirements. The high-speed communication isolation optocoupler and TVS protection chip are designed on the communication interface, which ensures the safety and reliability of communication. The driver interface unit of control and motor adopts differential output mode, and the four-wire differential driver chip AM26LS31 is used to output differential signal, which can convert single-ended output signal to differential signal for output, so as to improve the driving ability and anti-interference ability of the interface. At the same time, AM26LS32 is used to convert the input signal of the encoder into a single-ended signal. The difficulty in motion controller design is interpolation operation.
There are many interpolation algorithms, such as DDA algorithm. The controller adopts data sampling interpolation method. The method divides the motion trajectory into several small segments according to the sampling time. The length of the segment is the product of the sampling time speed and the sampling period.
The following is described by S curve. S acceleration and deceleration mode can be divided into acceleration, uniform acceleration, acceleration and deceleration, uniform speed, deceleration, uniform deceleration and deceleration stages. The corresponding time of each stage is t1, t2, thermostatic element t3, t4, t5, t6, t7. Generally, the starting and ending speed of a trajectory is zero, and the acceleration J is the fixed value. To ensure that the acceleration at the starting point and the end of the acceleration reduction section is zero, there is T1 = T2. To simplify the calculation, T3 = T1 = T2, T5 = T6 = T7. At the same time, in order to ensure the symmetry of acceleration and deceleration, there are Tm = T1 = T2 = T3 = T5 = T6 = T7 (Tm can be determined according to the given speed and acceleration). The upper computer transmits data to the controller through the serial port, converts it to the corresponding displacement and speed through the CPU, and then calculates the size of each period of time. The S-type acceleration and deceleration trajectory is generated by STM32. The basic timer of STM32 is selected as the generator of sampling period after division. The timer interrupts during sampling period. The acceleration AI of corresponding phase is calculated during interruption. Then the velocity iteration formula is used to calculate the velocity Vi of relative sampling period. The obtained Vi is converted into the corresponding frequency pulse value and written into the register of STM32 advanced timer. The PWM pulse is output after comparing with the timer. The register load value of the write timer is half of the pulse value. If expressed by Ni, there is Ni = fclk/2Vi, where fclk represents the reference clock of the basic timer. The STM32 motion controller studied in this paper realizes the basic functions of the motor, such as point motion, continuity and linkage. Pulse output frequency can reach 100 KHz. Data sampling interpolation method is used to solve the problem of low pulse output efficiency of traditional single chip microprocessors. Through the use of jacquard loom, the operation of jacquard loom can be controlled. Basically meet the design requirements, at the same time, the controller also needs to be improved, need to design analog input interface and analog output interface.