A PLC instruction design method suitable for motion control
By designing compiled PLC instructions, the problem of low efficiency of existing PLC motion control is solved, efficient and real-time motion control is achieved, the programming process is simplified and the flexibility of hardware resources is improved.
Patent Information
- Application Number
- CN202210503014.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-09
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2042-05-09
AI Technical Summary
The existing PLC's motion control instruction execution efficiency is low and it is difficult to meet the high efficiency and real-time requirements of the industrial control process, especially in terms of dynamic parameter configuration and hardware resource calling.
A compiled PLC instruction method suitable for motion control is designed, including high-speed pulse input and output instructions. Compiled IDE software is used to configure hardware resources and supports multiple counting modes and control modes. Through precise parameter configuration and S-curve algorithm Improve instruction execution efficiency.
It significantly improves the motion control efficiency of PLC, meets the high efficiency and real-time requirements of industrial control, simplifies the programming process, and improves user experience and flexibility of hardware resources.
Smart Images

Figure CN115268352B
Abstract
Description
Technical Field
[0001] The invention relates to a PLC instruction design method suitable for motion control, belonging to the technical field of PLC software design and programming interaction. Background Art
[0002] PLC stands for Programmable Logic Controller, which is a microcomputer specially used for industrial control. The motion control instructions of existing common PLCs mainly include high-speed pulse output instructions and high-speed pulse input instructions, most of which are based on interpretation. Interpretation PLCs interpret and execute the intermediate code program on the target machine one by one without translating it into target machine code first. However, the disadvantages are obvious: every step of the user program must be interpreted during its operation, which makes the program operation efficiency relatively low and occupies a lot of resources, which is not conducive to the high efficiency and real-time requirements of the industrial control process.
[0003] The PLC high-speed pulse input instructions are mostly based on interrupts, are not affected by the PLC scanning cycle, and collect input signals with a higher frequency. They are mainly used to connect external encoders. By using different counting modes to count different types of pulse input signals, users can convert the count value of high-speed pulses into distance, angle, speed and other data.
[0004] The PLC high-speed pulse output instructions generally include two types, namely pulse width modulation instructions PWM and pulse train output instructions PTO. PWM is an analog control mode, and PTO is a pulse control mode. When the device has precise requirements for speed and torque, select PWM; when the device has precise control of position, select PTO; select the type of servo device according to the needs of the device, and finally select the control method. For example, the acceleration and deceleration time of Mitsubishi PLC's PTO can only be the same, and the maximum supported step limit value is low. For example, the 16-bit instruction of FNC59 can only be set to 9 steps, and the 32-bit can only be set to 17 steps; and there is no deceleration operation when the pulse output is stopped.
[0005] Further analysis shows that the execution efficiency of the motion control instructions of the interpreted PLC is lower than that of the compiled PLC. When the prior art uses the compiled PLC to execute motion control instructions, there are the following technical difficulties: ① How to dynamically configure parameters according to demand, display the operation curve in real time, and make programming more intuitive to improve programming efficiency; ② How to quickly customize and flexibly call hardware resources; ③ How to improve the execution efficiency of motion control instructions to meet the real-time requirements of motion to the greatest extent. Based on this, the technical field urgently needs a compiled PLC instruction design suitable for motion control to improve the motion control efficiency of PLC. Summary of the invention
[0006] In view of the deficiencies of the prior art, the present invention discloses a PLC instruction design method suitable for motion control. SUMMARY OF THE INVENTION
[0008] The instruction design method of the present invention includes a high-speed pulse input instruction design method and a high-speed pulse output instruction design method:
[0009] The high-speed pulse input instruction is an HSC instruction. In the HSC instruction design, the present invention provides 10 high-speed counting methods for encoder pulse input counting in the motion control process, which can meet the high-speed counting requirements of most types of encoders; the high-speed pulse output instruction designs are pulse width modulation PWM instructions and pulse train output PTO instructions, respectively. The same high-speed pulse output port supports PWM mode and PTO mode, and PTO supports three working modes: manual, single-speed continuous operation, and relative position. It uses precise parameter configuration to output accurate high-speed pulses, provide ideal pulse control, and effectively improve the high-speed pulse output efficiency of compiled PLCs.
[0010] The present invention is implemented using compiled PLC programming software, which significantly improves program running efficiency compared to traditional interpreted PLCs, occupies less resources, and fully meets the high efficiency and high real-time performance of industrial control processes.
[0011] The detailed technical scheme of the present invention is as follows:
[0012] A PLC instruction design method suitable for motion control, characterized in that it includes the design of high-speed pulse output instructions and the design of high-speed pulse input instructions;
[0013] The design of the high-speed pulse output instruction includes: the compiled IDE software stores the PLC hardware resources configured with the high-speed pulse output instruction in a database, such as Figure 1 As shown in the serial number display 30-32; the compiled IDE software refers to the integrated development environment of the compiled PLC based on language conversion; the working principle of the compiled PLC based on language conversion is to translate the ladder diagram into a C language program and directly compile and execute it; the integrated development environment is a tool software composed of an editor, a manager, and a configurator that can realize PLC programming management; PWM instructions and PTO instructions share a high-speed output port; the PWM instructions and PTO instructions are called by the compiled IDE software to perform related ladder diagram programs;
[0014] The PTO instruction includes three high-speed pulse output modes: manual mode, single-speed continuous operation mode and relative position mode; the manual mode manually starts and stops the high-speed pulse output through a switch button; the single-speed continuous operation mode refers to continuous operation at a fixed target speed; the relative position mode refers to setting the parameters of an envelope motion curve by the method of relative calculation of position, with the starting point of each step as the relative zero point; the envelope motion curve refers to a curve, that is, a motion process from the starting speed to acceleration, uniform speed, deceleration to the stop speed; the step refers to a process from the start of acceleration / deceleration to the end of uniform speed operation within an envelope motion curve, especially the last step includes the deceleration to the stop speed segment;
[0015] The methods for calling PWM instructions through compiled IDE software include:
[0016] like Figure 2 As shown,
[0017] (1-1) Initialize the relevant parameters of the PWM instruction:
[0018] The relevant parameters include name, PWM channel, pin description, cycle, value range, duty cycle and remarks; the name is an alias for the PWM instruction function; the PWM channel is used to select the PWM hardware resource defined in the database; the pin description is used to describe the specific PLC position in the selected PWM channel, wherein the data of the pin description is obtained by querying the hardware resource configuration database; the cycle is set according to the value range, and the unit is optional; the duty cycle is the set duty cycle data, which can be a decimal; the remarks are used to add descriptions; Figure 3 As shown, drag the PWM instruction to the editing area of the compiled IDE software, and a dialog box automatically pops up to set the relevant parameters of the PWM instruction; after clicking the OK button, the relevant parameters of the initialization PWM instruction are completed;
[0019] (1-2) Initialize the PWM data structure:
[0020] The PWM data structure includes a Boolean unit variable, a floating-point duty cycle variable, an integer period variable and a PWM pin variable;
[0021] The compiled IDE software parses the relevant parameters of the PWM instruction in step (1-1) into the PWM data structure to initialize the PWM data structure. The parsing method is as follows: directly assign the period and duty cycle in step (1-1) to the integer period variable and integer period variable in the PWM data structure respectively; directly assign the unit of the period selected in step (1-1) to the Boolean unit variable in the PWM data structure: when the value is true, it represents microseconds; when the value is false, it represents milliseconds; assign the pin data of the PWM channel configuration in step (1-1) to the PWM pin variable in the PWM data structure. For example, if the user uses Q0.0 as the PWM pin, by querying the hardware resource configuration database, Q0.0 corresponds to the CPU pin PA0, and the PWM pin variable in the PWM data structure is PA0;
[0022] (1-3) PWM drive interface
[0023] It is used to realize the pulse width modulation function of PWM, and the user data required in the driving implementation process is the PWM data structure initialized in step (1-2); the PWM driving interface includes: PWM initialization configuration interface PWM_Config(), PWM cycle update interface PWM_Cycle_Update() and PWM duty ratio update interface PWM_DutyRatio_Update();
[0024] The methods for calling PTO instructions through compiled IDE software include:
[0025] like Figure 4 As shown,
[0026] (2-1) Initialize the relevant parameters of the PTO instruction:
[0027] The related parameters include basic configuration parameters and further configuration parameters for each mode;
[0028] The basic configuration parameters include the parameters that must be configured in the three modes of manual, single-speed continuous operation and relative position, such as Figure 5As shown, basic information, setting port, motor speed, acceleration setting and deceleration setting; the basic information includes name and remarks; the name is an alias for the PTO instruction function; the remarks are used to add instructions; the setting port is used for the high-speed pulse output port configured in the database, shared with the PWM port, but not compatible, that is, one port either selects PTO mode or PWM mode, and sets fault tolerance reminder; the motor speed includes maximum speed, start-stop speed and minimum speed, where the value of the minimum speed is the same as the start-stop speed, and the unit is pulse / second; the acceleration setting and deceleration setting include acceleration time t, change pulse number ΔN and single pulse cycle increment ΔT; the acceleration time t unit is milliseconds; the change pulse number ΔN unit is pulse; the single pulse cycle increment ΔT unit is microsecond / pulse; where the termination period T m The relationship between the five variables, starting cycle T0, acceleration time t, number of pulse changes ΔN and single pulse cycle increment ΔT, is shown in formulas (I) and (II). m is the reciprocal of the corresponding end frequency; the starting period T0 is the reciprocal of the corresponding start frequency;
[0029]
[0030]
[0031] Methods for further configuration of each mode include:
[0032] When the manual mode is selected, only the basic configuration parameters are required;
[0033] When configuring acceleration and deceleration, if the maximum speed and start / stop speed have been configured, the three variables of single pulse cycle increment, number of pulse changes, and acceleration / deceleration time are automatically calculated according to the formula. As long as any one variable is entered, the other two variables will automatically change, which can greatly reduce the tedious calculations and unit conversions of programmers.
[0034] When the single-speed continuous operation mode is selected, Figure 6 As shown, the configuration includes: target speed, stop distance; the unit of the target speed is pulse / second; the unit of the stop distance is pulse, and the stop distance can be configured only when the check box for the stop signal is selected; the stop signal refers to the high-speed pulse signal that triggers the PTO to stop outputting in the single-speed continuous operation mode;
[0035] When the relative position mode is selected, the relative position mode means that a whole section of PTO output includes n envelopes, each envelope consists of m steps; in each envelope: the last step contains a rising / falling segment, a parallel segment and an ending segment, and the remaining steps all contain a rising / falling segment and a parallel segment; Figure 7As shown, the configuration includes: adding envelope, adding step, modifying, deleting and exporting envelope; the adding envelope is used to automatically add an envelope and name the envelope; the adding step is used to add a step to the current envelope; the modifying is used to modify the step data after selecting a step; the deleting is used to delete the currently selected step after selecting a step; the exporting envelope is used to export and encapsulate the current envelope into an envelope library to customize and call standardized curves; the envelope library is the parameter configuration of an encapsulated envelope curve. When the user uses the envelope library again, he only needs to load the envelope curve encapsulated by the envelope library without repeated settings;
[0036] Drag the PTO instruction to the editing area of the compiled IDE software, and the dialog box that pops up automatically is used to configure the relevant parameters of the PTO instruction, including basic configuration and further configuration for each mode;
[0037] (2-2) Initialize the PTO data structure:
[0038] The PTO data structure includes a PTO pin variable, an integer maximum cycle variable, an integer start-stop cycle variable, a floating-point single pulse cycle increment, an integer working mode variable, a single-speed continuous operation mode structure, and a relative position mode structure;
[0039] The single-speed continuous operation mode structure includes a Boolean stop flag variable and an integer target period variable; the relative position mode structure includes an integer envelope total number variable and an envelope structure; the envelope structure includes an integer total step number variable and a step structure; the step structure includes an integer start period, a target period, and a preset pulse variable;
[0040] The compiled IDE software parses the relevant parameters of the PTO instruction in step (2-1) into the PTO data structure and initializes the PTO data structure. The parsing method is as follows: assign the port data set in step (2-1) to the PTO pin variable in the PTO data structure. For example, if the user uses Q0.1 as the PTO pin, then by querying the hardware resource configuration database, Q0.1 corresponds to the CPU pin PA1, and the PTO pin variable in the structure is PA1; convert the maximum speed in step (2-1) into the maximum cycle variable of the PTO data structure in microseconds; convert the start and stop speed in step (2-1) into the start and stop cycle variable of the PTO data structure in microseconds; directly assign the single pulse cycle increment in step (2-1) to the single speed pulse cycle increment in the PTO data structure; parse the configuration mode in step (2-1) into the working mode variable in the PTO data structure: the value of 1 represents the manual mode; the value of 2 represents the single speed continuous operation mode; the value of 3 represents the relative position mode; The target speed configured in the single speed mode in step (2-1) is converted into a period variable with microseconds as the calculation unit and assigned to the target period variable in the single speed continuous operation mode structure. The stop signal selected in the check box is assigned to the stop flag: the value of true represents the stop signal selection; the value of false represents the stop signal is not selected; the total number of envelopes configured in the relative position mode in step (2-1) is counted and assigned to the total number of envelopes variable in the relative position mode structure; the total number of steps configured in the relative position mode in step (2-1) is counted and assigned to the total number of steps in the envelope structure; the single-step target speed configured in the relative position mode in step (2-1) is converted into a target period variable in the step structure with microseconds as the unit; the single-step target position configured in the relative position mode in step (2-1) is directly assigned to the preset pulse variable in the step structure; the target speed of the previous step configured in the relative position mode in step (2-1) is converted into a starting period variable in the step structure with microseconds as the calculation unit; the starting period of the first step is the start-stop period value in the basic setting;
[0041] (2-3)PTO drive interface
[0042] It is used to realize the pulse transmission function of PTO, and the user data required in the driving implementation process is the PTO data structure initialized in step (2-2); the PTO driving interface includes the PTO initialization configuration interface PTO_Config(), the PTO start interface StartPTO(), and the PTO stop interface StopPTO().
[0043] In the step (2-3), in order to make the acceleration and deceleration of the PTO smoother, an S-curve algorithm is added to the functions corresponding to the PTO start interface StartPTO() and the PTO stop interface StopPTO() so that the acceleration does not change suddenly.
[0044] The S-curve algorithm includes an acceleration segment, a deceleration segment, an acceleration / deceleration segment, and a deceleration / deceleration segment. Figure 8 As shown, under the algorithm, the PTO controls the stepper motor stably and the speed changes smoothly, which greatly improves the phenomena of slow start, loss of step at start and large impact at start and stop. The S-curve algorithm includes formula (III), formula (IV) and formula (V);
[0045] The rate of change of acceleration k is fixed and is obtained by the parameters Cn, C0 and n set in the human-computer interaction design:
[0046]
[0047] In formula (III), k is the rate of change of acceleration, which is fixed; Cn, C0, and n are the corresponding period of the target frequency, the corresponding period of the starting speed, and the number of pulses during speed change, respectively;
[0048] The acceleration is divided into two change stages, one is a linear change according to the change rate k in the first half of the speed change stage; the other is a linear change in the second half of the speed change stage; the direction of the acceleration is determined by the acceleration and deceleration stages of the PTO, which is positive during acceleration and negative during deceleration; the magnitude of the acceleration is shown in formula (IV):
[0049]
[0050] In formula (IV): x, a x They are the current pulse number and the acceleration magnitude of the current pulse respectively;
[0051] The relationship between the cycles is:
[0052] C x =C x-1 +a x (V)
[0053] In formula (V): C x , C x-1 They are the period of the current pulse and the period of the previous pulse respectively.
[0054] Preferably according to the present invention, the further configuration also includes: curve drawing, the curve drawing is used to set a curve schematic diagram automatically drawn at each step, the figure includes an x-coordinate, a y-coordinate, a preset total number of pulses, and a maximum speed of the curve; the x-coordinate refers to the relative position of the operation, unit pulse; the y-coordinate refers to the operation speed, unit pulse / s; the preset total number of pulses refers to the sum of the position data set in all steps in an envelope curve, marked on the x-coordinate axis; the maximum speed of the curve refers to the preset maximum target speed in an envelope curve, marked on the y-coordinate axis.
[0055] According to the preferred embodiment of the present invention, the adding step is as follows Fig. 9 The dialog box for adding a step is shown, including adding position, target speed, target position, variable pulse increment and single pulse cycle increment;
[0056] The added position refers to adding after the position row; the change pulse increment and the single pulse cycle increment are the change pulse increment and the single pulse cycle increment in the basic configuration by default, or the change pulse increment and the single pulse cycle increment are calculated and adjusted in conjunction with formulas (I) and (II). As long as one of the variables is changed, the other variable is automatically updated.
[0057] Preferably, according to the present invention, the design method further comprises a PTO driving step: Fig.10 The following is a PTO driven workflow diagram.
[0058] (3-1) Drive the initialization pin and enable interrupt;
[0059] (3-2) The operations of different working modes are as follows:
[0060] In manual mode, when the PTO is started, the pulse starts from the start-stop speed, and smoothly accelerates to the maximum speed according to the single pulse cycle increment value configured in the acceleration configuration in the basic configuration, and continues to run at the maximum speed after reaching the maximum speed; when the PTO is stopped, the PTO pulse starts from the maximum speed, and smoothly decelerates to the start-stop speed according to the single pulse cycle increment value configured in the deceleration configuration in the basic configuration, and then stops the PTO output, and the PTO drive step closes the interrupt;
[0061] In single-speed continuous operation mode, when PTO is started, the pulse starts from the start-stop speed, and smoothly accelerates to the target speed according to the single pulse cycle increment value configured in the basic configuration. After reaching the target speed, it continues to run at the target speed; when the stop signal activation stop is not selected, the PTO stops abnormally; when the stop signal activation stop is selected, the PTO stops smoothly according to the configured stop distance; if the stop distance is set to 0, it stops immediately, and the PTO drive step closes the interrupt;
[0062] In relative position mode, after starting PTO, the PTO drive steps are executed in sequence according to the set envelope data. During the execution, the pulse count value and real-time cycle are updated in real time. When the pulse count value reaches the preset total number of pulses, PTO stops and triggers the PTO count completion interrupt. Finally, the PTO drive step closes the interrupt.
[0063] Preferably, according to the present invention, the design of the high-speed pulse input instruction includes: the compiled IDE software stores the PLC hardware resources configured with the high-speed pulse input instruction into a database, such as Fig.11As shown, the user calls the high-speed counter module on the compiled IDE software side to perform relevant ladder diagram programs. The high-speed counter module includes the following high-speed pulse input counting modes:
[0064] mode0: Unidirectional high-speed counter with internal direction control and no external reset;
[0065] mode1: Unidirectional high-speed counter with internal direction control and external reset;
[0066] mode2: Unidirectional high-speed counter with external direction control and no external reset;
[0067] mode3: Unidirectional high-speed counter with external direction control and external reset;
[0068] mode4: Bidirectional high-speed counter with two clock inputs and no external reset;
[0069] mode5: Bidirectional high-speed counter with two clock inputs and external reset;
[0070] mode6 / 8: Bidirectional high-speed counter with AB quadrature phase and no external reset;
[0071] mode7 / 9: Bidirectional high-speed counter with AB quadrature phase and external reset.
[0072] Preferably according to the present invention, the design of the high-speed pulse input instruction further includes:
[0073] 1) The compiled IDE software translates the configuration parameters of the ladder diagram related to the high-speed counter defined by the user into C language;
[0074] 2) Initialize the counting modes mode0 - mode9 of the high-speed pulse input, as Fig.12 shown;
[0075] 3) Configure the data structure of the high-speed counter defined by the compiled IDE software, as Fig.13 shown, including the following parameters:
[0076] Counting mode mode, current count value CV, target count value PV, control word, status word, pulse pin 1, pulse pin 2, direction pin, and reset pin; the control word includes counting direction, enable, and counting rate; the status word includes counting direction status, CV < PV status, CV = PV status, and CV > PV status; both the current count value CV and the target count value PV support 32-bit integer data;
[0077] 4) Define the pins of the high-speed counter according to the selected counting mode. In different counting modes, the initialized pins are different, as Fig.12 shown:
[0078] When the counting mode mode0~mode9 is selected, the first pulse pin is initialized;
[0079] When the counting mode mode4~mode9 is selected, the second pulse pin is initialized;
[0080] When the counting mode mode1, mode3, mode5, mode7, mode9 is selected, the external reset pin is initialized;
[0081] When selecting counting mode mode2 and mode3, the external direction pin is initialized;
[0082] Enable the external interrupt interfaces of the pulse pin, direction pin and reset pin configured above in sequence;
[0083] The high-speed counters that select counting modes mode0 to mode9 all have three interrupt function interfaces: count completion interrupt, count direction change interrupt, and count reset interrupt. The interrupt program dialog box and edit box of the high-speed counter are in Fig.14 and Fig.15 The above three high-speed counter interrupt programs are respectively nested in the pulse pin external interrupt interface, the direction pin external interrupt interface and the reset pin external reset interface, wherein the count completion interrupt function is nested in the pulse count pin interrupt interface, the count direction change interrupt function is nested in the external direction change pin interrupt interface, and the count reset interrupt function is nested in the external reset interrupt interface;
[0084] The count completion interrupt of counting modes mode6 and mode7 is nested in the interrupt interface of timer count overflow, and the count direction change interrupt is implemented by the main function scanning method;
[0085] The count completion interrupt and count direction change interrupt of counting modes mode8 and mode9 are nested in the timer input capture interrupt interface;
[0086] In the above three interrupt programs, users use IDE software to design related interrupt ladder programs, such as Fig.14 , 15 shown.
[0087] Preferably, according to the present invention, the detailed counting process of the counting modes mode 0 to mode 5 is as follows: Fig.16 The flowchart on the left in the figure is a program processing flowchart of the high-speed pulse input pin 1; the flowchart in the middle is a program processing flowchart of the high-speed pulse input pin or the direction change pin, and the flowchart on the right is a program processing flowchart of the reset pin;
[0088] Counting modes mode0 and mode1 belong to high-speed counters with internal direction control. The counting direction is user-defined. When counting, connect pulse pin 1 to the input port of the PLC device. The maximum counting frequency is 200kHz.
[0089] Counting modes mode2 and mode3 belong to high-speed counters with external direction control. They require 1 pulse signal and 1 direction signal to count up and down. The maximum counting frequency is 200kHz.
[0090] Counting modes mode4 and mode5 belong to dual-clock high-speed counters, including two pulse signals: one is an up-counting signal and the other is a down-counting signal. The maximum counting frequency is 200kHz.
[0091] According to the preferred embodiment of the present invention, the counting modes mode6 to mode9 all belong to AB quadrature phase high-speed counters, and input two pulse signals with a phase difference of 90 degrees. Fig.17 and Fig.18 Listed in Fig.17 It shows the AB phase pulse counting process of counting modes mode8 and 9. Fig.18 It shows the AB phase pulse counting process of counting modes mode6 and 7. The direction of pulse counting of counting modes mode6 to mode9 is selected in Fig.19 Listed in detail, mode6, mode7, mode8, mode9 counting directions all meet Fig.19 The counting direction changes in the state;
[0092] Counting modes mode6 and mode7 use hardware timer for counting, supporting 2x and 4x frequency: higher frequency pulse counting is allowed, and users can accurately read the current count value, but interrupt operation at the pulse moment of the target count value is not supported. The maximum counting frequency is the frequency of the optocoupler isolation switch. For example, the frequency of the 6N137 optocoupler isolation switch is 10MHz.
[0093] The 2x frequency counting method is to read the interrupt trigger state of the AB phase pulse. The maximum counting frequency is the frequency of the optocoupler isolation switch. For example, if a 6N137 optocoupler isolation switch is selected, its frequency is 10MHz, and only the A phase is counted.
[0094] The 4x frequency counting method is to read the interrupt trigger state of the AB phase pulse, and count on both phase A and phase B. The maximum counting frequency is the frequency of the optocoupler isolation switch. For example, the 6N137 optocoupler isolation switch has a frequency of 10MHz. The above-mentioned frequency multiplication counting method supports the user to perform interrupt operation at the pulse moment of the target count value in the case of high-speed counting.
[0095] Preferably, according to the present invention, the counting modes mode8 and mode9 use interruption mode to realize counting, and support 1x, 2x and 4x counting: wherein the 1x counting mode realizes up counting and down counting by reading the rising edge and falling edge of the A phase pulse and the level state of the B phase, and the maximum counting frequency is 100kHz;
[0096] The 2x counting method is to read the interrupt trigger status of the AB phase pulse, the maximum counting frequency is 200kHz, and counting is only performed on the A phase;
[0097] The 4x frequency counting method is to read the interrupt trigger status of the AB phase pulse, count both phase A and phase B, and the maximum counting frequency is 400kHz. The above-mentioned frequency multiplication counting method supports the user to perform interrupt operation on the pulse moment of the target count value in the case of high-speed counting.
[0098] The technical advantages of the present invention are:
[0099] 1. The present invention saves the hardware resources and motion control instruction data configured by the user into the database, so that the user can more conveniently and quickly call PWM, PTO and HSC instructions for ladder diagram programming; the IDE software end has encapsulated the underlying driver and interrupt function of PWM, PTO and HSC instructions, so that the user can more conveniently call PWM, PTO and HSC instructions.
[0100] 2. The HSC instruction of the present invention provides 10 high-speed pulse counting modes, which can support up to 200KHz single-channel high-speed pulse, dual-channel high-speed pulse and the highest frequency AB phase ultra-high-speed pulse.
[0101] 3. From the user's perspective, the present invention designs a detailed parameter configuration interactive interface for PTO instructions and PWM instructions to facilitate guiding programmers to use them quickly.
[0102] 4. The present invention incorporates relevant calculation formulas into the interactive design, and relevant variables are automatically updated in linkage. Users can debug at will according to actual parameters, thereby improving parameter debugging efficiency.
[0103] 5. The present invention adds a curve drawing function design for PTO instructions, and automatically generates curves according to the parameter data configured by the user, making the curve debugging process more intuitive and clear.
[0104] 6. The high-speed pulse output function design method proposed in the present invention is based on language conversion, borrowing the flexible programming advantage of C language, and has no strict requirements on the maximum limit number of curve envelope and steps, and can be applied to more complex curve motion control occasions.
[0105] 7. The high-speed pulse output function design method proposed in the present invention is based on the advantages of real-time database, which makes it easier to encapsulate curve data and customize curves, making it convenient for users to call them at will in multiple projects. BRIEF DESCRIPTION OF THE DRAWINGS
[0106] Figure 1 is the PWM and PTO resource configuration variable table in Example 1 of the present invention;
[0107] Figure 2 is a flow chart of a method for calling a PWM instruction by a compiled IDE software in Embodiment 1 of the present invention;
[0108] Figure 3 It is the PWM parameter configuration dialog box displayed when the PWM instruction is dragged to the editing area of the compiled IDE software in Example 1 of the present invention;
[0109] Figure 4 is a flow chart of a method for calling a PTO instruction by a compiled IDE software in Embodiment 1 of the present invention;
[0110] Figure 5 It is the basic configuration dialog box in the PTO parameter configuration in Example 1 of the present invention;
[0111] Figure 6 It is an additional configuration diagram in the single-speed continuous operation mode in the PTO parameter configuration in Example 1 of the present invention;
[0112] Figure 7 It is the envelope configuration dialog box in the relative mode in the PTO parameter configuration in Example 1 of the present invention;
[0113] Figure 8 1 is a schematic diagram of the change of speed and acceleration of the S-shaped curve in Example 1 of the present invention, in which V is the curve speed, a is the acceleration, and t is the running time.
[0114] Fig. 9 This is the dialog box for adding a step in the PTO envelope configuration in Example 3 of the present invention;
[0115] Fig.10 is a workflow diagram of PTO drive in Example 4 of the present invention;
[0116] Fig.11 is the IDE end high speed counter parameter configuration variable table in embodiment 5 of the present invention;
[0117] Fig.12 It is a high-speed counter initialization flow chart in Embodiment 5 and “Application Example 5” of the present invention;
[0118] Fig.13 It is the IDE end high-speed counter parameter definition dialog box in Example 5 and "Application Example 5" of the present invention;
[0119] Fig.14 It is the IDE end high-speed counter interrupt program dialog box in Example 5 of the present invention and "Application Example 5";
[0120] Fig.15 It is the IDE end high-speed counter interrupt program editing box in Embodiment 5 of the present invention and "Application Example 5";
[0121] Fig.16 It is a working flow chart of high-speed counter modes 0 to 5 in Embodiment 5 and “Application Example 5” of the present invention;
[0122] Fig.17 is a flowchart of the high-speed counter modes 6 and 7 in the embodiment of the present invention and "Application Example 5" 5;
[0123] Fig.18 is a flowchart of the high-speed counter modes 8 and 9 in Example 5 and "Application Example 5" of the present invention;
[0124] Fig.19 is a table showing the relationship between the counting direction and the pulse signal of the high-speed counter modes 6 to 9 in Embodiment 5 and “Application Example 5” of the present invention;
[0125] Fig. 20 This is the PWM ladder diagram program diagram of "Application Example 1";
[0126] Fig.21 This is the result diagram of the PWM basic configuration operation of "Application Example 1";
[0127] Fig. 22 This is the running result diagram after the PWM update cycle of "Application Example 1";
[0128] Fig.23 This is the running result diagram after PWM updates the duty cycle in "Application Example 1";
[0129] Fig.24 This is the ladder diagram of PTO manual mode in "Application Example 2";
[0130] Fig.25 This is the result diagram of the acceleration section of PTO manual mode in "Application Example 2";
[0131] Fig.26 This is the result diagram of the PTO manual mode uniform speed segment operation in "Application Example 2";
[0132] Fig. 27 This is the operation result diagram of the PTO manual mode deceleration stage in "Application Example 2";
[0133] Fig.28 This is the result diagram of the acceleration section of the PTO single-speed continuous operation mode in "Application Example 3";
[0134] Fig.29 This is the result diagram of the uniform speed section operation of the PTO single-speed continuous operation mode in "Application Example 3";
[0135] Fig.30 This is the operation result diagram of the deceleration section of the PTO single-speed continuous operation mode in "Application Example 3";
[0136] Fig.31 This is the single envelope operation result diagram of PTO relative position mode in "Application Example 4";
[0137] Fig.32 This is the full envelope operation result diagram of the PTO relative position mode in "Application Example 4".
[0138] Fig.33 This is the experimental hardware structure diagram for the comprehensive verification of "Application Example 6";
[0139] Fig.34 This is the experimental physical environment diagram for comprehensive verification of "Application Example 6";
[0140] Fig.35 This is the HSC configuration diagram for comprehensive verification of "Application Example 6";
[0141] Fig.36 , 37 This is the PTO configuration diagram for comprehensive verification of "Application Example 6";
[0142] Fig.38 It is the ladder diagram program diagram for comprehensive verification of "Application Example 6";
[0143] Fig.39 This is the oscilloscope verification result operation diagram of the comprehensive verification of "Application Example 6";
[0144] Fig.40 This is a computer received signal speed statistics chart of the encoder verified by the comprehensive verification of "Application Example 6". DETAILED DESCRIPTION
[0145] The present invention will be described in detail below with reference to the embodiments and the accompanying drawings, but is not limited thereto.
[0146] Embodiment 1,
[0147] A PLC instruction design method suitable for motion control, including the design of high-speed pulse output instructions and the design of high-speed pulse input instructions;
[0148] The design of the high-speed pulse output instruction includes: including: the compiled IDE software stores the PLC hardware resources configured with the high-speed pulse output instruction in the database, such as Figure 1As shown in the serial number display 30-32; the compiled IDE software refers to the integrated development environment of the compiled PLC based on language conversion; the working principle of the compiled PLC based on language conversion is to translate the ladder diagram into a C language program and directly compile and execute it; the integrated development environment is a tool software composed of an editor, a manager, and a configurator that can realize PLC programming management; PWM instructions and PTO instructions share a high-speed output port; the PWM instructions and PTO instructions are called by the compiled IDE software to perform related ladder diagram programs;
[0149] The PTO instruction includes three high-speed pulse output modes: manual mode, single-speed continuous operation mode and relative position mode; the manual mode manually starts and stops the high-speed pulse output through a switch button; the single-speed continuous operation mode refers to continuous operation at a fixed target speed; the relative position mode refers to setting the parameters of an envelope motion curve by the method of relative calculation of position, with the starting point of each step as the relative zero point; the envelope motion curve refers to a curve, that is, a motion process from the starting speed to acceleration, uniform speed, deceleration to the stop speed; the step refers to a process from the start of acceleration / deceleration to the end of uniform speed operation within an envelope motion curve, especially the last step includes the deceleration to the stop speed segment;
[0150] The methods for calling PWM instructions through compiled IDE software include:
[0151] like Figure 2 As shown,
[0152] (1-1) Initialize the relevant parameters of the PWM instruction:
[0153] The relevant parameters include name, PWM channel, pin description, cycle, value range, duty cycle and remarks; the name is an alias for the PWM instruction function; the PWM channel is used to select the PWM hardware resource defined in the database; the pin description is used to describe the specific PLC position in the selected PWM channel, wherein the data of the pin description is obtained by querying the hardware resource configuration database; the cycle is set according to the value range, and the unit is optional; the duty cycle is the set duty cycle data, which can be a decimal; the remarks are used to add descriptions; Figure 3 As shown, drag the PWM instruction to the editing area of the compiled IDE software, and a dialog box automatically pops up to set the relevant parameters of the PWM instruction; after clicking the OK button, the relevant parameters of the initialization PWM instruction are completed;
[0154] (1-2) Initialize the PWM data structure:
[0155] The PWM data structure includes a Boolean unit variable, a floating-point duty cycle variable, an integer period variable and a PWM pin variable;
[0156] The compiled IDE software parses the relevant parameters of the PWM instruction in step (1-1) into the PWM data structure to initialize the PWM data structure. The parsing method is as follows: directly assign the period and duty cycle in step (1-1) to the integer period variable and integer period variable in the PWM data structure respectively; directly assign the unit of the period selected in step (1-1) to the Boolean unit variable in the PWM data structure: when the value is true, it represents microseconds; when the value is false, it represents milliseconds; assign the pin data of the PWM channel configuration in step (1-1) to the PWM pin variable in the PWM data structure. For example, if the user uses Q0.0 as the PWM pin, by querying the hardware resource configuration database, Q0.0 corresponds to the CPU pin PA0, and the PWM pin variable in the PWM data structure is PA0;
[0157] (1-3) PWM drive interface
[0158] It is used to realize the pulse width modulation function of PWM, and the user data required in the driving implementation process is the PWM data structure initialized in step (1-2); the PWM driving interface includes: PWM initialization configuration interface PWM_Config(), PWM cycle update interface PWM_Cycle_Update() and PWM duty ratio update interface PWM_DutyRatio_Update();
[0159] The methods for calling PTO instructions through compiled IDE software include:
[0160] like Figure 4 As shown,
[0161] (2-1) Initialize the relevant parameters of the PTO instruction:
[0162] The related parameters include basic configuration parameters and further configuration parameters for each mode;
[0163] The basic configuration parameters include the parameters that must be configured in the three modes of manual, single-speed continuous operation and relative position, such as Figure 5As shown, basic information, setting port, motor speed, acceleration setting and deceleration setting; the basic information includes name and remarks; the name is an alias for the PTO instruction function; the remarks are used to add instructions; the setting port is used for the high-speed pulse output port configured in the database, shared with the PWM port, but not compatible, that is, one port either selects PTO mode or PWM mode, and sets fault tolerance reminder; the motor speed includes maximum speed, start-stop speed and minimum speed, where the value of the minimum speed is the same as the start-stop speed, and the unit is pulse / second; the acceleration setting and deceleration setting include acceleration time t, change pulse number ΔN and single pulse cycle increment ΔT; the acceleration time t unit is milliseconds; the change pulse number ΔN unit is pulse; the single pulse cycle increment ΔT unit is microsecond / pulse; where the termination period T m The relationship between the five variables, starting cycle T0, acceleration time t, number of pulse changes ΔN and single pulse cycle increment ΔT, is shown in formulas (I) and (II). m is the reciprocal of the corresponding end frequency; the starting period T0 is the reciprocal of the corresponding start frequency;
[0164]
[0165]
[0166] Methods for further configuration of each mode include:
[0167] When the manual mode is selected, only the basic configuration parameters are required;
[0168] When configuring acceleration and deceleration, if the maximum speed and start / stop speed have been configured, the three variables of single pulse cycle increment, number of pulse changes, and acceleration / deceleration time are automatically calculated according to the formula. As long as any one variable is entered, the other two variables will automatically change, which can greatly reduce the tedious calculations and unit conversions of programmers.
[0169] When the single-speed continuous operation mode is selected, Figure 6 As shown, the configuration includes: target speed, stop distance; the unit of the target speed is pulse / second; the unit of the stop distance is pulse, and the stop distance can be configured only when the check box for the stop signal is selected; the stop signal refers to the high-speed pulse signal that triggers the PTO to stop outputting in the single-speed continuous operation mode;
[0170] When the relative position mode is selected, the relative position mode means that a whole section of PTO output includes n envelopes, each envelope consists of m steps; in each envelope: the last step contains a rising / falling segment, a parallel segment and an ending segment, and the remaining steps all contain a rising / falling segment and a parallel segment; Figure 7As shown, the configuration includes: adding envelope, adding step, modifying, deleting and exporting envelope; the adding envelope is used to automatically add an envelope and name the envelope; the adding step is used to add a step to the current envelope; the modifying is used to modify the step data after selecting a step; the deleting is used to delete the currently selected step after selecting a step; the exporting envelope is used to export and encapsulate the current envelope into an envelope library to customize and call standardized curves; the envelope library is the parameter configuration of an encapsulated envelope curve. When the user uses the envelope library again, he only needs to load the envelope curve encapsulated by the envelope library without repeated settings;
[0171] Drag the PTO instruction to the editing area of the compiled IDE software, and the dialog box that pops up automatically is used to configure the relevant parameters of the PTO instruction, including basic configuration and further configuration for each mode;
[0172] (2-2) Initialize the PTO data structure:
[0173] The PTO data structure includes a PTO pin variable, an integer maximum cycle variable, an integer start-stop cycle variable, a floating-point single pulse cycle increment, an integer working mode variable, a single-speed continuous operation mode structure, and a relative position mode structure;
[0174] The single-speed continuous operation mode structure includes a Boolean stop flag variable and an integer target period variable; the relative position mode structure includes an integer envelope total number variable and an envelope structure; the envelope structure includes an integer total step number variable and a step structure; the step structure includes an integer start period, a target period, and a preset pulse variable;
[0175] The compiled IDE software parses the relevant parameters of the PTO instruction in step (2-1) into the PTO data structure and initializes the PTO data structure. The parsing method is as follows: assign the port data set in step (2-1) to the PTO pin variable in the PTO data structure. For example, if the user uses Q0.1 as the PTO pin, then by querying the hardware resource configuration database, Q0.1 corresponds to the CPU pin PA1, and the PTO pin variable in the structure is PA1; convert the maximum speed in step (2-1) into the maximum cycle variable of the PTO data structure in microseconds; convert the start and stop speed in step (2-1) into the start and stop cycle variable of the PTO data structure in microseconds; directly assign the single pulse cycle increment in step (2-1) to the single speed pulse cycle increment in the PTO data structure; parse the configuration mode in step (2-1) into the working mode variable in the PTO data structure: the value of 1 represents the manual mode; the value of 2 represents the single speed continuous operation mode; the value of 3 represents the relative position mode; The target speed configured in the single speed mode in step (2-1) is converted into a period variable with microseconds as the calculation unit and assigned to the target period variable in the single speed continuous operation mode structure. The stop signal selected in the check box is assigned to the stop flag: the value of true represents the stop signal selection; the value of false represents the stop signal is not selected; the total number of envelopes configured in the relative position mode in step (2-1) is counted and assigned to the total number of envelopes variable in the relative position mode structure; the total number of steps configured in the relative position mode in step (2-1) is counted and assigned to the total number of steps in the envelope structure; the single-step target speed configured in the relative position mode in step (2-1) is converted into a target period variable in the step structure with microseconds as the unit; the single-step target position configured in the relative position mode in step (2-1) is directly assigned to the preset pulse variable in the step structure; the target speed of the previous step configured in the relative position mode in step (2-1) is converted into a starting period variable in the step structure with microseconds as the calculation unit; the starting period of the first step is the start-stop period value in the basic setting;
[0176] (2-3)PTO drive interface
[0177] It is used to realize the pulse transmission function of PTO, and the user data required in the driving implementation process is the PTO data structure initialized in step (2-2); the PTO driving interface includes the PTO initialization configuration interface PTO_Config(), the PTO start interface StartPTO(), and the PTO stop interface StopPTO().
[0178] In the step (2-3), in order to make the acceleration and deceleration of the PTO smoother, an S-curve algorithm is added to the functions corresponding to the PTO start interface StartPTO() and the PTO stop interface StopPTO() so that the acceleration does not change suddenly.
[0179] The S-curve algorithm includes an acceleration segment, a deceleration segment, an acceleration / deceleration segment, and a deceleration / deceleration segment. Figure 8 As shown, under the algorithm, the PTO controls the stepper motor stably and the speed changes smoothly, which greatly improves the phenomena of slow start, loss of step at start and large impact at start and stop. The S-curve algorithm includes formula (III), formula (IV) and formula (V);
[0180] The rate of change of acceleration k is fixed and is obtained by the parameters Cn, C0 and n set in the human-computer interaction design:
[0181]
[0182] In formula (III), k is the rate of change of acceleration, which is fixed; Cn, C0, and n are the corresponding period of the target frequency, the corresponding period of the starting speed, and the number of pulses during speed change, respectively;
[0183] The acceleration is divided into two change stages, one is a linear change according to the change rate k in the first half of the speed change stage; the other is a linear change in the second half of the speed change stage; the direction of the acceleration is determined by the acceleration and deceleration stages of the PTO, which is positive during acceleration and negative during deceleration; the magnitude of the acceleration is shown in formula (IV):
[0184]
[0185] In formula (IV): x, a x They are the current pulse number and the acceleration magnitude of the current pulse respectively;
[0186] The relationship between the cycles is:
[0187] C x =C x-1 +a x (V)
[0188] In formula (V): C x , C x-1 are the period of the current pulse and the period of the previous pulse respectively.
[0189] Embodiment 2,
[0190] As for the design method described in Example 1, the further configuration also includes: curve drawing, the curve drawing is used to set a curve schematic diagram that is automatically drawn at each step, the figure including an x-coordinate, a y-coordinate, a preset total number of pulses, and a maximum speed of the curve; the x-coordinate refers to the relative position of the operation, in units of pulses; the y-coordinate refers to the operation speed, in units of pulses / s; the preset total number of pulses refers to the sum of the position data set in all steps within an envelope curve, marked on the x-coordinate axis; the maximum speed of the curve refers to the preset maximum target speed within an envelope curve, marked on the y-coordinate axis.
[0191] Embodiment 3,
[0192] As in the design method described in Examples 1 and 2, the adding step is as follows Fig. 9 The dialog box for adding a step is shown, including adding position, target speed, target position, variable pulse increment and single pulse cycle increment;
[0193] The added position refers to adding after the position row; the change pulse increment and the single pulse cycle increment are the change pulse increment and the single pulse cycle increment in the basic configuration by default, or the change pulse increment and the single pulse cycle increment are calculated and adjusted in conjunction with formulas (I) and (II). As long as one of the variables is changed, the other variable is automatically updated.
[0194] Embodiment 4,
[0195] The design method described in embodiments 1, 2, and 3 further includes a PTO driving step: Fig.10 The following is a PTO driven workflow diagram.
[0196] (3-1) Drive the initialization pin and enable interrupt;
[0197] (3-2) The operations of different working modes are as follows:
[0198] In manual mode, when the PTO is started, the pulse starts from the start-stop speed, and smoothly accelerates to the maximum speed according to the single pulse cycle increment value configured in the acceleration configuration in the basic configuration, and continues to run at the maximum speed after reaching the maximum speed; when the PTO is stopped, the PTO pulse starts from the maximum speed, and smoothly decelerates to the start-stop speed according to the single pulse cycle increment value configured in the deceleration configuration in the basic configuration, and then stops the PTO output, and the PTO drive step closes the interrupt;
[0199] In single-speed continuous operation mode, when PTO is started, the pulse starts from the start-stop speed, and smoothly accelerates to the target speed according to the single pulse cycle increment value configured in the basic configuration. After reaching the target speed, it continues to run at the target speed; when the stop signal activation stop is not selected, the PTO stops abnormally; when the stop signal activation stop is selected, the PTO stops smoothly according to the configured stop distance; if the stop distance is set to 0, it stops immediately, and the PTO drive step closes the interrupt;
[0200] In relative position mode, after starting PTO, the PTO drive steps are executed in sequence according to the set envelope data. During the execution, the pulse count value and real-time cycle are updated in real time. When the pulse count value reaches the preset total number of pulses, PTO stops and triggers the PTO count completion interrupt. Finally, the PTO drive step closes the interrupt.
[0201] Embodiment 5,
[0202] As in the design method described in embodiments 1, 2, 3, and 4, the design of the high-speed pulse input instruction includes: the compiled IDE software stores the PLC hardware resources configured with the high-speed pulse input instruction in a database, such as Fig.11 As shown, the user calls the high-speed counter module on the compiled IDE software to perform related ladder diagram programs. The high-speed counter module includes the following high-speed pulse input counting modes:
[0203] Mode 0: unidirectional high-speed counter with internal direction control and no external reset;
[0204] Mode 1: unidirectional high-speed counter with internal direction control and external reset;
[0205] Mode 2: unidirectional high-speed counter with external direction control and no external reset;
[0206] Mode 3: unidirectional high-speed counter with external direction control and external reset;
[0207] Mode 4: Bidirectional high-speed counter with two clock inputs and no external reset;
[0208] Mode 5: Bidirectional high-speed counter with two clock inputs and external reset;
[0209] Mode 6 / 8: AB quadrature phase bidirectional high-speed counter without external reset;
[0210] mode7 / 9: AB quadrature phase bidirectional high-speed counter with external reset.
[0211] The design of the high-speed pulse input instruction also includes:
[0212] 1) The compilation-based IDE software translates the configuration parameters of the ladder diagram related to the high-speed counter defined by the user programming into C language;
[0213] 2) Initialize the counting modes mode0 - mode9 of the high-speed pulse input, as Fig.12 shown;
[0214] 3) Configure the data structure of the high-speed counter defined by the compilation-based IDE software, as Fig.13 shown, including the following parameters:
[0215] Counting mode mode, current count value CV, target count value PV, control word, status word, pulse pin 1, pulse pin 2, direction pin, and reset pin; the control word includes counting direction, enable, and counting rate; the status word includes counting direction status, CV < PV status, CV = PV status, and CV > PV status; both the current count value CV and the target count value PV support 32-bit integer data;
[0216] 4) Define the pins of the high-speed counter according to the selected counting mode. In different counting modes, the initialized pins are different, as Fig.12 shown:
[0217] When selecting counting modes mode0 - mode9, initialize the first pulse pin;
[0218] When selecting counting modes mode4 - mode9, initialize the second pulse pin;
[0219] When selecting counting modes mode1, mode3, mode5, mode7, mode9, initialize the external reset pin;
[0220] When selecting counting modes mode2 and mode3, initialize the external direction pin;
[0221] Enable the external interrupt interfaces of the above-configured pulse pins, direction pins, and reset pins in sequence;
[0222] The high-speed counters selecting counting modes mode0 - mode9 all have three interrupt function interfaces: counting completion interrupt, counting direction change interrupt, and counting reset interrupt; the interrupt program dialog box and edit box of the high-speed counter are in Fig.14 and Fig.15The above three high-speed counter interrupt programs are respectively nested in the pulse pin external interrupt interface, the direction pin external interrupt interface and the reset pin external reset interface, wherein the count completion interrupt function is nested in the pulse count pin interrupt interface, the count direction change interrupt function is nested in the external direction change pin interrupt interface, and the count reset interrupt function is nested in the external reset interrupt interface;
[0223] The count completion interrupt of counting modes mode6 and mode7 is nested in the interrupt interface of timer count overflow, and the count direction change interrupt is implemented by the main function scanning method;
[0224] The count completion interrupt and count direction change interrupt of counting modes mode8 and mode9 are nested in the timer input capture interrupt interface;
[0225] In the above three interrupt programs, users use IDE software to design related interrupt ladder programs, such as Fig.14 , 15 shown.
[0226] The detailed counting process of the counting modes mode 0 to mode 5 is as follows: Fig.16 The flowchart on the left in the figure is a program processing flowchart of the high-speed pulse input pin 1; the flowchart in the middle is a program processing flowchart of the high-speed pulse input pin or the direction change pin, and the flowchart on the right is a program processing flowchart of the reset pin;
[0227] Counting modes mode0 and mode1 belong to high-speed counters with internal direction control. The counting direction is user-defined. When counting, connect pulse pin 1 to the input port of the PLC device. The maximum counting frequency is 200kHz.
[0228] Counting modes mode2 and mode3 belong to high-speed counters with external direction control. They require 1 pulse signal and 1 direction signal to count up and down. The maximum counting frequency is 200kHz.
[0229] Counting modes mode4 and mode5 belong to dual-clock high-speed counters, including two pulse signals: one is an up-counting signal and the other is a down-counting signal. The maximum counting frequency is 200kHz.
[0230] The counting modes mode6 to mode9 are all AB quadrature phase high-speed counters, inputting two pulse signals with a phase difference of 90 degrees. The detailed counting process is described in Fig.17 and Fig.18 Listed in Fig.17 It shows the AB phase pulse counting process of counting modes mode8 and 9. Fig.18It shows the AB phase pulse counting process of counting modes mode6 and 7. The direction of pulse counting of counting modes mode6 to mode9 is selected in Fig.19 Listed in detail, mode6, mode7, mode8, mode9 counting directions all meet Fig.19 The counting direction changes in the state;
[0231] Counting modes mode6 and mode7 use hardware timer for counting, supporting 2x and 4x frequency: higher frequency pulse counting is allowed, and users can accurately read the current count value, but interrupt operation at the pulse moment of the target count value is not supported. The maximum counting frequency is the frequency of the optocoupler isolation switch. For example, the frequency of the 6N137 optocoupler isolation switch is 10MHz.
[0232] The 2x frequency counting method is to read the interrupt trigger state of the AB phase pulse. The maximum counting frequency is the frequency of the optocoupler isolation switch. For example, if a 6N137 optocoupler isolation switch is selected, its frequency is 10MHz, and only the A phase is counted.
[0233] The 4x frequency counting method is to read the interrupt trigger state of the AB phase pulse, and count on both phase A and phase B. The maximum counting frequency is the frequency of the optocoupler isolation switch. For example, the 6N137 optocoupler isolation switch has a frequency of 10MHz. The above-mentioned frequency multiplication counting method supports the user to perform interrupt operation at the pulse moment of the target count value in the case of high-speed counting.
[0234] The counting modes mode8 and mode9 use interruption to realize counting, and support 1x, 2x and 4x counting: the 1x counting mode realizes up counting and down counting by reading the rising and falling edges of the A phase pulse and the level state of the B phase, and the maximum counting frequency is 100kHz;
[0235] The 2x counting method is to read the interrupt trigger status of the AB phase pulse, the maximum counting frequency is 200kHz, and counting is only performed on the A phase;
[0236] The 4x frequency counting method is to read the interrupt trigger status of the AB phase pulse, count both phase A and phase B, and the maximum counting frequency is 400kHz. The above-mentioned frequency multiplication counting method supports the user to perform interrupt operation on the pulse moment of the target count value in the case of high-speed counting.
[0237] Application example 1:
[0238] The following application implements PWM function test, the ladder diagram program is as follows Fig. 20 As shown in the figure, the test plan is: first set the basic settings to a period of 1000 microseconds and a duty cycle of 50%, as shown in the figure. Figure 3As shown; then, when button 0 is pressed, the period increases by 1000 microseconds; when button 1 is pressed, the duty cycle decreases by 10%; the test steps are as follows:
[0239] S1: The basic settings are 1000us period and 50% duty cycle. The operation results are as follows: Fig.21 As shown;
[0240] S2: Based on S1, when the user presses button 0 once, the period of PWM0 increases by 1000us to 2000us, and the duty cycle remains 50%. The operation results are as follows: Fig. 22 As shown;
[0241] S3: Based on S2, when the user presses button 1 again, the duty cycle of PWM0 decreases by 10% to 40%, and the period remains 2000us. The operation results are as follows: Fig.23 As shown;
[0242] In summary, the operating results of S1-S3 show that the PWM function test data is accurate.
[0243] Application Example 2:
[0244] The following application implements the PTO manual mode test. The ladder diagram program is as follows: Fig.24 As shown, key 0 controls the PTO start, key 1 controls the PTO stop, the test plan is: select PTO channel 0 as the test channel, press Figure 5 The basic configuration is shown below: maximum speed 10000 pulses / s, start / stop speed 100 pulses / s, acceleration time 45ms, variable pulse number 10 pulses, single pulse cycle increment -990us / pulse, deceleration time 45ms, variable pulse number 10 pulses, single pulse cycle increment 990us / pulse; the test steps are as follows:
[0245] S4: When button 0 is pressed, PTO accelerates from the start-stop speed of 100 pulses / s to the maximum speed of 10,000 pulses / s. The results of the acceleration section are as follows: Fig.25 As shown; the uniform speed section runs at a maximum speed of 10000 pulses / s, and the running results are as follows Fig.26 As shown;
[0246] S5: When button 1 is pressed, the PTO decelerates from the maximum speed of 10,000 pulses / s to the start-stop speed of 100 pulses / s. The results of the deceleration section are as follows: Fig. 27 As shown;
[0247] In summary, the operating results of S4-S5 show that the PTO manual mode function test data is accurate.
[0248] Application Example 3:
[0249] The following application implements the PTO single-speed continuous operation mode test. The ladder diagram main program only needs to call a PTO instruction. The start program is controlled by key 0, and the stop signal subroutine is controlled by key 1. The test plan is: select PTO channel 0 as the test channel, press Figure 6 As shown in the figure, basic configuration and single-speed continuous operation configuration are performed. The basic configuration data are maximum speed 10000 pulses / s, start-stop speed 100 pulses / s, acceleration time 45ms, variable pulse number 10 pulses, single pulse cycle increment -990us / pulse, deceleration time 45ms, variable pulse number 10 pulses, single pulse cycle increment 990us / pulse; single-speed continuous operation configuration data are target speed 5000 pulses / s, stop distance 10 pulses; the test steps are as follows:
[0250] S6: When button 0 is pressed, PTO accelerates from the start-stop speed of 100 pulses / s to the target speed of 5000 pulses / s. The results of the acceleration section are as follows: Fig.28 As shown; the uniform speed section runs at the target speed of 5000 pulses / s, and the running results are as follows Fig.29 As shown;
[0251] S7: When button 1 is pressed, the PTO decelerates from the target speed of 5000 pulses / s to the start-stop speed of 100 pulses / s. The results of the deceleration section are as follows: Fig.30 As shown;
[0252] In summary, the operating results of S6-S7 show that the PTO single-speed continuous operation mode function test data is accurate.
[0253] Application example 4:
[0254] The following application implements the PTO relative position mode test. The ladder diagram main program only needs to call a PTO instruction and press key 0 to control the PTO start. The test plan is: select PTO channel 0 as the test channel and press Figure 5 Perform basic configuration as shown below. Figure 7The envelope configuration is shown in the figure; the basic configuration data is the maximum speed of 10000 pulses / s, the start and stop speed of 100 pulses / s, the acceleration time of 45ms, the number of changing pulses of 10 pulses, the single pulse cycle increment of -990us / pulse, the deceleration time of 45ms, the number of changing pulses of 10 pulses, and the single pulse cycle increment of 990us / pulse; the envelope configuration data is that PTO includes three curves. In order to facilitate observation, the parameters of each curve are set the same, but the curve settings are as follows: the first step is the target speed of 1000 pulses / s, the target position of 12 pulses, the change pulse increment of 9 pulses, and the single pulse cycle increment of -1000us / pulse; the second step is the target speed of 10000 pulses / s, the target position of 12 pulses, the change pulse increment of 9 pulses, and the single pulse cycle increment of -100us / pulse; the third step is the target speed of 1000 pulses / s, the target position of 15 pulses, the change pulse increment of 3 pulses, and the single pulse cycle increment of 300us / pulse; the test steps are as follows:
[0255] S8: When button 0 is pressed, the first step: PTO accelerates from the start-stop speed of 100 pulses / s to the target speed of 1000 pulses / s in the first step, 9 pulses are sent in the acceleration section, and 3 pulses are run at a uniform speed; the second step: accelerates from the target speed of 1000 pulses / s in the first step to the target speed of 10000 pulses / s in the second step, 9 pulses are sent in the acceleration section, and 3 pulses are run at a uniform speed; the third step: decelerates from the target speed of 10000 pulses / s in the second step to the target speed of 1000 pulses / s in the third step, 3 pulses are sent in the deceleration section 1, and 3 pulses are run at a uniform speed, and finally decelerates from the uniform speed section 1000 pulses / s to the start-stop speed of 100 pulses / s, and the deceleration section 2 runs 9 pulses; the running results of the first curve are as follows Fig.31 As shown, the running results of the three curves are as follows Fig.32 As shown;
[0256] In summary, the operating results of S8 show that the PTO relative position mode function test data is accurate.
[0257] Application example 5:
[0258] After writing the related ladder diagram of high-speed pulse counting, the main program and interrupt subroutine can be compiled into binary files and downloaded to the PLC processor. The execution flow of the program inside the PLC is as follows: Fig.12 As shown, the PLC will transfer the IDE software to Fig.13 , 14 The configured parameters are loaded into the data structure of the high-speed counter, and then the hardware resources are configured according to the counting mode of the high-speed counter, including:
[0259] The external interrupt of the first pulse pin, the external interrupt of the second pulse pin, the external interrupt of the external reset pin and the external interrupt of the external direction pin, and finally enable the interrupt function interface of the above configuration pins; Fig.16 , Fig.17 and Fig.18 The program in the flowchart is nested in the external interrupt functions of the above four pins.
[0260] Fig.16 It shows the program flow chart of counting mode mode0~mode5. The flowchart on the left is the program executed after the first pulse pin triggers the external interrupt function. If the current counting mode is in dual input mode (mode4 and mode5), the internal counting direction will be changed to upward counting, otherwise (mode0~mode3) will count directly; if the current count value CV is equal to the target count value PV, it will trigger once. Fig.15 The high-speed counting completes the interrupt function in the figure. The flowchart in the middle is the program executed after the second pulse pin or the external direction pin triggers the external interrupt function. If the current counting mode is in the dual input mode (mode4 and mode5), it will count down; if the current count value is equal to the preset value, it will trigger once. Fig.15 The high-speed counting completion interrupt function in the , if the current counting mode is in the external direction control mode (mode2 and mode3), read the current pin level state to update the current counting direction, and enter the high-speed counting direction change interrupt function. The flowchart on the right is the program executed after the reset pin triggers the external interrupt function. If the current high-speed counter is in the external reset mode (mode1 or mode3 or mode5), reset the current high-speed counter and clear the count value CV of the current high-speed counter.
[0261] The high-speed counting modes of mode6 and mode7 are based on Fig.18 The flowchart on the right side executes the program. The counting modes mode6 and mode7 support counting of ultra-high-speed pulses up to 10MHz, that is, the frequency of the optocoupler isolation switch of 6N137. This is achieved by using the external counting method of the timer. It also supports 2x and 4x counting. The rules for updating the counting direction are in Fig.19 The table lists that 6N137 high-speed communication optocoupler isolation is used in hardware, and the software end is realized by enabling the count overflow interrupt of the timer. When the target count value PV is greater than 0XFFFF, the timer pre-load value is assigned in a cyclic decreasing manner until the pre-load value is less than 0XFFFF, which triggers the count completion interrupt function. The counting direction is judged by Fig.18 The flowchart on the left is executed, and when the main function is scanned and executed, if a direction change occurs, the high-speed counting direction change interrupt function is entered.
[0262] Counting modes mode8 and mode9 use the following Fig.17 The timer input capture mode counts, supports high-speed pulses up to 400KHz for counting, and supports 1x, 2x and 4x counting. When the AB phase pin receives a pulse, read the current pulse pin level state, and then change the input capture polarity of the pin. The counting process and counting direction are based on Fig.19 1x means counting only on the A-phase pulse pin when the B-phase pulse pin level is low, 2x means counting on the A-phase pulse pin when the B-phase pulse pin level is high and low, 4x means counting on both the A-phase pulse and the B-phase pulse, when the current count value is equal to the target count value, the count completion interrupt function is entered, and when the count direction is determined to have changed, the high-speed count direction change interrupt function is entered.
[0263] Application Example 6:
[0264] The following application builds a hardware verification platform to comprehensively test the PTO and HSC related to motion control. The test steps are divided into: software and hardware preparation, function verification, oscilloscope verification, and encoder verification.
[0265] Step 1: Software and hardware preparation
[0266] like Fig.33 The following is the hardware structure diagram of the verification experiment. The actual experimental environment is as follows: Fig.34 The experimental process is: when the encoder rotates one circle, the PLC high-speed counter receives 4000 pulse signals, and at the same time, each pulse train outputs 4000 high-speed pulse signals, driving the stepper motor to rotate 5 circles; among them, the encoder sends 1000 pulses per circle, and the HSC is set to 4 times the frequency, so the PLC can read 4000 pulses for one circle of the encoder. The HSC configuration is as follows Fig.35 As shown; Among them, the PTO configuration is as follows Fig.36 , 37 As shown in the figure, the stepper motor driver is set to 800 pulses per circle. Write a ladder diagram program as follows Fig.38 As shown.
[0267] Step 2: Functional Verification
[0268] The ladder diagram program is translated and compiled to generate a binary file, which is downloaded to the SK2109 PLC through the J-link downloader. The PLC's I0.0 terminal is closed by an external button to start the PTO. At this time, the oscilloscope and the driver receive the pulse signal. After receiving the pulse signal, the driver controls the stepper motor to operate. The stepper motor drives the encoder to rotate through the transmission device. The SK2109 PLC receives the data transmitted by the encoder through the high-speed counter function, and finally transmits the data to the computer through RS485.
[0269] Step 3: Oscilloscope Verification
[0270] The entire PTO waveform received by the oscilloscope from the PLC port is as follows: Fig.39 As shown in the figure, the upper left is a PTO output waveform, the upper right is the PTO maximum target speed output waveform, the lower left is the PTO acceleration output waveform, and the lower right is the PTO deceleration output waveform. After comparison, the number of pulses in this image is 4000, the maximum target speed cycle is 50us, etc. These parameters are consistent with the settings in the PTO human-computer interaction.
[0271] Step 4: Encoder Verification
[0272] The computer receives the signal transmitted by the encoder to the PLC through RS485. The signal speed diagram received by the computer in a PTO section is as follows: Fig.40 As shown, the horizontal axis is the number of pulses and the vertical axis is the speed. Its waveform is basically consistent with the speed change curve set in the envelope. In this section of PTO, the PLC received a total of 20,000 encoder signals. According to the settings of the encoder and high-speed counter, the encoder rotated five times at this time, so the stepper motor drove the encoder to rotate five times. At this time, it is inferred that the stepper motor driver received a total of 20,000 high-speed pulse signals. This parameter is consistent with the settings in the PTO human-computer interaction.
Claims
1. A PLC instruction design method suitable for motion control, characterized in that: Including the design of high-speed pulse output instructions and the design of high-speed pulse input instructions; The design of the high-speed pulse output instruction includes: the PWM instruction and the PTO instruction share the high-speed output port; The PTO instruction includes three high-speed pulse output modes: manual mode, single-speed continuous operation mode and relative position mode; the manual mode manually starts and stops the high-speed pulse output through the switch button; the single-speed continuous operation mode refers to continuous operation at a fixed target speed; the relative position mode refers to setting the parameters of an envelope motion curve by the method of relative calculation of position, with the starting point of each step as the relative zero point; The methods for calling PWM instructions through compiled IDE software include: (1-1) Initialize the relevant parameters of the PWM instruction: The related parameters include name, PWM channel, pin description, cycle, value range, duty cycle and remarks; the name is an alias for the PWM instruction function; the PWM channel is used to select the PWM hardware resource defined in the database; the pin description is used to describe the specific PLC position in the selected PWM channel, wherein the data of the pin description is obtained by querying the hardware resource configuration database; the cycle is set according to the value range, and the unit is optional; the duty cycle is the set duty cycle data; the remarks are used to add descriptions; (1-2) Initialize the PWM data structure: The PWM data structure includes a Boolean unit variable, a floating-point duty cycle variable, an integer period variable and a PWM pin variable; The compiled IDE software parses the relevant parameters of the PWM instruction in step (1-1) into the PWM data structure to initialize the PWM data structure. The parsing method is as follows: the period and duty cycle in step (1-1) are directly assigned to the integer period variable and integer period variable in the PWM data structure respectively; the unit of the period selection in step (1-1) is directly assigned to the Boolean unit variable in the PWM data structure: when the value is true, it represents microseconds; when the value is false, it represents milliseconds; the pin data of the PWM channel configuration in step (1-1) is assigned to the PWM pin variable in the PWM data structure; (1-3) PWM drive interface It is used to realize the pulse width modulation function of PWM, and the user data required in the driving implementation process is the PWM data structure initialized in step (1-2); the PWM driving interface includes: PWM initialization configuration interface PWM_Config(), PWM cycle update interface PWM_Cycle_Update() and PWM duty ratio update interface PWM_DutyRatio_Update(); The methods for calling PTO instructions through compiled IDE software include: (2-1) Initialize the relevant parameters of the PTO instruction: The related parameters include basic configuration parameters and further configuration parameters for each mode; The basic configuration parameters include basic information, setting port, motor speed, acceleration setting and deceleration setting; the basic information includes name and remarks; the name is an alias for the PTO instruction function; the remarks are used to add instructions; the setting port is a high-speed pulse output port configured in the database, shared with the PWM port, but not compatible, and a fault-tolerant reminder is set; the motor speed includes the maximum speed, start-stop speed and minimum speed, where the value of the minimum speed is the same as the start-stop speed, and the unit is pulse / second; the acceleration setting and deceleration setting include acceleration time t, change pulse number ΔN and single pulse cycle increment ΔT; the acceleration time t is in milliseconds; the change pulse number ΔN is in pulses; the single pulse cycle increment ΔT is in microseconds / pulse; where the termination period T m The relationship between the five variables, starting cycle T0, acceleration time t, change pulse number ΔN and single pulse cycle increment ΔT, is shown in formulas (I) and (II). m is the reciprocal of the corresponding end frequency; the starting period T0 is the reciprocal of the corresponding start frequency; Methods for further configuration of each mode include: When the manual mode is selected, only the basic configuration parameters are required; When configuring acceleration and deceleration, if the maximum speed and start / stop speed have been configured, the three variables of single pulse cycle increment, number of pulse changes, and acceleration / deceleration time are automatically calculated according to the formula. As long as any one variable is entered, the other two variables will automatically change, which can greatly reduce the tedious calculations and unit conversions of programmers. When the single-speed continuous operation mode is selected, the configuration includes: target speed, stop distance; the unit of the target speed is pulse / second; the unit of the stop distance is pulse, and the stop distance can only be configured when the check box for stop signal is selected; the stop signal refers to the high-speed pulse signal that triggers the PTO to stop outputting in the single-speed continuous operation mode; When the relative position mode is selected, the configuration includes: adding envelope, adding step, modifying, deleting and exporting envelope; the adding envelope is used to automatically add an envelope and name the envelope; the adding step is used to add a step to the current envelope; the modifying is used to modify the step data after selecting a step; the deleting is used to delete the currently selected step after selecting a step; the exporting envelope is used to export and encapsulate the current envelope into an envelope library to customize and call standardized curves; Drag the PTO instruction to the editing area of the compiled IDE software, and the dialog box that pops up automatically is used to configure the relevant parameters of the PTO instruction, including basic configuration and further configuration for each mode; (2-2) Initialize the PTO data structure: The PTO data structure includes a PTO pin variable, an integer maximum cycle variable, an integer start-stop cycle variable, a floating-point single pulse cycle increment, an integer working mode variable, a single-speed continuous operation mode structure, and a relative position mode structure; The single-speed continuous operation mode structure includes a Boolean stop flag variable and an integer target period variable; the relative position mode structure includes an integer envelope total number variable and an envelope structure; the envelope structure includes an integer total step number variable and a step structure; the step structure includes an integer start period, a target period, and a preset pulse variable; The compiled IDE software parses the relevant parameters of the PTO instruction in step (2-1) into the PTO data structure and initializes the PTO data structure. The parsing method is as follows: assign the port data set in step (2-1) to the PTO pin variable in the PTO data structure; convert the maximum speed in step (2-1) into the maximum period variable of the PTO data structure in microseconds; convert the start and stop speed in step (2-1) into the start and stop period variable of the PTO data structure in microseconds; directly assign the single pulse period increment in step (2-1) to the single speed pulse period increment in the PTO data structure; parse the configuration mode in step (2-1) into the working mode variable in the PTO data structure: the value of 1 represents the manual mode; the value of 2 represents the single speed continuous operation mode; the value of 3 represents the relative position mode; convert the target speed of the single speed mode configuration in step (2-1) into the period variable in microseconds. Assign to the target cycle variable in the single-speed continuous operation mode structure, and assign the stop signal selected in the check box to the stop flag: the value of true represents the stop signal selection; the value of false represents the stop signal is not selected; the total number of envelopes configured in the relative position mode in step (2-1) is counted and assigned to the total number of envelopes variable in the relative position mode structure; the total number of steps configured in the relative position mode in step (2-1) is counted and assigned to the total number of steps in the envelope structure; the single-step target speed configured in the relative position mode in step (2-1) is converted into the target cycle variable in the step structure in microseconds; the single-step target position configured in the relative position mode in step (2-1) is directly assigned to the preset pulse variable in the step structure; the target speed of the previous step configured in the relative position mode in step (2-1) is converted into the starting cycle variable in the step structure in microseconds; the starting cycle of the first step is the start-stop cycle value in the basic setting; (2-3)PTO drive interface It is used to realize the pulse transmission function of PTO, and the user data required in the driving implementation process is the PTO data structure initialized in step (2-2); the PTO driving interface includes the PTO initialization configuration interface PTO_Config(), the PTO start interface StartPTO(), and the PTO stop interface StopPTO().
2. A PLC instruction design method suitable for motion control according to claim 1, characterized in that: In the step (2-3), in order to make the acceleration and deceleration of the PTO smoother, an S-curve algorithm is added to the functions corresponding to the PTO start interface StartPTO() and the PTO stop interface StopPTO() so that the acceleration does not change suddenly.
3. A PLC instruction design method suitable for motion control according to claim 2, characterized in that: The S-curve algorithm includes an acceleration segment, a deceleration segment, an acceleration / deceleration segment, and a deceleration / deceleration segment, and the S-curve algorithm includes formula (III), formula (IV), and formula (V); The rate of change of acceleration k is fixed and is obtained by the parameters Cn, C0 and n set in the human-computer interaction design: In formula (III), k is the rate of change of acceleration, which is fixed; Cn, C0, and n are the corresponding period of the target frequency, the corresponding period of the starting speed, and the number of pulses during speed change, respectively; The acceleration is divided into two change stages, one is a linear change according to the change rate k in the first half of the speed change stage; the other is a linear change in the second half of the speed change stage; the direction of the acceleration is determined by the acceleration and deceleration stages of the PTO, which is positive during acceleration and negative during deceleration; the magnitude of the acceleration is shown in formula (IV): In formula (IV): x, a x They are the current pulse number and the acceleration magnitude of the current pulse respectively; The relationship between the cycles is: C x =C x-1 +a x (Ⅴ) In formula (V): C x , C x-1 They are the period of the current pulse and the period of the previous pulse respectively.
4. A PLC instruction design method suitable for motion control according to claim 1, characterized in that: The further configuration also includes: curve drawing, which is used to set a curve schematic diagram that is automatically drawn at each step, and the diagram includes an x-coordinate, a y-coordinate, a preset total number of pulses, and a maximum speed of the curve; the x-coordinate refers to the relative position of the operation, in units of pulses; the y-coordinate refers to the operation speed, in units of pulses / s; the preset total number of pulses refers to the sum of the position data set in all steps within an envelope curve, marked on the x-coordinate axis; the maximum speed of the curve refers to the preset maximum target speed within an envelope curve, marked on the y-coordinate axis.
5. A PLC instruction design method suitable for motion control according to claim 1, characterized in that: The adding step is a dialog box for adding a step, including adding a position, a target speed, a target position, a change pulse increment and a single pulse cycle increment; The added position refers to adding after the position row; the change pulse increment and the single pulse cycle increment are the change pulse increment and the single pulse cycle increment in the basic configuration by default, or the change pulse increment and the single pulse cycle increment are calculated and adjusted in conjunction with formulas (I) and (II). As long as one of the variables is changed, the other variable is automatically updated.
6. A PLC instruction design method suitable for motion control according to claim 1, characterized in that: The design method also includes a PTO driving step: (3-1) Drive the initialization pin and enable interrupt; (3-2) The operations of different working modes are as follows: In manual mode, when the PTO is started, the pulse starts from the start-stop speed, and smoothly accelerates to the maximum speed according to the single pulse cycle increment value configured in the acceleration configuration in the basic configuration, and continues to run at the maximum speed after reaching the maximum speed; when the PTO is stopped, the PTO pulse starts from the maximum speed, and smoothly decelerates to the start-stop speed according to the single pulse cycle increment value configured in the deceleration configuration in the basic configuration, and then stops the PTO output, and the PTO drive step closes the interrupt; In single-speed continuous operation mode, when PTO is started, the pulse starts from the start-stop speed, and smoothly accelerates to the target speed according to the single pulse cycle increment value of the acceleration configuration in the basic configuration. After reaching the target speed, it continues to run at the target speed; when the stop signal activation stop is not selected, the PTO stops abnormally; When the stop signal is selected to activate the stop, the PTO stops smoothly according to the configured stop distance; if the stop distance is set to 0, it stops immediately and the PTO drive step is closed and interrupted; In relative position mode, after starting PTO, the PTO drive steps are executed in sequence according to the set envelope data. During the execution, the pulse count value and real-time cycle are updated in real time. When the pulse count value reaches the preset total number of pulses, PTO stops and triggers the PTO count completion interrupt. Finally, the PTO drive step closes the interrupt.
7. A PLC instruction design method suitable for motion control according to claim 1, characterized in that: The design of the high-speed pulse input instruction includes: the compiled IDE software stores the PLC hardware resources configured by the high-speed pulse input instruction in the database, and the user calls the high-speed counter module at the compiled IDE software end to perform relevant ladder diagram programs. The high-speed counter module includes the following high-speed pulse input counting modes: mode0: Unidirectional high-speed counter with internal direction control and no external reset; mode1: Unidirectional high-speed counter with internal direction control and external reset; mode2: Unidirectional high-speed counter with external direction control and no external reset; mode3: Unidirectional high-speed counter with external direction control and external reset; mode4: Bidirectional high-speed counter with two clock inputs and no external reset; mode5: Bidirectional high-speed counter with two clock inputs and external reset; mode6 / 8: Bidirectional high-speed counter with AB quadrature phase and no external reset; mode7 / 9: Bidirectional high-speed counter with AB quadrature phase and external reset.
8. A PLC instruction design method suitable for motion control according to claim 7, characterized in that: The design of the high-speed pulse input instruction also includes: 1) The compiled IDE software translates the configuration parameters of the ladder diagram related to the high-speed counter defined by the user into C language; 2) Initialize the counting modes mode0 - mode9 of the high-speed pulse input; 3) Configure the data structure of the high-speed counter defined by the compiled IDE software, including the following parameters: Counting mode mode, current count value CV, target count value PV, control word, status word, pulse pin 1, pulse pin 2, direction pin, and reset pin; the control word includes counting direction, enable, and counting rate; the status word includes counting direction status, CV < PV status, CV = PV status, and CV > PV status; 4) Define the pins of the high-speed counter according to the selected counting mode. In different counting modes, the initialized pins are different: When selecting counting modes mode0 - mode9, the first pulse pin is initialized; When selecting counting modes mode4 - mode9, the second pulse pin is initialized; When selecting counting modes mode1, mode3, mode5, mode7, mode9, the external reset pin is initialized; When selecting counting modes mode2 and mode3, the external direction pin is initialized; Enable the external interrupt interfaces of the configured pulse pins, direction pins, and reset pins in sequence; The high-speed counters selected for counting modes mode0 - mode9 all have three interrupt function interfaces: count completion interrupt, count direction change interrupt, and count reset interrupt; the above three high-speed counter interrupt programs are respectively nested inside the external interrupt interfaces of the pulse pins, direction pins, and reset pins. Among them, the count completion interrupt function is nested in the interrupt interface of the pulse counting pin, the count direction change interrupt function is nested in the external direction change pin interrupt interface, and the count reset interrupt function is nested in the external reset interrupt interface; The count completion interrupt of counting modes mode6 and mode7 is nested in the interrupt interface of timer count overflow, and the count direction change interrupt is implemented by the main function scanning method; The count completion interrupt and count direction change interrupt of counting modes mode8 and mode9 are nested in the timer input capture interrupt interface.
9. A PLC instruction design method suitable for motion control according to claim 7 or 8, characterized in that: Counting modes mode0 and mode1 belong to high-speed counters with internal direction control. The counting direction is user-defined. When counting, connect pulse pin 1 to the input port of the PLC device. The maximum counting frequency is 200kHz. Counting modes mode2 and mode3 belong to high-speed counters with external direction control. They require 1 pulse signal and 1 direction signal to count up and down. The maximum counting frequency is 200kHz. Counting modes mode4 and mode5 belong to dual-clock high-speed counters, including two pulse signals: one is an up-counting signal and the other is a down-counting signal. The maximum counting frequency is 200kHz.
10. A PLC instruction design method suitable for motion control according to claim 7 or 8, characterized in that: The counting modes mode6 to mode9 all belong to AB quadrature phase high-speed counters, inputting two pulse signals with a phase difference of 90 degrees; Counting modes mode6 and mode7 use hardware timer for counting, supporting 2x and 4x frequency: allowing higher frequency pulse counting, and the maximum counting frequency is the optocoupler isolation switch frequency; The 2x frequency counting method is to read the interrupt trigger state of the AB phase pulse, and the maximum counting frequency is the optocoupler isolation switch frequency; The 4x frequency counting method is to read the interrupt trigger state of the AB phase pulse, count both phase A and phase B, and the maximum counting frequency is the optocoupler isolation switch frequency. The above-mentioned frequency multiplication counting method supports the user to perform interrupt operation at the pulse moment of the target count value in the case of high-speed counting; The counting modes mode8 and mode9 use interruption to realize counting, and support 1x, 2x and 4x counting: the 1x counting mode realizes up counting and down counting by reading the rising and falling edges of the A phase pulse and the level state of the B phase, and the maximum counting frequency is 100kHz; The 2x counting method is to read the interrupt trigger status of the AB phase pulse, the maximum counting frequency is 200kHz, and counting is only performed on the A phase; The 4x frequency counting method is to read the interrupt trigger status of the AB phase pulse, count both phase A and phase B, and the maximum counting frequency is 400kHz. The above-mentioned frequency multiplication counting method supports the user to perform interrupt operation on the pulse moment of the target count value in the case of high-speed counting.
