Stepping motor pulse output control method based on DMA

文档序号:687215 发布日期:2021-04-30 浏览:30次 中文

阅读说明:本技术 一种基于dma的步进电机脉冲输出控制方法 (Stepping motor pulse output control method based on DMA ) 是由 刘培超 陈俊同 刘主福 解俊杰 郝计军 于 2020-12-11 设计创作,主要内容包括:本发明涉及脉冲步进电机的控制技术领域,本发明提出了一种基于DMA的步进电机脉冲输出控制方法,包括:步骤一:MCU芯片单元接收点动指令信号;步骤二:所述定时器外设中断,所述MCU芯片单元根据所述指令参数信号分别计算出所需输出的总脉冲个数以及单次输出的脉冲个数;步骤三:所述DMA外设中断,所述DMA外设的脉冲发生模块获取所述单次输出的脉冲个数信号后生成所述单次输出的脉冲个数,并输出所述脉冲个数;步骤四:等待下一次所述DMA外设中断与下一次所述定时器外设中断;步骤五:重复步骤二至步骤四,直至DMA外设完成总脉冲个数的输出。本发明通过DMA外设接收MCU的脉冲个数信号来生成脉冲个数输出,可以精确控制脉冲发送的频率和数量。(The invention relates to the technical field of control of pulse stepping motors, and provides a stepping motor pulse output control method based on DMA (direct memory access), which comprises the following steps: the method comprises the following steps: the MCU chip unit receives a jog command signal; step two: the timer is interrupted, and the MCU chip unit respectively calculates the total number of pulses required to be output and the number of pulses output in a single time according to the instruction parameter signal; step three: the DMA peripheral is interrupted, and a pulse generating module of the DMA peripheral generates the number of pulses output once after acquiring the number of pulses output once and outputs the number of pulses; step four: waiting for the next DMA peripheral interrupt and the next timer peripheral interrupt; step five: and repeating the second step to the fourth step until the DMA peripheral finishes outputting the total pulse number. The invention receives the pulse number signal of the MCU through the DMA peripheral to generate pulse number output, and can accurately control the frequency and the number of pulse transmission.)

1. A stepping motor pulse output control method based on DMA is provided, an MCU chip unit is arranged in the stepping motor, the MCU chip unit comprises the DMA peripheral and a timer peripheral, and the method is characterized by comprising the following steps:

the method comprises the following steps: the MCU chip unit receives an external input instruction parameter signal;

step two: the timer is interrupted, and the MCU chip unit respectively calculates the total number of pulses required to be output and the number of pulses output in a single time according to the instruction parameter signal;

step three: the DMA peripheral is interrupted, and a pulse generating module of the DMA peripheral generates the number of pulses output once after acquiring the number of pulses output once and outputs the number of pulses;

step four: waiting for the next DMA peripheral interrupt and the next timer peripheral interrupt;

step five: and repeating the second step to the fourth step until the DMA peripheral finishes outputting the total pulse number.

2. The method according to claim 1, wherein in the second step, the MCU chip unit stores the pulse number information of a single output in a buffer unit and then waits for the next interrupt of the external timer.

3. The method as claimed in claim 1 or 2, wherein the parameter information includes movement distance information and movement speed information of the stepping motor, the MCU chip unit calculates the total number of pulses signals to be transmitted according to the movement distance information, and calculates the number of pulses signals to be output at a time according to the movement speed information.

4. The method as claimed in claim 1, wherein the timer peripheral interrupt is automatically triggered by a timing module in the timer peripheral reaching a preset period, and the DMA peripheral interrupt is automatically triggered by the DMA peripheral detecting that all the pulse number transmission of the last single output is completed.

5. The method as claimed in claim 2, wherein the pulse generating module of the DMA peripheral obtains the pulse number signal of the single output from the buffer unit.

6. The DMA-based stepping motor pulse output control method according to claim 1, wherein the generation process of the number of pulses per output comprises the steps of:

firstly, a pulse generation module of the DMA peripheral calculates the generation frequency of the number of the single pulses according to the signal of the number of the single pulses;

then, a frequency calculation module of the DMA peripheral obtains a frequency division coefficient according to the generated frequency;

and finally, generating the number of the pulses output at a single time by the pulse generating module of the DMA peripheral according to the frequency division coefficient and outputting the number of the pulses.

7. The DMA-based stepping motor pulse output control method according to claim 6, wherein the outputting the number of pulses comprises:

