Pulse generation method and device, electronic equipment and computer program product
By dynamically adjusting pulse generation by the calculated pulse generation parameters, the problem of low motion control accuracy and smoothness when the total pulse width is less than the control cycle is solved, and precise control of the motor and smoothness of the motion trajectory are achieved.
Patent Information
- Application Number
- CN202411798693.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-04-15
AI Technical Summary
In motion control, when the total pulse width is less than the control period, the pulse width of the last pulse is not fixed, resulting in a decrease in the accuracy and smoothness of the motion control.
By calculating the pulse generation parameters of the current control cycle, including the pulse frequency word, the frequency start word and the frequency increase word, and when the value of the pulse frequency word is detected to be greater than or equal to the value of the clock frequency, a pulse is generated.
Dynamically adjust the pulse generation parameters to adapt to the changes in pulse demand during different control cycles, ensure that the timing of pulse generation is more refined, avoid sudden changes in pulse width, achieve accurate control of the motor, and ensure the smoothness of the motion trajectory and the accuracy of the position.
Smart Images

Figure CN119834768A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of motion control technology, and in particular to a pulse generation method, device, electronic device and computer program product. Background Art
[0002] With the rapid development of industrial automation and precision manufacturing technology, motion control is increasingly used in modern industrial production. From precision machinery to industrial robots, and then to CNC machine tools, high-precision and smooth motion control has become a key factor in improving production efficiency and product quality. One of the core technologies of motion control is pulse generation technology, which can achieve precise positioning of mechanical parts and smooth control of motion trajectory by precisely controlling the pulse signal of the motor.
[0003] In motion control, the control cycle is the basic time unit for pulse generation. The microprocessor precalculates the number of pulses required to be generated in each control cycle, and then sends the number of pulses to the firmware. The firmware generates a corresponding number of pulses within the control cycle based on the number of pulses.
[0004] However, this method can only ensure that the number of pulses generated in a single control cycle is consistent with the number of pulses sent by the microprocessor, but when the total pulse width is less than the control cycle, the pulse width of the last pulse is not fixed, resulting in reduced accuracy and smoothness of motion control. Summary of the invention
[0005] The main purpose of the present application is to provide a pulse generation method, device, electronic device and computer program product, aiming to solve the technical problem of low accuracy and smoothness of motion control when the total pulse width is less than the control period.
[0006] To achieve the above object, the present application provides a pulse generation method, the pulse generation method comprising:
[0007] According to the number of pulses in the previous control cycle, the number of pulses in the current control cycle and the preset pulse step proportional coefficient, the pulse generation parameters of the current control cycle are calculated, wherein the pulse generation parameters include a pulse frequency word, a frequency start word and a frequency increase word, the value of the pulse frequency word is equal to the value of the frequency start word, the current control cycle includes multiple pulse single-segment times, and the pulse single-segment time includes at least one clock cycle;
[0008] Each time a new clock cycle is entered, the value of the pulse frequency word is added to the value of the frequency start word to obtain a new pulse frequency word; each time a new pulse single period is entered, the value of the frequency start word is added to the value of the frequency increase word to obtain a new frequency start word; whenever it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, the value of the pulse frequency word is subtracted from the value of the clock frequency to obtain a new pulse frequency word;
[0009] When it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, a pulse is generated.
[0010] In one embodiment, the step of calculating the pulse generation parameters of the current control cycle according to the number of pulses of the previous control cycle, the number of pulses of the current control cycle and a preset pulse step proportional coefficient includes:
[0011] Acquire a frequency coefficient of a control cycle, wherein the frequency coefficient represents the number of control cycles per unit time;
[0012] According to the frequency coefficient, the number of pulses in the previous control cycle, the number of pulses in the current control cycle and the preset pulse step proportional coefficient, the frequency start word is calculated by a preset frequency start word calculation formula, the frequency increase word is calculated by a preset frequency increase word calculation formula, and the value of the frequency start word is used as the value of the pulse frequency word;
[0013] Wherein, the frequency starting word calculation formula is:
[0014] Freq_start=((Pulse_para*Pulse1+Pulse2) / 2)*Freq_para;
[0015] The frequency increase word calculation formula is:
[0016] Freq_add=((-Pulse_para*Pulse1+Pulse2)*2)*Freq_para;
[0017] Among them, Freq_start is the frequency start word, Freq_add is the frequency increase word, Freq_para is the frequency coefficient, Pulse_para is the preset pulse step proportional coefficient, Pulse1 is the number of pulses in the previous control cycle, and Pulse2 is the number of pulses in the current control cycle.
[0018] In one embodiment, the method further comprises:
[0019] Based on the preset pulse segmentation parameters, the current control cycle is divided into multiple pulse single-segment times.
[0020] In one embodiment, the method further comprises:
[0021] Based on the preset pulse segmentation parameters, the current control cycle is divided into a plurality of pulse single segment times and a pulse residual time, wherein the pulse residual time is located between two pulse single segment times.
[0022] In one embodiment, the preset pulse segmentation parameters include the number of pulse single segment times, and the step of dividing the current control cycle into a plurality of pulse single segment times and a pulse residual time based on the preset pulse segmentation parameters includes:
[0023] The duration of the current control cycle is taken as the dividend, and the number of pulse single-segment times is taken as the divisor. The duration of the pulse single-segment time is obtained through integer division operation, and the duration of the pulse residual time is obtained through modulo operation;
[0024] According to the number of pulse single-segment times, the duration of the pulse single-segment time and the duration of the pulse residual time, the current control cycle is divided into a plurality of pulse single-segment times and one pulse residual time.
[0025] In one embodiment, the preset pulse segmentation parameter is the duration of a pulse single segment time, and the step of dividing the current control cycle into a plurality of pulse single segment times and a pulse residual time based on the preset pulse segmentation parameter includes:
[0026] The duration of the current control cycle is taken as the dividend, and the duration of the pulse single segment time is taken as the divisor. The number of pulse single segment times is obtained through integer division operation, and the duration of the pulse residual time is obtained through modulo operation;
[0027] According to the number of pulse single-segment times, the duration of the pulse single-segment time and the duration of the pulse residual time, the current control cycle is divided into a plurality of pulse single-segment times and one pulse residual time.
[0028] In one embodiment, the number of pulse independent times is N, where N is a positive integer greater than 1;
[0029] When N is an even number, the pulse residual time is between the N / 2th pulse single segment time and the N / 2+1th pulse single segment time;
[0030] When N is an odd number, the pulse difference time is between the (N+1) / 2th pulse single segment time and the (N+3) / 2th pulse single segment time.
[0031] In addition, to achieve the above-mentioned purpose, the present application also provides a pulse generating device, the pulse generating device comprising:
[0032] A parameter calculation module, used for calculating the pulse generation parameters of the current control cycle according to the number of pulses of the previous control cycle, the number of pulses of the current control cycle and the preset pulse step proportional coefficient, wherein the pulse generation parameters include a pulse frequency word, a frequency start word and a frequency increase word, the value of the pulse frequency word is equal to the value of the frequency start word, the current control cycle includes a plurality of pulse single-segment times, and the pulse single-segment time includes at least one clock cycle;
[0033] The frequency update module is used to add the value of the pulse frequency word to the value of the frequency start word every time a new clock cycle is entered to obtain a new pulse frequency word; every time a new pulse single period is entered, the value of the frequency start word is added to the value of the frequency increase word to obtain a new frequency start word; whenever it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, the value of the pulse frequency word is subtracted from the value of the clock frequency to obtain a new pulse frequency word;
[0034] The pulse generating module is used to generate a pulse when it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency.
[0035] In addition, to achieve the above-mentioned purpose, the present application also provides an electronic device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the computer program is executed by the processor, the steps of the pulse generation method as described above are implemented.
[0036] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the pulse generation method as described above are implemented.
[0037] The embodiments of the present application provide a pulse generation method, device, electronic device and computer program product. The technical solution of the embodiments of the present application is to calculate the pulse generation parameters of the current control cycle according to the number of pulses in the previous control cycle, the number of pulses in the current control cycle and the preset pulse step proportional coefficient, wherein the pulse generation parameters include a pulse frequency word, a frequency start word and a frequency increase word, the value of the pulse frequency word is equal to the value of the frequency start word, the current control cycle includes multiple pulse single-segment times, and the pulse single-segment time includes at least one clock cycle; each time a new clock cycle is entered, the value of the pulse frequency word is added to the value of the frequency start word to obtain a new pulse frequency word; each time a new pulse single-segment time is entered, the value of the frequency start word is added to the value of the frequency increase word Add to obtain a new frequency starting word; whenever it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, subtract the value of the pulse frequency word from the value of the clock frequency to obtain a new pulse frequency word; when it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, generate a pulse, so that the present application can dynamically adjust the pulse generation parameters to adapt to the changes in pulse demand in different control cycles, more finely control the timing of pulse generation, avoid sudden changes in pulse width caused by too long a control cycle, and ensure that even when the total pulse width is less than the control cycle, the motor can be accurately controlled to ensure the smoothness of the motion trajectory and the accuracy of the position, thereby solving the technical problem of low precision and smoothness of motion control when the total pulse width is less than the control cycle. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0039] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying any creative work.
[0040] Figure 1 A schematic diagram of a flow chart of a first embodiment of a pulse generation method of the present application;
[0041] Figure 2 A schematic diagram of a flow chart of a second embodiment of a pulse generation method of the present application;
[0042] Figure 3 A schematic diagram of a flow chart of a third embodiment of a pulse generation method of the present application;
[0043] Figure 4 This is a schematic diagram of the module structure of the pulse generating device according to an embodiment of the present application;
[0044] Figure 5 Schematic diagram of the device structure of the hardware operating environment involved in the pulse generation method in the embodiment of the present application.
[0045] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0046] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0047] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0048] At present, the traditional pulse generation method can only ensure that the number of pulses generated in a single control cycle is consistent with the number of pulses sent by the microprocessor. However, when the total pulse width is less than the control cycle, the pulse width of the last pulse is not fixed, resulting in reduced accuracy and smoothness of motion control.
[0049] The main solution of the embodiment of the present application is: according to the number of pulses in the previous control cycle, the number of pulses in the current control cycle and the preset pulse step proportional coefficient, the pulse generation parameters of the current control cycle are calculated, wherein the pulse generation parameters include a pulse frequency word, a frequency start word and a frequency increase word, the value of the pulse frequency word is equal to the value of the frequency start word, the current control cycle includes multiple pulse single-segment times, and the pulse single-segment time includes at least one clock cycle; every time a new clock cycle is entered, the value of the pulse frequency word is added to the value of the frequency start word to obtain a new pulse frequency word; every time a new pulse single-segment time is entered, the value of the frequency start word is added to the value of the frequency increase word to obtain a new frequency start word; whenever it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, the value of the pulse frequency word is subtracted from the value of the clock frequency to obtain a new pulse frequency word; when it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, a pulse is generated.
[0050] The embodiments of the present application can dynamically adjust the pulse generation parameters to adapt to the changes in pulse demand within different control cycles, more finely control the timing of pulse generation, avoid sudden changes in pulse width caused by too long a control cycle, and ensure that even when the total pulse width is less than the control cycle, the motor can be accurately controlled to ensure the smoothness of the motion trajectory and the accuracy of the position, thereby solving the technical problem of low precision and smoothness of motion control when the total pulse width is less than the control cycle.
[0051] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0052] This application proposes a pulse generation method of the first embodiment, please refer to Figure 1 , Figure 1 A schematic diagram of a flow chart of the first embodiment of the pulse generation method of the present application.
[0053] In this embodiment, the pulse generation method includes steps S100 to S300:
[0054] Step S100, according to the number of pulses in the previous control cycle, the number of pulses in the current control cycle and the preset pulse step proportional coefficient, the pulse generation parameters of the current control cycle are calculated, wherein the pulse generation parameters include a pulse frequency word, a frequency start word and a frequency increase word, the value of the pulse frequency word is equal to the value of the frequency start word, the current control cycle includes a plurality of pulse single-segment times, and the pulse single-segment time includes at least one clock cycle;
[0055] Step S200, each time a new clock cycle is entered, the value of the pulse frequency word is added to the value of the frequency start word to obtain a new pulse frequency word; each time a new pulse single period is entered, the value of the frequency start word is added to the value of the frequency increase word to obtain a new frequency start word; whenever it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, the value of the pulse frequency word is subtracted from the value of the clock frequency to obtain a new pulse frequency word;
[0056] Step S300, generating a pulse when it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency.
[0057] It is known to those skilled in the art that the control cycle refers to the basic time unit in the motion control system, and a certain number of pulses need to be generated in each control cycle to control the movement of the motor. The control cycle determines the response speed and accuracy of the system to motion control. In a control cycle, the system calculates the number of pulses that need to be generated according to a predetermined algorithm and sends it to the actuator (such as a motor). The number of pulses refers to the number of pulses that need to be generated in each control cycle. The number of pulses directly affects the movement speed and position of the motor. By accurately controlling the number of pulses in each control cycle, precise positioning and speed control of the motor movement can be achieved. The clock cycle is the most basic time unit in the system, usually determined by the clock signal. The clock cycle determines the minimum time resolution of the system and is the basis for pulse generation and control. In each clock cycle, the system decides whether to generate a pulse based on the current pulse generation parameters.
[0058] It should be noted that, in this embodiment, the pulse generation parameters are a set of parameters for controlling the pulse generation process, including at least a pulse frequency word, a frequency start word, and a frequency increase word. By dynamically adjusting the pulse generation parameters, it can be ensured that the pulse generated in each control cycle can meet the requirements of high precision and smoothness.
[0059] Among them, the pulse frequency word is a numerical value used to determine the timing of pulse generation, and its initial value is the same as the frequency start word. The frequency start word is the starting frequency value of pulse generation, and is also the initial value of the pulse frequency word. It is used to initialize the pulse generation process of the current control cycle and gradually increase in each pulse single segment time to adapt to different pulse generation requirements. The frequency increase word is the incremental value of the frequency start word in each pulse single segment time, and is used to gradually increase the frequency start word in each pulse single segment time, thereby achieving smooth transition and precise control of pulse generation.
[0060] It should also be noted that, in this embodiment, the pulse step proportional coefficient is a preset proportional coefficient, which is used to adjust the pulse generation parameters to adapt to different motion control requirements, smooth the pulse generation process, and ensure the smooth transition of pulse generation between different control cycles, thereby improving the accuracy and stability of motion control. The pulse single segment time refers to multiple time periods divided within the control cycle, and each time period contains at least one clock cycle. The division of the pulse single segment time allows this embodiment to more finely control the generation of pulses within each small time period, thereby improving the overall motion control accuracy and smoothness.
[0061] This embodiment calculates the pulse generation parameters of the current control cycle by considering the number of pulses in the previous control cycle, the number of pulses in the current control cycle and the preset pulse step proportional coefficient, thereby making pulse generation more flexible and accurate, ensuring that the pulse generation parameters can adapt to changes in pulse demand in different control cycles, and improving the adaptability and robustness of the system.
[0062] This embodiment dynamically adjusts the pulse frequency word and the frequency start word in each clock cycle and pulse single segment time, generates a pulse when it detects that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, subtracts the pulse frequency word from the clock frequency, and re-accumulates the pulse frequency word to ensure that the generation timing of the next pulse is based on the current accumulated value, thereby more finely controlling the generation timing of the pulse and improving the resolution of pulse generation, so that even when the total pulse width is less than the control period, accurate pulses can be generated, avoiding sudden changes in pulse width due to too long a control period, thereby significantly improving the accuracy and smoothness of motion control, and improving production efficiency and product quality.
[0063] This embodiment calculates the pulse generation parameters of the current control cycle according to the number of pulses in the previous control cycle, the number of pulses in the current control cycle and the preset pulse step proportional coefficient, wherein the pulse generation parameters include a pulse frequency word, a frequency start word and a frequency increase word, the value of the pulse frequency word is equal to the value of the frequency start word, the current control cycle includes multiple pulse single-segment times, and the pulse single-segment time includes at least one clock cycle; each time a new clock cycle is entered, the value of the pulse frequency word is added to the value of the frequency start word to obtain a new pulse frequency word; each time a new pulse single-segment time is entered, the value of the frequency start word is added to the value of the frequency increase word to obtain a new frequency start word; whenever a pulse frequency is detected When the value of the word is greater than or equal to the value of the clock frequency, the value of the pulse frequency word is subtracted from the value of the clock frequency to obtain a new pulse frequency word; when it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, a pulse is generated, so that the present embodiment can dynamically adjust the pulse generation parameters to adapt to the changes in pulse demand in different control cycles, more finely control the timing of pulse generation, avoid sudden changes in pulse width caused by too long a control cycle, and ensure that even when the total pulse width is less than the control cycle, the motor can be accurately controlled to ensure the smoothness of the motion trajectory and the accuracy of the position, thereby solving the technical problem of low precision and smoothness of motion control when the total pulse width is less than the control cycle.
[0064] In a feasible implementation manner, step S100 is a step of calculating the pulse generation parameters of the current control cycle according to the number of pulses of the previous control cycle, the number of pulses of the current control cycle and the preset pulse step proportional coefficient, which may include steps S110 to S120:
[0065] Step S110, obtaining a frequency coefficient of a control cycle, where the frequency coefficient represents the number of control cycles per unit time;
[0066] Step S120, according to the frequency coefficient, the number of pulses in the previous control cycle, the number of pulses in the current control cycle and the preset pulse step proportional coefficient, the frequency start word is calculated by the preset frequency start word calculation formula, the frequency increase word is calculated by the preset frequency increase word calculation formula, and the value of the frequency start word is used as the value of the pulse frequency word;
[0067] Among them, the frequency start word calculation formula is:
[0068] Freq_start=((Pulse_para*Pulse1+Pulse2) / 2)*Freq_para;
[0069] The frequency increase word calculation formula is:
[0070] Freq_add=((-Pulse_para*Pulse1+Pulse2)*2)*Freq_para;
[0071] Among them, Freq_start is the frequency start word, Freq_add is the frequency increase word, Freq_para is the frequency coefficient, Pulse_para is the preset pulse step proportional coefficient, Pulse1 is the number of pulses in the previous control cycle, and Pulse2 is the number of pulses in the current control cycle.
[0072] It should be noted that, in this embodiment, the frequency coefficient is used to convert the pulse requirement of the control cycle into an actual pulse generation parameter to ensure that the frequency of pulse generation matches the requirement of the control cycle.
[0073] This implementation method calculates an average frequency starting value by considering the number of pulses in the previous control cycle and the number of pulses in the current control cycle, and combines it with a preset pulse step proportional coefficient, and then multiplies this average value by the frequency coefficient to convert it into an actual frequency starting word, ensuring that the frequency of pulse generation matches the requirements of the control cycle.
[0074] In addition, this embodiment also calculates a frequency increase value by considering the number of pulses in the previous control cycle and the number of pulses in the current control cycle, and combining it with a preset pulse step proportional coefficient. This increase value is also multiplied by the frequency coefficient to convert it into an actual frequency increase word, ensuring the gradual increase of the frequency start word within each pulse single period, thereby achieving smooth pulse generation.
[0075] At the same time, this implementation uses the value of the frequency start word as the initial value of the pulse frequency word to ensure that the starting point of pulse generation is correct.
[0076] It is worth mentioning that when Freq_start calculated by the above formula has a decimal part, this embodiment can use the integer part of Freq_start as the frequency start word, and the decimal part of Freq_start as the frequency start word remainder, which is used to determine how many clock cycles are separated to perform a complement processing on the frequency start word, that is, how many clock cycles are separated, the value of the frequency start word is increased by one, or to determine how many times the complement processing needs to be performed on the frequency start word within a preset number of clock cycles, that is, how many times the value of the frequency start word is increased by one within a preset number of clock cycles. Exemplarily, when the frequency start word remainder is 0.2, it means that the value of the frequency start word is increased by one every 5 clock cycles, or the number of times the value of the frequency start word is increased by one within 10 clock cycles is 2.
[0077] It is not difficult to understand that the reciprocal of the remainder of the frequency start word can be used to determine how many intervals of the start and end cycles the value of the frequency start word is increased by one. For example, if the remainder of the frequency start word is 0.2 and the reciprocal is 5, it is determined that the value of the frequency start word is increased by one every 5 start and end cycles. In addition, the frequency start word remainder can be converted into a fraction with 10 to the power of N (N is an integer greater than 0) as the denominator and an integer as the numerator to determine how many times the value of the frequency start word is increased by one within a preset number of clock cycles. For example, if the remainder of the frequency start word is 0.33, it is converted into a fraction 33 / 100, and it is determined that the number of times the value of the frequency start word is increased by one within 100 clock cycles is 33. At this time, the first 32 times can be separated by 3 clock cycles each, and the last time can be separated by 4 clock cycles.
[0078] In a feasible implementation manner, the pulse generation method further includes step S400:
[0079] Step S400, based on the preset pulse segmentation parameters, the current control cycle is divided into a plurality of pulse single-segment times.
[0080] In this embodiment, the pulse segmentation parameter is a preset parameter used to divide the control period into smaller time units, thereby controlling the generation of pulses in smaller time units. The pulse segmentation parameter may include information such as the number and duration of a single pulse segment.
[0081] It should be noted that a control cycle is usually composed of multiple clock cycles and is the basic time unit of motion control. In the traditional pulse generation method, after the microprocessor parses the instruction, it calculates the number of pulses required to be generated in each control cycle, and sends the number of pulses and other related parameters to the firmware, which generates the pulses of the control cycle. It is impossible to subdivide it into smaller time units to perform more precise pulse generation.
[0082] This embodiment divides the control cycle into multiple smaller time units - pulse single segment times through preset pulse segment parameters. Therefore, in the process of pulse generation, each time a new pulse single segment time is entered, the value of the frequency start word is added to the value of the frequency increase word to obtain a new frequency start word, so that after the pulse frequency word enters a new pulse single segment time, the frequency start word increased in each clock cycle changes, thereby more finely controlling the generation of pulses in each small time period, improving the resolution of pulse generation, avoiding sudden changes in pulse width, and ensuring a smooth transition of pulse generation. Even when the total pulse width is less than the control period, accurate pulses can be generated, thereby improving the smoothness of motion control.
[0083] In this embodiment, since each control cycle is composed of multiple clock cycles, and the duration of each clock cycle is equal, the duration of the control cycle can be reflected by the number of clock cycles it contains. Therefore, when the current control cycle is divided into multiple pulse single-segment times, the clock cycles contained in the current control cycle are actually allocated to each pulse single-segment time. According to actual needs, the number of clock cycles allocated to each pulse single-segment time can be the same or different. Preferably, the clock cycles contained in the control cycle are evenly distributed to each pulse single-segment time to ensure that the duration of each pulse single-segment time is consistent.
[0084] In a feasible implementation, step S400 may include step S410:
[0085] Step S410, based on the preset pulse segmentation parameters, the current control cycle is divided into a plurality of pulse single segment times and a pulse residual time, wherein the pulse residual time is located between two pulse single segment times.
[0086] It is not difficult to understand that, since the clock cycle is the smallest measurable time unit in motion control, when dividing the pulse single-segment time and evenly distributing the clock cycles contained in the current control cycle to each pulse single-segment time, there is a situation where it cannot be completely evenly divided. At this time, the remaining number of clock cycles cannot guarantee that each pulse single-segment time will increase by one clock cycle. This part of the clock cycle can be separated out as a separate period of time, called the pulse difference time, and the pulse difference time is arranged between two pulse single-segment times. For example, the current control cycle includes 10 clock cycles, which need to be evenly distributed to 3 pulse single-segment times. Each pulse single-segment time is allocated to 3 clock cycles, and 1 clock cycle is left over, which is used as the pulse difference time and placed between the first pulse single-segment time and the second pulse single-segment time, or between the second pulse single-segment time and the third pulse single-segment time.
[0087] It should be noted that when placed between the second pulse single-segment time and the third pulse single-segment time, after the second pulse single-segment time, the pulse difference time is entered first, and the value of the frequency start word remains unchanged. After the pulse difference time, the third pulse single-segment time is entered, and the value of the frequency start word increases by the value of the frequency increase word.
[0088] In this embodiment, the pulse segmentation parameters may also include the duration of the pulse difference time.
[0089] It can be understood that in order to avoid the pulse difference time being too long as much as possible, which would cause a sudden change in the pulse width between the two previous and subsequent pulse single-segment times, the present embodiment can also divide the remaining clock cycle into multiple pulse difference times, and disperse them between each pulse single-segment time to ensure that the pulse difference times are not adjacent to each other.
[0090] In a feasible implementation manner, the preset pulse segmentation parameters include the number of pulse single segment times, and step S410 may include steps S411 to S412:
[0091] Step S411, taking the duration of the current control cycle as the dividend and the number of pulse single-segment times as the divisor, obtaining the duration of the pulse single-segment time by integer division operation, and obtaining the duration of the pulse residual time by modulo operation;
[0092] Step S422, dividing the current control cycle into a plurality of pulse single-segment times and one pulse residual time according to the number of pulse single-segment times, the duration of the pulse single-segment time and the duration of the pulse residual time.
[0093] In this embodiment, the pulse segmentation parameter is the number of pulse single segment times. At this time, the length of the pulse single segment time can be determined by integer division, and then the length of the pulse residual time can be determined by modulo, thereby dividing the current control cycle into multiple pulse single segment times and one pulse residual time.
[0094] In another feasible implementation manner, the preset pulse segmentation parameters include the duration of a single pulse segment, and step S410 may include steps S413 to S414:
[0095] Step S413, taking the duration of the current control cycle as the dividend and the duration of the pulse single segment time as the divisor, obtaining the number of pulse single segment times through integer division operation, and obtaining the duration of the pulse residual time through modulo operation;
[0096] Step S414, dividing the current control cycle into a plurality of pulse single-segment times and one pulse surplus time according to the number of pulse single-segment times, the duration of the pulse single-segment time and the duration of the pulse surplus time.
[0097] In this embodiment, the pulse segmentation parameter is the length of a single pulse segment. At this time, the number of single pulse segments can be determined by integer division, and then the length of the pulse residual time can be determined by modulo taking, thereby dividing the current control cycle into multiple single pulse segments and one pulse residual time.
[0098] In a feasible implementation manner, the number of pulse single-segment times is N, where N is a positive integer greater than 1;
[0099] When N is an even number, the pulse residual time is between the N / 2th pulse single segment time and the N / 2+1th pulse single segment time;
[0100] When N is an odd number, the pulse residual time is between the (N+1) / 2th pulse single segment time and the (N+3) / 2th pulse single segment time.
[0101] In this implementation, the pulse difference time is placed in the middle of the current control cycle. When the pulse difference time does not exceed a certain clock cycle, the instability caused by the sudden change of the pulse width can be reduced to the greatest extent.
[0102] In this embodiment, N is preferably an odd number, that is, when setting the pulse segmentation parameters, the number of pulse single-segment times is preferably set to an odd number greater than 1.
[0103] In addition, please refer to Figure 4 , Figure 4 This is a schematic diagram of the module structure of the pulse generating device according to an embodiment of the present application.
[0104] The embodiment of the present application also provides a pulse generating device, the pulse generating device comprising:
[0105] A parameter calculation module 10 is used to calculate the pulse generation parameters of the current control cycle according to the number of pulses in the previous control cycle, the number of pulses in the current control cycle and a preset pulse step proportional coefficient, wherein the pulse generation parameters include a pulse frequency word, a frequency start word and a frequency increase word, the value of the pulse frequency word is equal to the value of the frequency start word, the current control cycle includes multiple pulse single-segment times, and the pulse single-segment time includes at least one clock cycle;
[0106] The frequency update module 20 is used to add the value of the pulse frequency word to the value of the frequency start word every time a new clock cycle is entered to obtain a new pulse frequency word; add the value of the frequency start word to the value of the frequency increase word every time a new pulse single period is entered to obtain a new frequency start word; whenever it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, subtract the value of the pulse frequency word from the value of the clock frequency to obtain a new pulse frequency word;
[0107] The pulse generating module 30 is used to generate a pulse when it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency.
[0108] In one embodiment, the parameter calculation module 10 is further used for:
[0109] Obtain a frequency coefficient of a control cycle, where the frequency coefficient represents the number of control cycles per unit time;
[0110] According to the frequency coefficient, the number of pulses in the previous control cycle, the number of pulses in the current control cycle and the preset pulse step proportional coefficient, the frequency start word is calculated by the preset frequency start word calculation formula, the frequency increase word is calculated by the preset frequency increase word calculation formula, and the value of the frequency start word is used as the value of the pulse frequency word;
[0111] Among them, the frequency start word calculation formula is:
[0112] Freq_start=((Pulse_para*Pulse1+Pulse2) / 2)*Freq_para;
[0113] The frequency increase word calculation formula is:
[0114] Freq_add=((-Pulse_para*Pulse1+Pulse2)*2)*Freq_para;
[0115] Among them, Freq_start is the frequency start word, Freq_add is the frequency increase word, Freq_para is the frequency coefficient, Pulse_para is the preset pulse step proportional coefficient, Pulse1 is the number of pulses in the previous control cycle, and Pulse2 is the number of pulses in the current control cycle.
[0116] In one embodiment, the pulse generating device further includes a pulse segmentation module (not shown) for dividing the current control cycle into a plurality of pulse single-segment times based on preset pulse segmentation parameters.
[0117] In one embodiment, the pulse segmentation module is further configured to:
[0118] Based on the preset pulse segmentation parameters, the current control cycle is divided into a plurality of pulse single segment times and a pulse residual time, wherein the pulse residual time is located between two pulse single segment times.
[0119] In one embodiment, the preset pulse segmentation parameters include the number of pulse single segment times, and the pulse segmentation module is further used to:
[0120] The duration of the current control cycle is taken as the dividend, and the number of pulse single-segment times is taken as the divisor. The duration of the pulse single-segment time is obtained through integer division operation, and the duration of the pulse residual time is obtained through modulo operation;
[0121] According to the number of pulse single-segment times, the duration of the pulse single-segment time and the duration of the pulse residual time, the current control cycle is divided into a plurality of pulse single-segment times and one pulse residual time.
[0122] In one embodiment, the preset pulse segmentation parameter is the duration of a single pulse segment, and the pulse segmentation module is further used for:
[0123] The duration of the current control cycle is taken as the dividend, and the duration of the pulse single segment time is taken as the divisor. The number of pulse single segment times is obtained through integer division operation, and the duration of the pulse residual time is obtained through modulo operation;
[0124] According to the number of pulse single-segment times, the duration of the pulse single-segment time and the duration of the pulse residual time, the current control cycle is divided into a plurality of pulse single-segment times and one pulse residual time.
[0125] In one embodiment, the number of pulse independent times is N, where N is a positive integer greater than 1;
[0126] When N is an even number, the pulse residual time is between the N / 2th pulse single segment time and the N / 2+1th pulse single segment time;
[0127] When N is an odd number, the pulse residual time is between the (N+1) / 2th pulse single segment time and the (N+3) / 2th pulse single segment time.
[0128] The pulse generating device provided in the embodiment of the present application adopts the pulse generating method in the above embodiment, which can solve the technical problem that the accuracy and smoothness of motion control are too low when the total pulse width is less than the control period. Compared with the prior art, the beneficial effects of the pulse generating device provided in the embodiment of the present application are the same as the beneficial effects of the pulse generating method provided in the above embodiment, and the other technical features in the pulse generating device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0129] In addition, please refer to Figure 5 , Figure 5 Schematic diagram of the device structure of the hardware operating environment involved in the pulse generation method in the embodiment of the present application.
[0130] The present application also provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the steps of the pulse generation method in the above-mentioned embodiment.
[0131] Reference below Figure 5, which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present application. The electronic devices in the embodiments of the present application may include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs (Televisions), desktop computers, etc., or any electronic device capable of implementing the above functions, as well as motor control devices such as microprocessors, microcontrollers, and motion controllers. Figure 5 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0132] like Figure 5 As shown, the electronic device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the electronic device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows an electronic device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0133] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0134] The electronic device provided by the present application adopts the pulse generation method in the above embodiment, which can solve the technical problem that the accuracy and smoothness of motion control are too low when the total pulse width is less than the control period. Compared with the prior art, the beneficial effects of the electronic device provided by the present application are the same as the beneficial effects of the pulse generation method provided by the above embodiment, and other technical features in the electronic device are the same as the features disclosed by the pulse generation method in the above embodiment, which will not be repeated here.
[0135] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0136] In addition, the present application also provides a computer storage medium, which has computer-readable program instructions (ie, computer program) stored thereon, and the computer-readable program instructions are used to implement the steps of the pulse generation method in the above embodiment when executed.
[0137] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0138] The computer-readable storage medium may be included in the electronic device, or may exist independently without being installed in the electronic device.
[0139] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by an electronic device, the electronic device: calculates the pulse generation parameters of the current control cycle according to the number of pulses in the previous control cycle, the number of pulses in the current control cycle and the preset pulse step proportional coefficient, wherein the pulse generation parameters include a pulse frequency word, a frequency start word and a frequency increase word, the value of the pulse frequency word is equal to the value of the frequency start word, the current control cycle includes multiple pulse single-segment times, and the pulse single-segment time includes at least one clock cycle; each time a new clock cycle is entered, the value of the pulse frequency word is added to the value of the frequency start word to obtain a new pulse frequency word; each time a new pulse single-segment time is entered, the value of the frequency start word is added to the value of the frequency increase word to obtain a new frequency start word; whenever it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, the value of the pulse frequency word is subtracted from the value of the clock frequency to obtain a new pulse frequency word; when it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, a pulse is generated.
[0140] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0141] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0142] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0143] The computer-readable storage medium provided by the present application stores computer-readable program instructions (i.e., computer programs) for executing the steps of the pulse generation method in the above-mentioned embodiment, which can solve the technical problem that the accuracy and smoothness of motion control are too low when the total pulse width is less than the control period. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the pulse generation method provided by the above-mentioned embodiment, and are not described in detail here.
[0144] In addition, an embodiment of the present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of the pulse generation method in the above embodiment are implemented.
[0145] The computer program product provided by the present application can solve the technical problem that the accuracy and smoothness of motion control are too low when the total pulse width is less than the control period. Compared with the prior art, the beneficial effects of the computer program product provided by the embodiment of the present application are the same as the beneficial effects of the pulse generation method provided by the above embodiment, which will not be repeated here.
[0146] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A pulse generation method, characterized in that: The pulse generation method comprises: According to the number of pulses in the previous control cycle, the number of pulses in the current control cycle and the preset pulse step proportional coefficient, the pulse generation parameters of the current control cycle are calculated, wherein the pulse generation parameters include a pulse frequency word, a frequency start word and a frequency increase word, the value of the pulse frequency word is equal to the value of the frequency start word, the current control cycle includes multiple pulse single-segment times, and the pulse single-segment time includes at least one clock cycle; Each time a new clock cycle is entered, the value of the pulse frequency word is added to the value of the frequency start word to obtain a new pulse frequency word; each time a new pulse single period is entered, the value of the frequency start word is added to the value of the frequency increase word to obtain a new frequency start word; whenever it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, the value of the pulse frequency word is subtracted from the value of the clock frequency to obtain a new pulse frequency word; When it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, a pulse is generated.
2. The pulse generation method according to claim 1, characterized in that: The step of calculating the pulse generation parameters of the current control cycle according to the number of pulses of the previous control cycle, the number of pulses of the current control cycle and the preset pulse step proportional coefficient comprises: Acquire a frequency coefficient of a control cycle, wherein the frequency coefficient represents the number of control cycles per unit time; According to the frequency coefficient, the number of pulses in the previous control cycle, the number of pulses in the current control cycle and the preset pulse step proportional coefficient, the frequency start word is calculated by a preset frequency start word calculation formula, the frequency increase word is calculated by a preset frequency increase word calculation formula, and the value of the frequency start word is used as the value of the pulse frequency word; Wherein, the frequency starting word calculation formula is: Freq_start=((Pulse_para*Pulse1+Pulse2) / 2)*Freq_para; The frequency increase word calculation formula is: Freq_add=((-Pulse_para*Pulse1+Pulse2)*2)*Freq_para; Among them, Freq_start is the frequency start word, Freq_add is the frequency increase word, Freq_para is the frequency coefficient, Pulse_para is the preset pulse step proportional coefficient, Pulse1 is the number of pulses in the previous control cycle, and Pulse2 is the number of pulses in the current control cycle.
3. The pulse generation method according to claim 1, characterized in that: The method further comprises: Based on the preset pulse segmentation parameters, the current control cycle is divided into multiple pulse single-segment times.
4. The pulse generation method according to claim 3, characterized in that: The step of dividing the current control cycle into a plurality of pulse single-segment times based on the preset pulse segmentation parameters comprises: Based on the preset pulse segmentation parameters, the current control cycle is divided into a plurality of pulse single segment times and a pulse residual time, wherein the pulse residual time is located between two pulse single segment times.
5. The pulse generation method according to claim 4, characterized in that: The preset pulse segmentation parameters include the number of pulse single segment times. The step of dividing the current control cycle into a plurality of pulse single segment times and a pulse residual time based on the preset pulse segmentation parameters includes: The duration of the current control cycle is taken as the dividend, and the number of pulse single-segment times is taken as the divisor. The duration of the pulse single-segment time is obtained through integer division operation, and the duration of the pulse residual time is obtained through modulo operation; According to the number of pulse single-segment times, the duration of the pulse single-segment time and the duration of the pulse residual time, the current control cycle is divided into a plurality of pulse single-segment times and one pulse residual time.
6. The pulse generation method according to claim 4, characterized in that: The preset pulse segmentation parameter is the duration of a pulse single segment time. The step of dividing the current control cycle into a plurality of pulse single segment times and a pulse residual time based on the preset pulse segmentation parameter includes: The duration of the current control cycle is taken as the dividend, and the duration of the pulse single segment time is taken as the divisor. The number of pulse single segment times is obtained through integer division operation, and the duration of the pulse residual time is obtained through modulo operation; According to the number of pulse single-segment times, the duration of the pulse single-segment time and the duration of the pulse residual time, the current control cycle is divided into a plurality of pulse single-segment times and one pulse residual time.
7. The pulse generation method according to any one of claims 4 to 6, characterized in that: The number of pulse independent times is N, where N is a positive integer greater than 1; When N is an even number, the pulse residual time is between the N / 2th pulse single segment time and the N / 2+1th pulse single segment time; When N is an odd number, the pulse difference time is between the (N+1) / 2th pulse single segment time and the (N+3) / 2th pulse single segment time.
8. A pulse generating device, characterized in that: The pulse generating device comprises: A parameter calculation module, used for calculating the pulse generation parameters of the current control cycle according to the number of pulses of the previous control cycle, the number of pulses of the current control cycle and the preset pulse step proportional coefficient, wherein the pulse generation parameters include a pulse frequency word, a frequency start word and a frequency increase word, the value of the pulse frequency word is equal to the value of the frequency start word, the current control cycle includes a plurality of pulse single-segment times, and the pulse single-segment time includes at least one clock cycle; The frequency update module is used to add the value of the pulse frequency word to the value of the frequency start word every time a new clock cycle is entered to obtain a new pulse frequency word; every time a new pulse single period is entered, the value of the frequency start word is added to the value of the frequency increase word to obtain a new frequency start word; whenever it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency, the value of the pulse frequency word is subtracted from the value of the clock frequency to obtain a new pulse frequency word; The pulse generating module is used to generate a pulse when it is detected that the value of the pulse frequency word is greater than or equal to the value of the clock frequency.
9. An electronic device, characterized in that: The electronic device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the pulse generation method according to any one of claims 1 to 7 when executed by the processor.
10. A computer program product, characterized in that The computer program product comprises a computer program, which, when executed by a processor, implements the steps of the pulse generation method according to any one of claims 1 to 7.