A method and system for implementing electrical precision control using FPGA
By combining an FPGA development board with a custom IP core, and using infrared and laser photodiodes for position feedback, a precise PWM signal is generated, solving the problems of cumulative error and calibration after power failure in stepper motor control, and achieving efficient and precise motor control.
Patent Information
- Application Number
- CN202110143667.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-02
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2041-02-02
AI Technical Summary
In the existing technology, the control of stepper motors has problems such as untimely operation, poor parallel capability, large scanning cycle, poor real-time performance, inability to achieve high-speed control, inability to eliminate accumulated errors, and inability to calibrate the motor angle after a sudden power failure.
Using an FPGA development board combined with a NiosII soft-core CPU and custom IP cores, position feedback is achieved through infrared and laser photodiodes, and a custom PWM IP core is used to generate precise PWM signals, enabling precise motor control and automatic calibration.
It achieves precise control of the motor, eliminates cumulative errors, and can automatically calibrate after the system is powered on, improving control accuracy and efficiency. It is suitable for multi-dimensional motor motion control.
Smart Images

Figure CN115616942B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the technical field of control of electric motor, and particularly relates to a method and system for realizing electric precise control by using FPGA. BACKGROUND
[0002] At present, in the electric control system, it is often required to make the controlled element move to a determined coordinate by a precise control scheme, and the smaller the expected deviation is, the better. As an execution element for moving objects, the stepping motor becomes the key in the mechatronic electric control system. The traditional motor control is controlled by CPU. Since the CPU uses a serial program to realize control, there are inevitable disadvantages of untimely operation and poor parallelism. It is more difficult to make the cumulative error in the motor operation process to be zero, so as to achieve the expected arbitrary absolute coordinate, which becomes the key problem solved by the present patent.
[0003] The traditional method for driving the stepping motor, such as the PLC driver, needs to be used with the corresponding power amplifier module when it is applied to the stepping motor control system. The PWM signal for controlling the motor is generated by the PLC control module, and then the corresponding driving signal is generated by the power amplifier to drive the stepping motor to rotate. Although the PLC software is relatively simple to realize, its scanning period is relatively large, and the real-time performance is poor. The speed of the stepping motor is determined by the pulse frequency, so the stepping motor is affected by the PLC scanning period and cannot realize high-speed control, and can only be applied to low-speed occasions.
[0004] During the operation of the stepping motor, movement oscillation caused by unstable speed will occur, and frequent movement for a long time is prone to out-of-step, thereby reducing the positioning control accuracy. In the prior art, the following methods are used to improve the stepping motor control accuracy:
[0005] ①Subdivision driving is adopted to reduce the vibration of the stepping motor and improve the accuracy of the stepping distance. This method belongs to the open-loop control method of the stepping motor. Since the stepping motor has high energy consumption, the control accuracy of the open-loop control system cannot be guaranteed, and other problems still exist. In addition, in order to improve the control effect, a large subdivision number needs to be selected, so that the control current is close to the sine current. At present, 32, 64 subdivision, and at most 256 subdivision are commonly used. However, a higher subdivision number requires a higher carrier frequency to ensure the running speed of the stepping motor. If more than one subdivision pulse number is skipped in each control pulse period, the higher subdivision will lose its significance, and the higher subdivision number will limit the running speed of the stepping motor.
[0006] ②Adopting closed-loop control system, position feedback correction is carried out. The position of the stepping motor is accurately fed back by using high-precision encoder, and the original open-loop control is replaced by closed-loop control. The position control precision is ensured by the encoder with higher precision instead of the step angle of the original stepping motor. Some domestic scholars gradually realize the importance of intelligent stepping motor in the control field, and begin to study the key technologies, but it is still in the research and experimental stage, and there is no mature closed-loop stepping motor product.
[0007] At present, there is no method to solve the problem that the system cannot record the stepping angle of the motor at the power-off moment after sudden power-off, so that the motor stepping angle cannot be calibrated after power-on. The current measures for motor closed-loop control, such as PID control, cannot solve the problem of determining the current initial coordinates after power-on, and cannot calibrate the motor during operation. On the other hand, the PID technology cannot eliminate the cumulative error in a long time (such as several years).
[0008] Through the above analysis, the problems and defects of the prior art are:
[0009] (1) The traditional motor control is controlled by CPU. Since the CPU uses serial programs to realize control, it is inevitable to have the disadvantages of untimely operation and poor parallelism. It is more difficult to reduce the cumulative error of the motor during operation to zero, so as to achieve the key problem of the desired arbitrary absolute coordinates solved by the present application.
[0010] (2) The scanning period of the traditional driving method of the stepping motor is relatively large, and the real-time performance is poor. The speed of the stepping motor is determined by the pulse frequency, so the stepping motor is affected by the scanning period of the PLC and cannot realize high-speed control, and can only be applied to low-speed occasions.
[0011] (3) The problems such as high energy consumption of the stepping motor and low control precision of the open-loop control system still exist in the subdivision driving method. Higher carrier frequency is required to ensure the running speed of the stepping motor if more than one subdivision pulse is skipped in each control pulse period. Higher subdivision will lose its significance, and higher subdivision will limit the running speed of the stepping motor.
[0012] (4) In the method of adopting closed-loop control system for position feedback correction, the position and current control method in the closed-loop control belongs to the key technology of the product. Some domestic scholars gradually realize the importance of intelligent stepping motor in the control field, and begin to study the key technologies, but it is still in the research and experimental stage, and there is no mature closed-loop stepping motor product.
[0013] (5) At present, in the precise control technology of stepper motor, the system cannot record the stepping angle of the motor at the power-off moment after sudden power-off, so that the motor stepping angle cannot be calibrated after power-on.
[0014] (6) The current measures for motor closed-loop control cannot solve the problem of determining the current initial coordinates after power-on, and also cannot calibrate the motor multiple times during operation. The PID technology cannot guarantee that the system eliminates the cumulative error after a long time (such as several years).
[0015] The difficulty of solving the above problems and defects is:
[0016] The above-mentioned control types have their applicable scenarios, such as PID algorithm. However, some scenarios can ignore some of the shortcomings and fully utilize the advantages. The implementation of the above control types requires the purchase of a large number of imported devices or the creation of new control technology. There is no ready-made solution for automatic calibration after power-on. The control method of the present application is controlled by C language and Verilog hardware description language, which greatly reduces the CPU pressure, and can take advantage of the advantages of the above algorithms and avoid disadvantages.
[0017] The significance of solving the above problems and defects is:
[0018] The present application is exactly through the comprehensive above-mentioned problems and defects, and correspondingly proposes a precise control method suitable for multiple scenes in electrical control. The control method of the present application can make the calibration of complex electrical control system more efficient. It fills the technical gap of the current electrical precise control field that cannot solve the start self-calibration after power-off, and makes the calibration method in the electrical precise control field more intelligent and convenient. SUMMARY
[0019] In view of the problems existing in the prior art, the present application provides a method and system for realizing electrical precise control by using FPGA.
[0020] The present application is realized as follows: a system for realizing electrical precise control by using FPGA, the system for realizing electrical precise control by using FPGA comprises:
[0021] FPGA development board, motor driving module, motor, motor controlled unit, infrared pair tube and its control circuit, liquid crystal screen, WIFI Bluetooth control end, and other power supply, wire components.
[0022] The FPGA development board realizes the control of the outside world by embedding NiosII soft core CPU and multiple self-defined IP cores.
[0023] Motor drive module, used to drive the motor to move, and the weak electrical signal of NiosII processor is converted into strong electrical signal which can drive the motor to rotate;
[0024] Infrared pair tube, installed on the motion path of the controlled object, the coordinate of each infrared pair tube on the motion path is fixed and known, and the coordinate is input to the NiosII processor for subsequent control and processing;
[0025] Liquid crystal screen, used to display various operating states of the system.
[0026] Further, the FPGA includes a plurality of exposed pins, which are connected to other components by wires to realize the control function of other components.
[0027] Further, the system for realizing electrical precise control by using FPGA takes FPGA as the main control MCU, and a NiosII soft core CPU system is constructed by using the logic resources of FPGA, the system includes self-defined PWM IP core, SDRAM IP core, EPCS IP core, serial port IP core and display IP core, the IP cores are connected with the NiosII processor through the avalon bus and respond to the control of the CPU.
[0028] SDRAM IP core, used to convert the external hardware nonlinear SDRAM into linear so that the FPGA can read;
[0029] EPSC IP core, which enables the FPGA to successfully download programs, and the FPGA configuration data and NiosII programs are stored in EPCS;
[0030] The serial port IP core and the display IP core are directly called from the library and hung on the avalon bus, and the serial port communication between Bluetooth and CPU and the communication between liquid crystal display and CPU are realized through the two.
[0031] Further, the system for realizing electrical precise control by using FPGA further includes PWM core structure,
[0032] The self-defined motor pulse generation IP core has irq interrupt and pwm_out output interface, and a frequency greater than 10M pwm_clk is generated by using phase-locked loop to ensure that the IP core can stably output PWM pulse to control the motor to rotate, the IP core has: pulse enable register ctrl_reg, expected pulse number register purpose_pulse_num, current cumulative pulse counter num_cnt, high and low level duration clock number registers n_high and n_low, PWM generator
[0033] In the IP core, an output-type pwm_out variable is defined to represent the generated PWM signal; two 32-bit n_high and n_low variables are defined, and the time duration of high and low levels is changed by assigning values to the two variables, and accordingly the duty cycle and frequency of pwm_out are changed; a 32-bit counter num_cnt is defined to accumulate the number of generated PWM pulses, and the driving clock of the register is pwm_out.
[0034] Further, the default duty cycle of the current PWM IP core is 50%, the frequency of the pwm wave is set to 1 kHz, and the pwm_go flag is set to zero;
[0035] ① The pulse enable register ctrl_reg is to make the whole IP core have a total control flag bit; the CPU configures a bit of the 32-bit register as a flag bit go through the avalon bus; when the system needs to drive the motor, the flag bit go=1 is configured, so that the IP core outputs PWM wave through the pwm_out port to drive the motor; when the pulse generation is completed or the system is on standby, go=0 is configured, at this time the system resets the IP core and the IP core will not generate PWM pulse, and the IP core will reset and wait for operation instruction;
[0036] ② The current cumulative pulse counter num_cnt is to accumulate the total number of current PWM pulses, and when each rising edge of pwm_out comes, a PWM pulse is generated, and the counter num_cnt is increased by 1. When the system needs to obtain the total number of steps accumulated at present, the counter can be directly accessed to read out data through the Avalon bus;
[0037] ③ The expected pulse register purpose_pulse_num is a register to store the number of pulses to be generated, and the CPU can read and write the value of the register through the avalon bus; by configuring this register and cooperating with the counter, the IP core can accurately generate any desired number, i.e. the number of pulses to be generated to reach the destination coordinate is set;
[0038] ④ The high and low level duration clock number registers n_high and n_low store the clock period of pwm_clk that the high and low levels are to be sustained. The CPU can write different values to the two registers through the avalon bus, so as to change the duty cycle and frequency of the PWM wave.
[0039] The PWM generator is used to generate a frequency and duty cycle adjustable pulse generator, and the CPU can change the parameters n_high and n_low in the IP core through the avalon bus to achieve the effect of frequency and duty cycle adjustment through the C language. Meanwhile, the PWM generator is controlled by the expected pulse register, the current cumulative pulse counter and the pulse enable register, and when the cumulative generated pulse is equal to the target pulse number, an interrupt irq signal is generated to transmit the PWM stop generation interrupt signal to the CPU, so that the pulse enable flag is set to zero and the PWM generation is stopped.
[0040] Further, the motor driving module can realize subdivision, and can rotate forward and reverse, and different subdivision coefficients drive the motor to rotate at different angular velocities.
[0041] Further, a shielding piece is installed on the controlled object and moves with the controlled object, if the shielding piece does not block the laser tube during movement, the low level is sent to the NiosII processor in the FPGA by the tube control circuit, and if the shielding piece blocks the laser tube, the high level is sent to the NiosII processor by the tube control circuit. The system is set to trigger the interrupt of the NiosII processor by the rising edge of the high level, and the value of the current position variable is modified to be equal to the position of the laser tube in the interrupt service program, so that the calibration is realized once.
[0042] Another object of the application is to provide a method for realizing electrical precision control by FPGA, which comprises the following steps:
[0043] Step one, the user sends instructions through the external WIFI and Bluetooth control end to the NiosII CPU through the Usart IP core in the form of serial communication for communication; the FPGA development board realizes the control of the outside world by using the embedded NiosII soft core CPU and multiple custom IP cores;
[0044] Step two, the CPU accesses the custom pulse generation IP core through the avalon bus, configures the corresponding register to generate the number and duty cycle adjustable pwm_out signal output to control the motor to move with a specific step number;
[0045] Step three, the motor is driven to move by the motor driving module, and the weak electric signal of the NiosII processor is converted into a strong electric signal capable of driving the motor to rotate;
[0046] Step four, when the system has multiple dimensional motors to be controlled, multiple custom pulse generation IP cores are added, each IP core controls one motor, and multiple IP cores control multiple motors;
[0047] Step five, install infrared pairs of tubes on the motion path of the controlled object, the coordinate of each infrared pairs of tubes on the motion path is fixed and known, and the coordinate is input to the NiosII processor for subsequent control and processing;
[0048] Step six, control the motor to rotate through the NiosII processor in the FPGA and the self-defined PWM IP core, and the motor drives the controlled unit to realize precise motion to complete different functions; at the same time, display various operating states of the system through the liquid crystal screen.
[0049] Further, in step three, the motor driving method further comprises:
[0050] The self-defined PWM IP core is used to generate a pulse with adjustable duty ratio and frequency to control a motor to drive an object to move in the X-axis direction, and one pulse drives the stepper motor to step an angle, which is converted into a small moving distance of the driven object. Similarly, another IP core is added to drive another motor to drive the same object to move in the Y-axis direction. In this way, multiple self-defined IP cores are used to control multiple motors to drive an object to move in multiple dimensions in horizontal or curved motion and other forms.
[0051] When the motor moves to a certain coordinate, the conversion factor between the number of motor rotations and the moving distance of the driven object is α, and the coordinate multiplied by α can be converted into the number of steps of the motor, that is, the number of pulses to be generated. Then the NiosII processor writes the target pulse number into the purpose_pulse_num register in the IP core. The num_cnt counter in the IP core will perform self-increment operation according to the forward and reverse rotation of the motor in the current axis, so as to record the number of pwm_out pulses provided by the IP core to the current motor in real time. When the value recorded by the num_cnt current cumulative pulse counter is equal to the value assigned to the variable, the IP core stops generating PWM pulses.
[0052] Further, in step five, each motor is installed with multiple infrared pairs of tubes on the running track of the part controlled by the motor, each infrared pairs of tubes has its own pairs of tube control circuit, and each controlled part is installed with a shielding piece that moves with the controlled object. If the shielding piece does not block the laser pairs of tubes during the movement, the pairs of tube control circuit sends a low level to the NiosII processor, and if the shielding piece blocks the laser pairs of tubes, the pairs of tube control circuit sends a high level to the NiosII processor. The NiosII processor can generate an interrupt in response to the rising edge of the high level of each laser pairs of tubes, and modify the value of the current position variable in the interrupt service program to equal the position where the laser pairs of tubes are installed, so as to realize one-time calibration.
[0053] Further, the variable and function defined by the control method are realized:
[0054] The purpose_pulse_num register representing the destination coordinate is defined in the Verilog hardware description language, which is used to store the number of PWM pulses that the IP core needs to generate after data conversion; num_cnt is the current cumulative pulse counter, which will be increased by 1 when the IP core generates a pwm_out signal to drive the motor to move further.
[0055] In C language, the infrared interrupt service function IRQ_Handler() is defined; the variable Position_Now representing the current coordinate position is defined, and the value of the variable is dynamically changed. There are two ways to change it: one is to periodically obtain the value of the cumulative pulse counter num_cnt in the IP core through a thread on the UCOS operating system, convert it into a coordinate position, and assign it to the variable after calculating the current absolute coordinate based on the coordinate position of the driven object when the motor starts moving; the second is when the driven object collides with a certain infrared pair, the infrared interrupt is entered, and the value of the variable in the interrupt service program will be changed to the coordinate of the pair. The variable purpose_position representing the destination coordinate position is defined; the function Move_To_absolute_Position(position) to drive the motor to move the driven object to a certain absolute coordinate is defined; the functions drive_motor_right(step) and drive_motor_left(step) to drive the motor to move in the left and right directions of a certain axis are defined.
[0056] Further, the control method for automatic calibration after power-on is realized, including:
[0057] After the system is powered on, it is automatically calibrated. Taking the movement of a motor-driven driven object in the X-axis direction as an example. At least three infrared pairs must be installed in the movable range of the X-axis direction driven by the motor: one at each end and one at the midpoint of the X-axis direction. Write the absolute coordinates of the three infrared pairs into the initialization program. After the system is powered off, the driven object will stop at a certain position. When the system is powered on, the motor drives the driven object to move to the right, and when the driven object moves in the X-axis direction and collides with a certain infrared pair, the system immediately jumps into the infrared interrupt IRQ_Handler(), which updates the global variable Position_Now representing the current position to the coordinate of the current pair in the interrupt service program. The system automatically calibrates and stops standby;
[0058] Similarly, adding a motor can drive the object to move along the Y-axis. The three laser pairs mentioned above are installed at the front, rear, and middle of the Y-axis. When the driven object touches one of the infrared pairs along the Y-axis, the system immediately jumps into an infrared interrupt and performs the same operation: updating the global variable Position_Now, which represents the current dimension, to the current position coordinates of the pair. This method can be used to complete automatic calibration in N dimensions.
[0059] Furthermore, the method for processing the infrared photodiode reaching a certain absolute coordinate during motor movement includes:
[0060] Taking a motor controlling a driven object to move upwards along the X-axis as an example, when the CPU controls the stepper motor to move towards a certain coordinate, it assigns the target coordinate to the global variable `purpose_position` in the C program, which represents the target coordinate. Through data conversion, the coordinate is transformed into the number of steps the motor needs to take. Nios II writes the converted value to the `purpose_pulse_num` register of the IP core via the Avalon bus. Subsequently, the CPU enables the IP core to start generating PWM waves. Each time a `pwm_out` signal is generated, `num_cnt` increments by 1, indicating that the motor has taken one step.
[0061] The `Move_To_absolute_Position(x_position)` function moves the driven object toward a specific absolute coordinate. This function works by subtracting the current coordinate (`Position_Now`) from the target coordinate (`purpose_position`). The result is the distance between the two coordinates. If the result is greater than zero, the `drive_motor_right(step)` function is called; otherwise, the `drive_motor_left(step)` function is called. The conversion factor between the number of motor rotations and the distance the driven object moves is α. Executing these two functions first multiplies the difference in coordinates by α, converting it into the number of steps the motor needs to take, which is the number of pulses required. The CPU then writes the converted phase difference step count back into the IP core's purpose_pulse_num register via the Avalon bus and resets the IP core. After the reset, num_cnt equals 0. Then, when Nios II sets go=1 via an instruction, num_cnt starts accumulating the number of pulses again. That is, each rising edge of pwm_out will drive num_cnt to increment by 1. The IP core will generate an accurate pwm_out pulse wave based on the updated target pulse count, thereby driving the motor to rotate left or right by the appropriate step size.
[0062] When a certain infrared pair tube is encountered in the movement process, the infrared interruption is entered, and the calibration in the movement is completed. By analogy, the above operation is repeatedly performed when the next infrared pair tube is blocked by the carried object. The calibration is continuously performed in the movement process, so that the motor is accurately stepped to the destination coordinate position of the X axis.
[0063] Similarly, an additional motor can be controlled to move the carried object in the Y axis, and each additional motor increases an IP core, and a variable representing the destination coordinate position y_purpose_position and the current coordinate position Y_Position_Now are correspondingly increased. After the motor calibration is completed, the motor continues to step to the destination coordinate in the Y axis. By this method, the motor can be controlled to accurately move to an absolute coordinate in N axes.
[0064] Further, in step six, various operating states of the system include: power supply condition, destination coordinate position, current coordinate, current stepping step number, calibration number and system running time information.
[0065] Another object of the present application is to provide a computer program product stored on a computer readable medium, comprising a computer readable program, which, when executed on an electronic device, provides a user input interface to implement the method of using FPGA to achieve electrical precision control.
[0066] Another object of the present application is to provide a computer readable storage medium, which stores instructions, when the instructions are run on a computer, the computer executes the method of using FPGA to achieve electrical precision control.
[0067] In combination with all the above technical solutions, the advantages and positive effects of the present application are: the method of using FPGA to achieve electrical precision control provided by the present application uses hardware description language and C language in FPGA to work simultaneously, cooperates with laser pair tubes and specific algorithms to enable the system to achieve a method of controlling the motor without cumulative error. This method can fully utilize the parallelism of hardware description language and the flexibility of C language to minimize the control deviation of absolute position. At the same time, the start-from-accurate function proposed by the system can effectively solve the situation of losing power-off position, and eliminates the tedious process of manual calibration, and has a wide range of applications in electrical automatic control systems.
[0068] The application utilizes the SOPC technology of FPGA to control the movement of a stepping motor and accurately controls the position of the stepping motor through a laser, and a new method is provided for precisely controlling the stepping motor. The FPGA is used to control the self-defined PWM pulse generation IP core to generate the number of pulses and the duty cycle, and a counter defined by a hardware description language is used to record the number of pulses for controlling the motor at present, and the number can be read at any time. The above problems are well solved, and on the one hand, the calibration can be automatically realized after the system is powered on, and the control object of the motor can be moved to the set coordinate position without cumulative error after the self-calibration is completed.
[0069] Meanwhile, the application can well solve the problem that the system cannot be automatically calibrated after the motor transmission device suddenly loses power and the system restarts, and the cumulative error caused by the long-time operation of the motor can be eliminated through the non-periodic calibration during the operation of the motor, so that the control field of the motor transmission device is more efficient and convenient, and a large amount of time and human resources can be saved.
[0070] Comparative technical effects or experimental effects.
[0071] Compared with the traditional control method, such as the PID algorithm, the closed-loop control and the PLC, these traditional control algorithms have obvious advantages and disadvantages. The present application provides a soft core NiosII CPU built by using the FPGA technology, and a plurality of multifunctional and multi-category IP cores are connected to build the system. Through the joint control method of the C language and the Verilog hardware description language, the load of the CPU can be greatly reduced, and the control efficiency and accuracy can be improved. Through the calibration method of the present application, the problems of the current coordinate being unable to be determined after the system is powered on and self-started and the non-periodic calibration during the operation can be conveniently and quickly solved, and the control accuracy in the current control field is effectively improved. BRIEF DESCRIPTION OF DRAWINGS
[0072] In order to more clearly illustrate the technical solutions of the embodiments of the application, the drawings needed to be used in the embodiments of the application will be briefly introduced as follows. Obviously, the drawings described below are only some embodiments of the application, and other drawings can be obtained by those skilled in the art without any creative effort on the basis of these drawings.
[0073] Figure 1 is the overall structure diagram of the system for realizing the electrical precise control provided by the embodiments of the application.
[0074] Figure 2 is the internal detailed structure diagram of the self-defined pulse generation IP core provided by the embodiments of the application.
[0075] Figure 3 is the overall block diagram of the intelligent drawing robot system provided by the embodiments of the application.
[0076] Figure 4 is a workflow diagram of the intelligent drawing robot system provided by the embodiment of the present application.
[0077] Figure 5 is a software overall program flow diagram of the intelligent drawing robot system provided by the embodiment of the present application.
[0078] Figure 6 is a method flow diagram for realizing electrical precision control by using FPGA provided by the embodiment of the present application. DETAILED DESCRIPTION
[0079] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application is further described in detail below with reference to embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and do not limit the present application.
[0080] In view of the problems in the prior art, the present application provides a method and system for realizing electrical precision control by using FPGA, which are described in detail below with reference to the accompanying drawings.
[0081] As shown in Figure 1 , the system for realizing electrical precision control by using FPGA provided by the embodiment of the present application comprises: an FPGA development board, a motor driving module, a motor, a motor controlled unit, an infrared pair tube and a control circuit thereof, a liquid crystal screen, a WIFI Bluetooth control end, and other power supply and wire components.
[0082] The FPGA development board realizes control over the outside world by embedding a NiosII soft core CPU and multiple self-defined IP cores.
[0083] The motor driving module is used to drive the motor to move and convert the weak electric signal of the NiosII processor into a strong electric signal capable of driving the motor to rotate.
[0084] The infrared pair tube is installed on the motion path of the controlled object, and the position coordinates of each infrared pair tube on the motion path are fixed and known, and the coordinates are input to the NiosII processor for subsequent control and processing.
[0085] The liquid crystal screen is used to display various running states of the system.
[0086] As shown in Figure 6 , the method for realizing electrical precision control by using FPGA provided by the embodiment of the present application comprises the following steps:
[0087] S101, the user sends an instruction through an external WIFI and a Bluetooth control terminal to the NiosII CPU in a serial communication mode through the Usart IP core to communicate; the FPGA development board uses the embedded NiosII soft core CPU and multiple self-defined IP cores to realize the control of the outside world;
[0088] S102, the CPU accesses the self-defined pulse generation IP core through an avalon bus, configures a corresponding register to generate a pwm_out signal output with adjustable number and duty cycle to control the motor to move with a specific number of steps;
[0089] S103, the motor is driven to move through the motor drive module, and a weak signal of the NiosII processor is converted into a strong signal capable of driving the motor to rotate;
[0090] S104, when the system has multiple dimensional motors to be controlled, multiple self-defined pulse generation IP cores are added, each IP core controls one motor, and multiple IP cores control multiple motors;
[0091] S105, an infrared pair tube is installed on a motion path of the controlled object, a position coordinate of each infrared pair tube on the motion path is fixed and known, and the coordinate is input to the NiosII processor for subsequent control and processing;
[0092] S106, the NiosII processor in the FPGA and the self-defined PWM IP core control the motor to rotate, the motor drives the controlled unit to realize precise movement, and different functions are completed; meanwhile, various running states of the system are displayed through the liquid crystal screen.
[0093] The application will be further described in combination with the embodiments.
[0094] Embodiment 1
[0095] The application is applied to any scene of moving a moving part in one-dimensional, two-dimensional, three-dimensional or higher-dimensional space by controlling the moving part by a motor, such as moving a belt around a circular arc by a motor, or writing by a pen by three motors, one motor controls the pen to move along the x-axis, one motor controls the pen to move along the y-axis, and the third motor controls the pen to move along the vertical direction, the cooperation of the three motors enables the pen to move forward and backward, left and right, and up and down, and completes the writing function. All such scenes of controlling the moving part by the motor to reach an accurate position to complete a certain function belong to the research object of the patent. The more accurate the motor moves, the smaller the deviation from the desired position, the better the control effect, and the better the corresponding control strategy. At the same time, in the motor control, it is also necessary to ensure that the cumulative movement error of the controlled moving part will not become larger and larger after the moving part runs for a long time, which is the second problem to be solved by the application. Finally, the application also solves the third problem. If the system suddenly loses power during operation, the current position cannot be determined and cannot be written into a specific register, so the current position cannot be obtained after the next power-on start, and the controlled object cannot be moved to a certain absolute position by controlling the motor to rotate a certain step length based on the current position. In order to solve the above three problems, the application proposes a method of using FPGA self-defined IP core and NiosII processor to cooperate with laser tube to control the motor, which can perfectly solve the above three problems.
[0096] The following will be described in detail from four aspects of system overall structure, FPGA internal structure, PWM core structure and control algorithm, wherein the system overall structure includes the preliminary description of the functions of each sub-module used by the system.
[0097] (1) System overall structure
[0098] The main functional modules of the system include an FPGA development board (or an FPGA minimum system board), a motor driving module, a motor, a motor controlled unit, a laser tube (or an infrared tube) and a control circuit thereof, a liquid crystal screen, a WIFI Bluetooth control end, and other power supplies, wires and the like. The system overall block diagram is as shown in Figure 1 .
[0099] The FPGA development board controls the outside world by embedding NiosII soft core CPU and multiple self-defined IP cores, and multiple exposed pins on the FPGA are connected to other components by wires to realize the control function of other components. The motor driving module is used to drive the motor to move, and converts the weak electric signal of the NiosII processor into a strong electric signal capable of driving the motor to rotate, wherein the motor driving module can realize subdivision, can rotate forward and can reverse, and different subdivision coefficients drive the motor to rotate at different angular velocities. The motor is the core controlled component, and the purpose of the application is to control the motor rotation by the NiosII processor in the FPGA and the self-defined PWM IP core, and the motor drives the controlled unit such as the belt, gear, bridge arm and other components to realize precise movement, thereby completing different functions. The infrared pair tube is installed on the motion path of the controlled object, and the position coordinates of each infrared pair tube on the motion path are fixed and known, and the coordinates are input to the NiosII processor for subsequent control and processing. A shielding piece is installed on the controlled object and moves with the controlled object, if the shielding piece does not block the laser pair tube during the movement, the pair tube control circuit sends a low level to the NiosII processor in the FPGA, and if the shielding piece blocks the laser pair tube, the pair tube control circuit sends a high level to the NiosII processor. The system is set to trigger the interrupt of the NiosII processor by the rising edge of the high level, and the value of the current position variable is modified in the interrupt service program to equal the installation position of the laser pair tube, thereby realizing one-time calibration.
[0100] The user sends instructions through the WIFI and Bluetooth control end to the NiosII CPU in the form of serial communication through the Usart IP core, accesses the self-defined pulse generation IP core through the Avalon bus, configures the corresponding register to generate a pwm_out signal with adjustable number and duty cycle to control the motor to move with a specific number of steps. When the system has multiple dimensional motors to be controlled, multiple self-defined pulse generation IP cores can be added, each IP core controls one motor, and multiple IP cores control multiple motors. Similarly, each motor is installed with multiple infrared pair tubes on the running track of the controlled component, each infrared pair tube has a corresponding pair tube control circuit, and each controlled component is installed with a shielding piece that moves with the controlled object. If the shielding piece does not block the laser pair tube during the movement, the pair tube control circuit sends a low level to the NiosII processor, and if the shielding piece blocks the laser pair tube, the pair tube control circuit sends a high level to the NiosII processor, and the NiosII processor can respond to the interrupt generated by the rising edge of each laser pair tube. The liquid crystal screen is used to display various running states of the system, such as power supply condition, target coordinate position, current coordinate, current stepping step, calibration times, system running time and other information.
[0101] (2) FPGA internal structure
[0102] By Figure 1 It can be clear that the system is mainly composed of FPGA as the main control MCU, using its rich logic resources to build a NiosII soft core CPU system, the system mainly includes custom PWM IP core, SDRAM IP core, EPCS IP core, serial IP core, display IP core, these IP cores are connected with NiosII processor through avalon bus, responding to the control of CPU.
[0103] SDRAM IP core, external hardware nonlinear SDRAM can be converted to linear so that FPGA can read. EPSC IP core, FPGA can successfully download programs, FPGA configuration data and NiosII program are stored in EPCS. Serial IP core and display IP core are directly called from the library and connected to the avalon bus, through which the serial communication between Bluetooth and CPU and the communication between liquid crystal display and CPU are realized.
[0104] The user sends instructions through the external WIFI and Bluetooth control end to the NiosII CPU through the serial communication IP core and the avalon bus connection, and the CPU also accesses the custom pulse PWM IP core through the avalon bus to configure the corresponding register to generate a number of adjustable pwm_out signal output.
[0105] (3) PWM core structure
[0106] The custom motor pulse generation IP core is used, which has irq interrupt and pwm_out output interface, and a frequency greater than 10M pwm_clk is generated by using phase-locked loop to ensure that the IP core can stably output PWM pulse to control the motor rotation; the IP core has: pulse enable register ctrl_reg, expected pulse number register purpose_pulse_num, current cumulative pulse counter num_cnt, high and low level duration clock number register n_high and n_low, interrupt register irq, PWM generator
[0107] An output type pwm_out variable is defined in the IP core to represent the generated PWM signal; two 32-bit n_high and n_low variables are defined, and the time of high and low level is changed by assigning values to these two variables, and the duty cycle and frequency of pwm_out are also changed accordingly; a 32-bit counter num_cnt is defined to accumulate the number of generated PWM pulses, and the driving clock of the register is pwm_out.
[0108] Further, the IP core of the current PWM duty cycle is set to 50% by default, the frequency of the pwm wave is set to 1 kHz, and the pwm_go flag is set to zero;
[0109] ①The pulse enable register ctrl_reg is used to enable the entire IP core to have a total control flag. The CPU configures a certain bit of the 32-bit register as a flag go through the avalon bus. When the system needs to drive the motor, the flag go is configured to 1, so that the IP core outputs the PWM wave through the pwm_out port to drive the motor. When the pulse generation is completed or the system is on standby, the flag go is configured to 0, at which time the system resets the IP core and the IP core will not generate PWM pulses. The IP core will be reset and wait for operation instructions;
[0110] ②The current cumulative pulse counter num_cnt is used to accumulate the total number of current PWM pulses. When each rising edge of pwm_out comes, a PWM pulse is generated, and the counter num_cnt is increased by 1. When the system needs to obtain the total number of current cumulative steps, the counter can be directly accessed to read the data through the Avalon bus;
[0111] ③The expected pulse register purpose_pulse_num is used to store the number of pulses to be generated. The CPU can read and write the value of the register through the avalon bus. By configuring this register and cooperating with the counter, the IP core can accurately generate any desired number, i.e. the number of pulses to be generated to reach the destination coordinate.
[0112] ④The high and low level duration clock number registers n_high and n_low store the clock cycles of pwm_clk that the high and low levels are to be sustained. The CPU can write different values to the two registers through the avalon bus, thereby changing the duty cycle and frequency of the PWM wave.
[0113] ⑤The PWM generator is used to generate a pulse generator with adjustable frequency and duty cycle. The CPU can change the parameters n_high and n_low in the IP core through the avalon bus to achieve the effect of adjustable frequency and duty cycle through C language. At the same time, it is controlled by the expected pulse register, the current cumulative pulse counter and the pulse enable register. When the cumulative number of pulses and the number of destination pulses are the same, an interrupt irq signal will be generated, which transmits the interrupt signal of PWM stop generation to the CPU, so that the pulse enable flag is set to zero and the PWM generation is stopped.
[0114] The application uses a self-defined motor pulse generation IP core, can stably output PWM pulse to control motor rotation, and has a pwm_out interface. The IP core has a pulse enable register, a desired pulse number register, a current cumulative pulse number register, and a counter. The internal detailed structure of the IP core is as shown in Figure 2
[0115] The specific hardware description language is:
[0116] reg pwm_out;
[0117] reg [31:0] n_high=32'd25000;
[0118] reg [31:0] n_low=32'd25000;
[0119] reg [31:0] num_cnt;
[0120] reg [31:0] pwm_cnt;
[0121] reg [31:0] pwm_go=32'd0;
[0122] The current IP core PWM duty cycle is set to 50% by default, the pwm wave frequency is set to 1kHz, and the pwm_go flag is set to zero.
[0123] ①The pulse enable register ctrl_reg is to make the whole IP core have a total control flag bit; the CPU configures a certain bit of the 32-bit register as a flag bit go through the avalon bus; when the system needs to drive the motor, the flag bit go=1 is configured, so that the IP core outputs PWM wave through the pwm_out port to drive the motor; when the pulse generation is completed or the system is on standby, go=0 is configured, at this time the system resets the IP core and the IP core will not generate PWM pulse, and the IP core will reset and wait for operation instruction;
[0124] ②The current cumulative pulse counter num_cnt is to accumulate the total number of current PWM pulses, when each rising edge of pwm_out comes, a PWM pulse is generated, and the counter num_cnt increases by 1. When the system needs to obtain the current cumulative total number of steps, the counter can be directly accessed through the Avalon bus to read out the data;
[0125] The specific hardware description language is:
[0126] always@(posedge clk)
[0127] begin
[0128] if(num_cnt>= n_high + n_low)
[0129] num_cnt=0;
[0130] else num_cnt = num_cnt +1;
[0131] end
[0132] ③The purpose_pulse_num register is a register for storing the number of pulses to be generated. The CPU can read and write the value of the register through the Avalon bus. By configuring the register and cooperating with the counter, the IP core can accurately generate any desired number of pulses, i.e., the number of pulses to be generated to reach the destination coordinate is set.
[0133] ④The n_high and n_low registers store the clock periods of the pwm_clk that the high and low levels are to be sustained. The CPU can write different values to the two registers through the Avalon bus, thereby changing the duty cycle and frequency of the PWM wave.
[0134] ⑤The PWM generator is a pulse generator with adjustable frequency and duty cycle. The CPU can change the parameters n_high and n_low in the IP core through the Avalon bus using C language, achieving the effect of adjustable frequency and duty cycle. At the same time, it is controlled by the expected pulse register, the current cumulative pulse counter, and the pulse enable register. When the cumulative number of pulses and the desired number of pulses are the same, an irq signal will be generated, sending an interrupt signal to the CPU to stop the PWM generation, thereby setting the pulse enable flag to zero and stopping the PWM generation.
[0135] The specific hardware description language is:
[0136] always@(posedge clk)
[0137] begin
[0138] if((pwm_cnt< n_high)&&(pwm_go[0]==1))
[0139] pwm_out<=1;
[0140] else pwm_out<=0;
[0141] end
[0142] Using SOPC technology, using C language and Verilog language joint programming has obvious advantages, the work of pulse generation to NiosII, so that the pulse generation speed is faster, the time is more accurate. C language can access the IP core hanging on the Avalon bus, while also can be other logic operation and through the C language to IP core send instructions, can write and read out the desired pulse number register and the current pulse counter in the IP core of the value, the current pulse generation number and the desired pulse number equal to stop generating pulse, through this kind of control mode can well reduce the CPU load.
[0143] (4) control algorithm description
[0144] ① motor drive part:
[0145] Through the self-defined PWM IP core to produce duty cycle and frequency adjustable pulse to control a motor to drive a certain object in the X axis movement, a pulse will drive the stepper motor step by step a degree, thus can be converted into a small moving distance of the driven object. Similarly, increase an IP core to drive another motor can machine drive the same object in the Y axis movement. By analogy, using multiple self-defined IP core to control multiple motors, can realize multiple motor drive a certain object in multiple dimensions to carry on the horizontal or curve movement and many other forms of movement.
[0146] When the motor to a certain position coordinate movement, the number of motor rotation and drive the moving distance between the conversion factor of the object is alpha, the coordinates multiplied by alpha can be converted into the number of motor step that is the number of pulses need to produce, after NiosII processor to the purpose of pulse_num register in the IP core write the purpose of pwm pulse number. The num_cnt counter in the IP core will be according to the current axis of the motor forward and reverse to carry on the self increment operation, thus real-time record IP core to the current motor provided how many pwm_out pulse. When the num_cnt current cumulative pulse counter recorded value and the value of the variable is equal, the IP core will stop generating PWM pulse.
[0147] ② infrared pair tube interrupt function part:
[0148] The system is running in the process, the body will carry the shielding piece shielding infrared pair tube at any time, infrared pair tube will produce level change, through the corresponding one input type GPIO port will level change that is shielding situation timely to convey to FPGA; through judging this IO port level change, NiosII processor will enter infrared interrupt service program IRQ_Handler, each infrared pair tube is configured with a separate interrupt line; when the system enters the infrared interrupt service function, first judge its trigger interrupt line, if it is X axis upward interrupt line, will rewrite the variable X_Position_Now representing the current X axis coordinate into the position of the pair tube, and clear the interrupt flag bit of the corresponding interrupt line; if it is judged that it is the Y axis upward interrupt line, then the variable Y_Position_Now representing the Y axis coordinate will be rewritten into the position of the pair tube, and the interrupt flag bit of the corresponding interrupt line will be cleared.
[0149] ③The control algorithm part of realizing power-on automatic calibration:
[0150] The system is powered on and automatically calibrated, taking two motors as an example. Ten infrared pairs are installed equidistantly in the movable range of the X axis direction and the Y axis direction driven by the motor, and two shielding pieces are installed for the driven body. After the system is powered off, the driven body will stop at a certain position. When the system is powered on, the motor first drives the driven body to move right on the X axis direction, and when the driven body moves and collides with a certain infrared pair tube, the system immediately jumps into the infrared interrupt IRQ_Handler(), and the global variable X_Position_Now representing the current position is updated to the position coordinate of the current pair tube in the interrupt service program. Then let the other motor drive the driven body to move right on the Y axis direction, and when the driven body moves and collides with a certain infrared pair tube, the system immediately jumps into the infrared interrupt IRQ_Handler(), and the global variable Y_Position_Now representing the current position is updated to the position coordinate of the current pair tube in the interrupt service program. Complete automatic calibration, and the system stops standby.
[0151] ④The control algorithm part of realizing reaching a certain destination coordinate:
[0152] The same two motors are used as an example to realize the method of accurately reaching a certain fixed coordinate and calibrating at any time in the process, including:
[0153] When the system receives the user set purpose coordinate, the purpose coordinate is respectively assigned to two global variables x_purpose_position and y_purpose_position; the coordinate is converted into the step number required by the motor through data conversion, and NiosII writes the converted value into the purpose_pulse_num register of the IP core through the avalon bus. Then the CPU enables the IP core to start generating the PWM wave, and the num_cnt is increased by 1 every time a pwm_out signal is generated, that is, the motor steps once.
[0154] The motor drives the driven object to move towards a certain absolute coordinate by calling Move_To_absolute_Position(x_position, y_position). The implementation principle of the function is that the X_Position_Now and Y_Position_Now variables representing the current coordinate are subtracted from the x_purpose_position and y_purpose_position representing the purpose coordinate, and the difference between the current coordinate and the purpose coordinate is obtained. If the obtained result is greater than zero, the drive_motor_right(step) function is continuously called; if it is less than zero, the drive_motor_left(step) function is called. By executing the function, the coordinate difference distance is converted into the step number required by the motor through data conversion, the CPU writes the converted difference step number into the purpose_pulse_num register of the IP core through the avalon bus again, and the IP core is reset. The num_cnt instruction is restarted to accumulate the generated pulse number, and the IP core generates the accurate pwm_out according to the updated purpose pulse number, so that the motor drives the driven object to continue moving according to the coordinate difference distance.
[0155] When a certain infrared pair tube is encountered in the movement process, the infrared interrupt is entered, and the calibration in the movement is completed. By analogy, when the next infrared pair tube is blocked by the driven object, the above operation is repeatedly executed. The calibration is continuously performed in the movement process, so that the motor accurately steps to the absolute position of the purpose coordinate.
[0156] Compared with the prior art, the present application has the following advantages and effects:
[0157] The application relates to the technical field of step motor control, and particularly relates to a novel method for eliminating accumulated errors caused by step motor out-of-step.
[0158] Key technical points of the application:
[0159] 1. An FPGA self-defined IP core is used to control the operation of a step motor, and the IP core comprises:
[0160] 1) A pwm_clk clock interface and a reset interface are comprised, the clock interface is used to coordinate internal registers and variables to work in a unified rhythm, and the reset interface is used to reset registers and sub-modules in the IP core.
[0161] 2) An output interface pwm_out is comprised and used to output a pulse signal for controlling the operation of the motor.
[0162] 3) An output interrupt line irq is comprised and used to transmit an interrupt signal generated by the PWM to a CPU.
[0163] 4) A purpose_pulse_num expected pulse number register is comprised and used to store a set expected pulse number.
[0164] 5) A current cumulative pulse counter num_cnt is used to accumulate the total number of current PWM pulses, when each rising edge of the pwm_out comes, a PWM pulse is generated, and the counter num_cnt is increased by 1. When the system needs to obtain the total number of current accumulations, the counter can be directly accessed through an Avalon bus to read data.
[0165] 2. The application proposes a method for recalibrating current coordinates as current_position by triggering an infrared interrupt, so that one calibration is completed.
[0166] Embodiment 2
[0167] The application is described below by taking a work of an intelligent drawing robot system as an example, and a system overall block diagram is shown in the figure. Figure 3
[0168] The main hardware part of the work includes seven parts: stepper motor, servo, track, writing pen, infrared pair tube, shielding piece, FPGA-based integrated board, etc. The overall function of the system is: by installing at least three infrared pair tubes on each axis of the stepper motor movement, each pair tube is installed at a certain interval, and the fixed coordinates are calibrated in the C program. When a certain object driven by the stepper motor passes through a certain infrared pair tube, i.e. a certain pair tube is shielded, the interrupt program is entered immediately, and the object movement coordinates are recalibrated as current_position, i.e. the position coordinates of the current pair tube to complete an automatic calibration. After that, the object will continue to move to the destination coordinates according to the recalibrated coordinates to draw or wait for the next instruction.
[0169] The specific working process of the system is shown in Figure 4
[0170] The specific working principle and specific working process of the system include:
[0171] 1. After the system is powered on, the origin is automatically calibrated, and the two stepper motors execute the initialization program to move the slide rails towards the X-axis and Y-axis directions. During the movement, the program records the absolute coordinates of the writing pen in real time through the operation of X_Position_N_Pulse_Now and Y_Position_N_Pulse_Now two variables. Ten infrared pair tubes are installed equidistantly below the X-axis direction slide rail and Y-axis direction slide rail within the movable range of the slide rail, and the absolute coordinates of the ten infrared pair tubes are written into the initialization program. In order to ensure that the slide rail accurately shields the infrared pair tube during the movement in the X-axis and Y-axis directions, two shielding pieces are installed. When the slide rail moves in the X-axis direction and encounters the first infrared pair tube, the system immediately jumps into the infrared interrupt IRQHandler(). In this interrupt service program, the X_Position_N_Pulse_Now global variable representing the current position is updated to zero, and the system identifies this position as the current X-axis direction origin position. Similarly, when the slide rail moves in the Y-axis direction and encounters the first infrared pair tube, the system immediately jumps into the infrared interrupt, and the Y_Position_N_Pulse_Now global variable representing the current Y-axis direction origin position is updated to zero. In this way, when the next infrared pair tube is encountered, the same operation is performed in the infrared interrupt program. In this way, after the system is powered on, the motor can be moved towards the X-axis and Y-axis by executing the initialization program. After the power-on automatic calibration program is executed, the system will stop standby.
[0172] 2、When the system receives the user set purpose coordinates, the purpose coordinates are respectively assigned to the two global variables x_pusle_purpose and y_pusle_purpose. When the motor is normally operated on the system powered on, the function Pen_Move_To_XY_Position(x_position, y_position) that controls the movement of the pen is repeatedly subtracted from the two global variables x_pusle_purpose and y_pusle_purpose representing the purpose coordinates and the two global variables X_Position_N_Pulse_Now and Y_Position_N_Pulse_Now representing the current position, and the distance between the current position and the purpose coordinates is repeatedly updated. When a shielding piece in a certain axial direction shields a certain infrared pair tube during operation, the system immediately enters the infrared interrupt, and the current coordinates of the X axial direction or the Y axial direction are re-assigned to zero. After the interrupt, the main program is entered again to continue the subtraction, and the stepper motor will continue to step according to the difference distance in the pen control program, and the current coordinate variable is updated to the absolute coordinate calibrated by the infrared pair tube, and then continues to change according to the running condition of the motor. In this way, when the next infrared pair tube is shielded by the shielding piece, the above operation is repeated. Finally, the two stepper motors cooperate to rotate, so that the slide rail moves in the X axial direction first and then moves in the Y axial direction, so that the pen reaches the X axial direction purpose coordinates first and then reaches the Y axial direction purpose coordinates.
[0173] 3、After the pen moves to the purpose coordinate position, the pen is lifted and drawn by executing the Pen_UP() function and the Pen_down() function. The main function in the lifting and falling pen function is the TIM_SetCompare() function that controls the rotation angle of the rudder to make the pen reach the lifting and falling effect. After completing the specified task, the pen is lifted, and the entire system is stationary and waits for the next instruction.
[0174] The overall program flow of the system software is shown in Figure 5 .
[0175] Proof part (specific examples / experiments / simulations / pharmacological analysis / positive experimental data that can prove the inventiveness of the invention, etc.)
[0176] Our control algorithm can make a single motor reciprocate along a line segment without deviation for a long time, and also can make a writing and drawing system composed of multiple motors work for a long time without cumulative error, and we can successfully draw a circle with a drawing pen. This has video evidence.
[0177] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware or any combination thereof. When implemented in whole or in part in the form of a computer program product, the computer program product comprises one or more computer instructions. When the computer program instructions are loaded or executed on a computer, all or part of the processes or functions described in the embodiments of the present application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another, for example, the computer instructions can be transferred from one website, computer, server or data center to another website, computer, server or data center through a wired (such as coaxial cable, optical fiber, digital subscriber line (DSL) or wireless (such as infrared, wireless, microwave, etc.)) way. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. integrated with one or more available media. The available media can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)) and the like.
[0178] The above is only a specific embodiment of the present application, but the protection scope of the present application is not limited thereto, and any modification, equivalent replacement and improvement within the technical range disclosed by the present application and within the spirit and principles of the present application should be covered within the protection scope of the present application.
Claims
1. A method for implementing electrical precision control using FPGA, characterized in that, It comprises the following steps: The control terminal sends instructions to the NiosII CPU through the Usart IP core in the form of serial communication; the FPGA development board uses the embedded NiosII soft core CPU and multiple custom IP cores to control the outside world; The CPU accesses the custom pulse generation IP core through the avalon bus, configures the corresponding register to generate a pwm_out signal with adjustable number and duty cycle to control the motor to move with a specific number of steps; The motor driving module drives the motor to move, and converts the weak signal of the NiosII processor into a strong signal that can drive the motor to rotate; When the system has multiple dimensions of motors to control, multiple custom pulse generation IP cores are added, each IP core controls one motor, and multiple IP cores control multiple motors; Install infrared pairs on the motion path of the controlled object, the position coordinates of each infrared pair on the motion path are fixed and known, and the coordinates are input to the NiosII processor for subsequent control and processing; The NiosII processor in the FPGA and its custom PWM IP core control the motor to rotate, and the motor drives the controlled unit to achieve precise movement and complete different functions; at the same time, the liquid crystal screen displays the various operating states of the system; The method for realizing precise electrical control by using FPGA further comprises: After the system is powered on, it is automatically calibrated, when a motor drive is used to drive the object to move in the X-axis direction, at least three infrared pairs must be installed in the movable range of the X-axis direction driven by the motor: one at each end and one at the midpoint of the X-axis direction, and the absolute coordinates of the three infrared pairs are written into the initialization program; after the system is powered off, the driven object will stop at a certain position; after the system is powered on, the motor drives the driven object to move to the right, when the driven object moves in the X-axis direction and collides with a certain infrared pair, the system immediately jumps into the infrared interrupt IRQ_Handler(), in this interrupt service program, the global variable Position_Now representing the current position is updated to the position coordinate of the current pair, the system is automatically calibrated and stopped; A motor drive is added to drive the object to move in the Y-axis direction, three laser pairs are installed at the front end, the rear end and the middle of the Y-axis, when the driven object collides with a certain infrared pair in the Y-axis direction, the system immediately jumps into the infrared interrupt, and the same operation is performed: the Position_Now global variable representing the current dimension is updated to the position coordinate of the current pair; in this way, automatic calibration in N dimensions can be completed.
2. The method for implementing electrical precision control using FPGA according to claim 1, wherein, The motor driving method further comprises: The present application discloses a control method for controlling the movement of an object in multiple dimensions by using multiple motors, and a control system thereof. When the motor moves to a certain coordinate, the conversion factor between the number of motor rotations and the movement distance of the driven object is α. The coordinate is multiplied by α to convert it into the number of steps that the motor needs to take, i.e. the number of pulses that need to be generated. Then the NiosII processor writes the number of target pulses into the purpose_pulse_num register in the IP core. The num_cnt counter in the IP core performs self-increment operation according to the forward and reverse rotation of the motor in the current axis, thereby recording the number of pwm_out pulses provided by the IP core to the motor in real time. When the value recorded by the num_cnt current cumulative pulse counter is equal to the value assigned to the variable, the IP core stops generating PWM pulses.
3. The method for implementing electrical precision control using FPGA according to claim 1, wherein, Each motor is installed with multiple infrared pairs of tubes on the running track of the component controlled thereby, each infrared pair of tube has a respective pair of tube control circuit, and each controlled component is installed with a shielding piece that moves together with the driven object. If the shielding piece does not block the laser pair of tubes during the movement, the pair of tube control circuit sends a low level to the NiosII processor; if the shielding piece blocks the laser pair of tubes, the pair of tube control circuit sends a high level to the NiosII processor. The NiosII processor can respond to the interrupt generated by the rising edge of the high level of each laser pair of tube, and modify the value of the current position variable Position_Now to be equal to the position coordinate of the laser pair of tube in the interrupt service program, thereby achieving one-time calibration.
4. The method for implementing electrical precision control using FPGA according to claim 1, wherein, The variables and functions defined in the control method include: A purpose_pulse_num register representing the target coordinate is defined in the Verilog hardware description language, which is used to store the number of PWM pulses that the IP core needs to generate after data conversion; the num_cnt current cumulative pulse counter is increased by 1 after the IP core generates a pwm_out signal to drive the motor to take a further step. In C language, define infrared interrupt service function IRQ_Handler(); define variable Position_Now representing current coordinate position, the value of the variable is dynamically changed; the change includes: (1) through a thread on the UCOS operating system, periodically acquire the value in the num_cnt representing current cumulative pulse number counter in IP core through avalon bus, convert the data into coordinate position, and according to the coordinate position of the driven object when the motor starts to move, calculate the current absolute coordinate and assign the value to the variable; (2) when the driven object collides with a certain infrared pair tube, enter the infrared interrupt, and the value of the variable in the interrupt service program will be changed to the coordinate of the pair tube; define variable purpose_position representing destination coordinate position; function Move_To_absolute_Position(position) for driving the motor to rotate and drive the driven object to move to a certain absolute coordinate; function drive_motor_right(step) and drive_motor_left(step) for driving the motor to move in the left and right directions of a certain axis.
5. The method for implementing electrical precision control using FPGA according to claim 1, wherein, The processing method of the infrared pair tube reaching a certain absolute coordinate during the motor movement, comprising: When a motor controls a driven object to move in the X-axis direction, when the CPU controls the stepping motor to move towards a certain coordinate, the destination coordinate is assigned to the purpose_position global variable representing the destination coordinate in the C language program; the coordinate is converted into the number of steps that the motor needs to step through data conversion, and NiosII writes the converted value into the purpose_pulse_num register of the IP core through the avalon bus; then the CPU enables the IP core to start generating the PWM wave, and the num_cnt increases by 1, that is, the motor steps once, every time a pwm_out signal is generated; The motor drives the driven object to move towards a certain absolute coordinate by calling the function Move_To_absolute_Position(x_position). The principle of the function Move_To_absolute_Position(x_position) is that the difference between the Position_Now variable representing the current coordinate and the purpose_position representing the destination coordinate is obtained, and the result is the distance between the current coordinate and the destination coordinate. If the result is greater than zero, the drive_motor_right(step) function is continuously called. If the result is less than zero, the drive_motor_left(step) function is called. The conversion factor between the number of motor rotations and the distance of the driven object movement is α. By executing the two functions, the coordinate difference obtained is first multiplied by α to convert it into the number of steps step that the motor needs to step, and the number of pulses that need to be generated. Then the CPU writes the converted step difference into the purpose_pulse_num register of the IP core again through the avalon bus and resets the IP core. After the reset, num_cnt is equal to 0. Then when NiosII makes go=1 through the instruction, num_cnt starts to accumulate the number of pulses generated again, that is, the rising edge of pwm_out will drive num_cnt to increase by 1. The IP core will generate accurate pwm_out pulse waves according to the updated purpose pulse number, so as to drive the motor to rotate to the left or right by the appropriate step length. When a certain infrared pair tube is encountered during movement, the infrared interrupt is entered, and the calibration in the movement is completed. When the next infrared pair tube is blocked by the driven object, the above operation is repeatedly performed. Calibration is continuously performed during movement, so that the motor can accurately step to the destination coordinate position on the X-axis. Similarly, by adding another motor, the driven object can be controlled to move on the Y-axis. With the increase of one motor, one IP core is added, and a y_purpose_position variable representing the destination coordinate position and a Y_Position_Now representing the current coordinate position are also added. After the calibration of the motor is completed, the motor continues to step to the destination coordinate on the Y-axis. The motor can be expanded to N axes to accurately move to a certain absolute coordinate in N dimensions. The various operating states of the system include power supply conditions, destination coordinate positions, current coordinates, current stepping steps, calibration times, and system running time information.
6. A system for implementing electrical precision control using FPGA, characterized in that, The system for realizing the method for realizing electrical precision control by using FPGA according to any one of claims 1-5 comprises: an FPGA development board, a motor driving module, an infrared pair tube, and a liquid crystal screen; the FPGA development board realizes control over the outside world by embedding a NiosII soft core CPU and multiple self-defined IP cores; Motor drive module, for driving the motor to move, and the weak electrical signal of NiosII processor is converted into strong electrical signal which can drive the motor to rotate; Infrared pair tube, installed on the motion path of the controlled object, the coordinate of each infrared pair tube on the motion path is fixed and known, and the coordinate is input to the NiosII processor for subsequent control and processing; Liquid crystal screen, for displaying various running states of the system.
7. The system for implementing electrical precision control using FPGA as claimed in claim 6, wherein, The FPGA includes a plurality of exposed pins, which are connected to other components by wires to realize the control function of other components.
8. The system for implementing electrical precision control using FPGA as claimed in claim 6, wherein, The system for realizing electrical precision control by using FPGA takes FPGA as the main control MCU, and a NiosII soft core CPU system is constructed by using the logic resources of FPGA. The system includes a self-defined PWM IP core, an SDRAM IP core, an EPCS IP core, a serial port IP core and a display IP core. The IP cores are connected to the NiosII processor through an avalon bus and respond to the control of the CPU. The SDRAM IP core is used to convert the external hardware non-linear SDRAM into linear so that the FPGA can read; The EPSC IP core enables the FPGA to successfully download programs. The FPGA configuration data and NiosII programs are stored in the EPCS. The serial port IP core and the display IP core are directly called from the library and hung on the avalon bus. The two realize the serial communication between the Bluetooth and the CPU and the communication between the liquid crystal display and the CPU, respectively.
9. The system for implementing electrical precision control using FPGA as claimed in claim 6, wherein, The system for realizing electrical precision control by using FPGA further includes a PWM core structure. A self-defined motor pulse generation IP core is used, which has irq interrupt and pwm_out output interface. A frequency greater than 10M pwm_clk is generated by using a phase-locked loop to ensure that the IP core can stably output PWM pulses to control the motor rotation. The IP core has the following components: a pulse enable register ctrl_reg, a register purpose_pulse_num of expected pulse number, a current cumulative pulse counter num_cnt, high and low level duration clock number registers n_high and n_low, and a PWM generator. In the IP core, an output-type pwm_out variable is defined to represent the generated PWM signal. Two 32-bit n_high and n_low variables are defined. The number of pwm_clk clocks during the high and low level is changed by assigning values to the two variables, and accordingly the duty cycle and frequency of pwm_out are changed. A 32-bit counter num_cnt is defined to accumulate the number of generated PWM pulses. The driving clock of the register is pwm_out. When the go bit of ctrl_reg changes from low to high, the value of num_cnt will automatically increase by 1 at the rising edge of each pwm_out.
Citation Information
Patent Citations
IP core for realizing real-time detection of phase and power factor of multiphase power supply by utilizing FPGA
CN111929607A
Control systems state vector management using co-processing and multiport ram
US20160342146A1