and the DMA peripheral stores the frequency division coefficient into the timer peripheral, triggers a switch module of the DMA peripheral to start and controls the number of the output pulses.

8. The method for controlling the pulse output of the stepping motor based on the DMA according to claim 7, wherein after the pulse generation module of the DMA peripheral generates the number of pulses of the single output according to the frequency division coefficient, the method comprises:

and detecting the transmission completion condition of all the pulse numbers output at one time, if all the pulse numbers are transmitted, stopping transmitting the pulses by a pulse generating module of the DMA peripheral and triggering the DMA peripheral to be interrupted to acquire a pulse number signal output at the next time.

9. The DMA-based stepper motor pulse output control method of claim 6, wherein the frequency calculation module obtains the corresponding frequency division coefficient from a frequency look-up table stored in a DMA peripheral according to the generated frequency.

10. The method according to claim 5, wherein before the DMA peripheral is triggered by an interrupt, the completion of the transmission of all the pulse numbers of the previous single output is detected, and if the DMA peripheral pulse generation module is detected to have not completed the output of all the pulse numbers of the single output, the output of the remaining pulse numbers of the single output is continuously detected; and if the DMA peripheral pulse generation module is detected to finish the output of all the pulse numbers output at a single time, the DMA peripheral pulse generation module stops sending pulses and triggers the DMA peripheral to interrupt, and the next pulse number signal output at a single time is obtained from the cache unit.

Technical Field

The invention relates to the technical field of control of pulse stepping motors, in particular to a stepping motor pulse output control method based on DMA (direct memory access).

Background

In the prior art, as shown in fig. 1, the pulse generation of the stepping motor is completed by the cooperation of the MCU and the FPGA. The MCU is responsible for calculating the number of pulses required to be generated in each period, and then writing the number of pulses into a pulse generation module of the FPGA through a specific communication interface. The FPGA can inform the MCU of sending the number of pulses required to be generated in the next period in the process of generating the pulses in the period, so that the condition that the pulses are not connected to each other to cause discontinuity can be prevented.

The MCU and the FPGA are used in the prior art, because two chips are involved, the reliability and the stability of the system are reduced to some extent, the cost is higher, the design difficulty of the board card is increased, the production line test is more complex, so that a single MCU is urgently needed to complete high-quality step control pulse output, the hardware cost and the system reliability are more advantageous, and the firmware maintenance difficulty is reduced.

Disclosure of Invention

The present invention is directed to solving at least one of the problems of the prior art. Therefore, the invention provides a stepping motor pulse output control method based on DMA, an MCU chip unit is arranged in the stepping motor, the MCU chip unit comprises the DMA peripheral and a timer peripheral, and the method comprises the following steps: the method comprises the following steps: the MCU chip unit receives a jog command signal; step two: the timer is interrupted, and the MCU chip unit respectively calculates the total number of pulses required to be output and the number of pulses output in a single time according to the instruction parameter signal; step three: the DMA peripheral is interrupted, and a pulse generating module of the DMA peripheral generates the number of pulses output once after acquiring the number of pulses output once and outputs the number of pulses; step four: waiting for the next DMA peripheral interrupt and the next timer peripheral interrupt; step five: and repeating the second step to the fourth step until the DMA peripheral finishes outputting the total pulse number.

In some embodiments, in the second step, the MCU chip unit stores the pulse number information of the single output in the buffer unit and then waits for the next interrupt of the external device of the timer.

In some embodiments, the parameter information includes movement distance information and movement speed information of the stepping motor, and the MCU chip unit calculates the total number of pulses to be transmitted according to the movement distance information and calculates the number of pulses to be output at a single time according to the movement speed information.

In some embodiments, the timer peripheral interrupt is automatically triggered by a timing module within the timer peripheral reaching a preset period, and the DMA peripheral interrupt is automatically triggered by the DMA peripheral detecting completion of all pulse number transmissions last output a single time.

In some embodiments, the pulse generation module of the DMA peripheral acquires the pulse number signal of the single output from the buffer unit.

In some embodiments, the generating of the number of pulses of the single output comprises the steps of: firstly, a pulse generation module of the DMA peripheral calculates the generation frequency of the number of the single pulses according to the signal of the number of the single pulses; then, a frequency calculation module of the DMA peripheral obtains a frequency division coefficient according to the generated frequency; and finally, generating the number of the pulses output at a single time by the pulse generating module of the DMA peripheral according to the frequency division coefficient and outputting the number of the pulses.

In some embodiments, the DMA peripheral stores the frequency division coefficient in the timer peripheral, and triggers a switch module of the DMA peripheral to start, so as to control the number of output pulses.

In some embodiments, the sending completion condition of all the pulse numbers output at a single time is detected, and if all the pulse numbers are sent, the pulse generating module of the DMA peripheral stops sending pulses and triggers the DMA peripheral to interrupt, so as to obtain a next pulse number signal output at a single time.

In some embodiments, the frequency calculation module obtains the corresponding frequency division coefficient from a frequency look-up table stored in a DMA peripheral according to the generated frequency.

In some embodiments, before the DMA peripheral is triggered by an interrupt, the sending completion condition of all the pulse numbers output at a previous single time is detected, and if the DMA peripheral is detected that the pulse generation module does not complete the output of all the pulse numbers output at a single time, the output of the remaining pulse numbers output at a single time is continuously detected; and if the DMA peripheral pulse generation module is detected to finish the output of all the pulse numbers output at a single time, the DMA peripheral pulse generation module stops sending pulses and triggers the DMA peripheral to interrupt, and the next pulse number signal output at a single time is obtained from the cache unit.

Additional aspects and advantages of the invention will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the invention.

Drawings

In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the structures shown in the drawings without creative efforts.

FIG. 1 is a control flow diagram of a prior art stepper motor pulse output;

FIG. 2 is a control flow chart of the single MCU chip and the DMA peripheral controlling the pulse output together.

FIG. 3 is a control flow chart of the MCU chip of the present invention for obtaining the pulse number output once.

FIG. 4 is a flow chart of the control of the output of the number of single output pulses of the DMA peripheral according to the present invention.

Fig. 5 is a control flowchart of the number of pulses generated by the pulse generation module of the DMA peripheral according to the present invention.

The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.

Detailed Description

Reference will now be made in detail to embodiments of the present invention, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the drawings are illustrative and intended to be illustrative of the invention and are not to be construed as limiting the invention.

The following disclosure provides many different embodiments, or examples, for implementing different features of the invention. To simplify the disclosure of the present invention, the components and arrangements of specific examples are described below. Of course, they are merely examples and are not intended to limit the present invention. Furthermore, the present invention may repeat reference numerals and/or letters in the various examples. This repetition is for the purpose of simplicity and clarity and does not in itself dictate a relationship between the various embodiments and/or configurations discussed. In addition, the present invention provides examples of various specific processes and materials, but one of ordinary skill in the art may recognize the applicability of other processes and/or the use of other materials.

A DMA-based stepping motor pulse output control method according to an embodiment of the present invention is described below with reference to fig. 2 to 4.

As shown in fig. 2, in the method for controlling pulse output of a DMA-based stepping motor, an MCU chip unit is disposed in the stepping motor, and the MCU chip unit includes a DMA peripheral and a timing peripheral, and the method includes steps of: the MCU chip unit receives an external input instruction parameter signal (specifically, the stepping motor is externally connected with an operating device, and instruction parameter information is input by clicking an application program such as an upper computer or a mobile terminal by an operator); step two, S2: the timer is interrupted, and the MCU chip unit calculates the total pulse number and the single output pulse number according to the externally input instruction parameter information; step three, i.e. S3: the DMA peripheral is interrupted, and a pulse generation module of the DMA peripheral acquires the number of single output pulses calculated by the MCU chip unit and outputs the number of the single output pulses; step four, S4: waiting for the next DMA peripheral interrupt and the next timer peripheral interrupt; step five, S5: and repeating the steps from S2 to S4 until the DMA peripheral finishes outputting all the total pulse number.

According to the stepping motor pulse output control method based on the DMA, the DMA peripheral and the timer peripheral are arranged in the single MCU chip, the timer peripheral interrupt and the DMA peripheral interrupt are automatically triggered through the system, the single output pulse number information obtained through MCU calculation is used as the information source of the pulse generation frequency of the pulse generation module of the DMA peripheral, the MCU chip unit and the DMA peripheral can be functionally coupled, the frequency and the number of pulse transmission can be accurately controlled, compared with the prior art that the combination of the MCU and the FPGA double chips is adopted, the hardware cost, the board design difficulty and the maintenance difficulty are reduced, and the reliability and the stability of the system are improved. By loading the MCU chip with the DMA peripheral, the pulse generation number can be controlled, the DMA peripheral can be triggered to interrupt after all the generated pulse numbers are detected to be completely sent, and the continuity of pulse number generation and output is guaranteed.

As a preferred implementation manner, before step one, that is, S1, as shown in fig. 3 and 4, the embodiment of the present invention further performs initialization setting on the MCU and the DMA peripheral, that is, step S0, where the initialization process of the MCU and the DMA peripheral is performed simultaneously, the purpose of the initialization is to match the function on the DMA peripheral with the function on the MCU, and the function of the MCU is programmed by using the MCU chip unit in a specific application environment, in the programming process, an initialization program of the MCU and the DMA, for example, used to turn on a timer peripheral, a DMA register, a DMA source address and a destination address, etc., and the step of the initialization setting is a conventional means of a person skilled in the art, and is not described in detail herein.

As a preferred implementation manner, in the embodiment of the present invention, as shown in fig. 2 and fig. 3, the parameter information includes movement distance information and movement speed information of the stepping motor, the MCU chip unit calculates the total number of pulses to be transmitted according to the movement distance information, and calculates the number of pulses to be output at a single time according to the movement speed information. Because the total pulse number and the pulse number output once are determined, and the number of times of the pulse number output by the DMA peripheral pulse generation module can be determined according to the preset period of the timer peripheral, the MCU chip unit can be planned according to the internal algorithm rule, such as the trapezoidal speed algorithm rule, for example, after the stepping motor is started, according to the externally input movement distance information and movement speed information, an acceleration process, a uniform speed process and finally deceleration are carried out until the stepping motor completes the movement of the movement distance, the MCU chip unit can not initially enable the speed of the stepping motor to reach the externally input movement speed, so that the MCU can not initially enable the pulse number output once to be different in number in the interval time after the interruption triggering of each timer to be calculated, thereby not only realizing the accurate control of the DMA peripheral on the output number of the total pulse number, the method can also accurately control the output quantity of the corresponding pulse number of single output according to different time nodes triggered by timer interruption, and it needs to be explained here that the preset period of the external timer means that the timing period of the external timer is edited aiming at the application of the MCU chip unit on the stepping motor by programming each functional module of the MCU chip before the MCU chip unit is formally used, so that the preset period is the fixed timing period of the external timer after the MCU is initialized, namely when the MCU chip unit normally works, and the external timer can trigger the interruption according to the fixed timing period after the fixed timing period reaches.

As a preferred embodiment, as shown in fig. 3 and 4, in step two, i.e., S2, step S11 to step S13 are further included, specifically, S11 is a trigger of a timer peripheral interrupt; s12 storing the pulse number information outputted once into the buffer unit for the MCU chip unit; s13 is waiting for the next interrupt of the timer peripheral, and in step three, i.e., S3, the method further includes steps S31 to S34, specifically, step S31 detects whether the number of last single-output pulses is completely transmitted for the DMA peripheral; step S32 is the DMA peripheral interrupt trigger; step S33, obtaining the pulse number signal of single output from the buffer unit for the pulse generation module of the DMA peripheral; step S34 generates the number of pulses for the pulse generation module of the DMA peripheral and outputs the number of pulses. The control process that the MCU calculates the number of the pulses output at a single time and the control process that the DMA peripheral acquires the number of the pulses according to the number of the pulses output at a single time are two independent control processes, the control authority of the MCU is transferred to the DMA peripheral by a bus when the DMA peripheral works, so that the DMA peripheral needs to acquire the number information of the pulses output at a single time in order to ensure the continuous generation of the pulses, and therefore the MCU chip unit needs to store the number information of the pulses output at a single time in advance into the cache unit, so that the DMA peripheral can be directly acquired for use, and the problem that when the number of the pulses output at a next time is generated, the number of the pulses output at a single time is not calculated yet, and a program is made mistakes is.

As another preferred embodiment, as shown in fig. 3 and 4, the specific step of the timer peripheral interrupt triggering in step S11 is that the timer peripheral interrupt is automatically triggered by the timer module in the timer peripheral reaching a preset period, and the specific step of the DMA peripheral interrupt triggering in step S32 is that the DMA peripheral interrupt is automatically triggered by the DMA peripheral detecting that all the pulse number transmission of the last single output is completed. The MCU chip unit can be released from the bus by triggering the external interrupt of the timer, and is used for respectively calculating the total number of output pulses and the number of pulses output in a single time according to the movement distance information and the movement speed information; the DMA peripheral is triggered to be interrupted, so that the pulse generating module of the DMA peripheral generates the pulse number of single output according to the acquired pulse number information of single output, and the working efficiency of the DMA peripheral can be improved by utilizing an automatic triggering mode.

In some embodiments of the present invention, as shown in fig. 5, the step S34, i.e. the generation process of the number of pulses of the single output, includes the following steps: step S331, the pulse generation module of the DMA peripheral calculates the generation frequency of the number of single pulses according to the signal of the number of single pulses; step S332, the frequency calculation module of the DMA peripheral obtains a frequency division coefficient according to the generated frequency; and finally, the pulse generation module of the DMA peripheral generates the number of pulses output in one time according to the frequency division coefficient and outputs the number of the pulses. The generation process of the number of the single-time output pulses is completed by two steps, and the calculation error can be reduced and the generation precision of the number of the pulses is further ensured in the process of acquiring the frequency division coefficient by using the generation frequency of the number of the single-time pulses obtained by calculation as a factor.

In some embodiments of the present invention, as shown in fig. 5, the step S34 of generating the number of pulses output once further includes the step S333 of storing the frequency division coefficient in the timer peripheral device by the DMA peripheral device and generating the number of pulses output once, and the step S334 of triggering the start of the switch module of the DMA peripheral device, specifically, after the frequency division coefficient is stored (written) in the timer peripheral device, the DMA peripheral device will automatically trigger the start of the switch module according to the edited program (the switch module will be switched on and off after the first frequency division coefficient is written in the timer peripheral device until the total number of pulses is completely transmitted), control and output the number of pulses, the DMA peripheral device detects the completion of the transmission of all the number of pulses output once, if all the number of pulses have been transmitted, the pulse generation module of the DMA peripheral device stops transmitting pulses and triggers the DMA peripheral device to interrupt, and acquire the next number of pulses output, the continuity of the output of the pulse number which is divided into single output by the total pulse number is ensured.

In some embodiments of the present invention, as shown in fig. 5, the specific step of step S332 is that the frequency calculation module obtains the corresponding frequency division coefficient from a frequency lookup table stored in the DMA peripheral according to the generated frequency. Through programming the DMA peripheral, the information of the frequency lookup table is firstly stored in a register of the DMA peripheral, the frequency lookup table comprises the corresponding relation between the frequency division coefficient and the generation frequency, the frequency division coefficient and the generation frequency can be in one-to-one correspondence through a mathematical formula or experimental data or personal experience, the frequency calculation module can quickly find the corresponding frequency division coefficient by utilizing the frequency lookup table according to the generation frequency, complex operation is not needed, the error of the calculation frequency can be reduced, and the precision of acquiring the frequency division coefficient can be improved.

In some embodiments of the present invention, as shown in fig. 4, before step S32, that is, before the DMA peripheral is triggered to interrupt, the sending completion condition of all the pulse numbers of the previous single output is detected, and if it is detected that the pulse generation module of the DMA peripheral does not complete the output of all the pulse numbers of the single output, the output of the remaining pulse numbers of the single output is continuously detected; if the DMA peripheral pulse generation module is detected to finish the output of all the pulse numbers output at a single time, the DMA peripheral pulse generation module stops sending pulses and triggers the DMA peripheral to interrupt, and the next pulse number signal output at a single time is obtained from the cache unit. By detecting all the pulse number output results of the last single output of the DMA peripheral, the time can be provided for the MCU chip unit, so that the MCU chip unit can store the pulse number signals of the next single output into the cache unit, and the DMA peripheral can also be triggered and interrupted, so that the DMA peripheral can automatically obtain the pulse number signals of the next single output from the cache unit to generate the pulse number, and the continuity of pulse number generation and output is guaranteed.

In the description of the present invention, it is to be understood that the terms "first", "second" and "third" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implying any number of technical features indicated. Thus, features defined as "first", "second", "third" may explicitly or implicitly include one or more of the features. In the description of the present invention, "a plurality" means two or more unless specifically defined otherwise.

In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction.

While embodiments of the invention have been shown and described, it will be understood by those of ordinary skill in the art that: various changes, modifications, substitutions and alterations can be made to the embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the claims and their equivalents.

13页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:用于空间光学载荷步进电机定位的微动开关位置调整方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!