MCU-based DMA function control AD converter peak value sampling method

文档序号:875984 发布日期:2021-03-19 浏览:3次 中文

阅读说明:本技术 基于mcu的dma功能控制ad转换器峰值采样方法 (MCU-based DMA function control AD converter peak value sampling method ) 是由 何其齐 赵浩华 高志齐 于 2020-12-03 设计创作,主要内容包括:本发明涉及一种基于MCU的DMA功能控制AD转换器峰值采样方法,包括如下步骤:根据AD转换器的时序要求配置好MCU的定时器DMA功能;配置连接AD转换器的端口寄存器指向第一缓冲区,AD转换器数据通过MCU的端口传输到第一缓冲区,进入中断执行程序;中断执行程序的第Ⅰ阶段,在小于1us的时间里完成DMA的关闭、重新指定数据端口寄存器传输到第二缓冲区,然后重新启动DMA;在第Ⅱ阶段,程序寻找上个缓冲区中已经填满的AD电压和电流数据中的最大值和最小值,并计算出平均值;在第Ⅲ阶段,MCU可执行其他程序。本发明能够用最简单的电路图实现电压、电流的无丢失连续全采样,并由此实现电压、电流峰值和纹波测量。(The invention relates to a method for controlling the peak value sampling of an AD converter based on the DMA function of an MCU, which comprises the following steps: configuring a timer DMA function of the MCU according to the time sequence requirement of the AD converter; configuring a port register connected with an AD converter to point to a first buffer area, transmitting the data of the AD converter to the first buffer area through a port of the MCU, and entering an interrupt execution program; in the I stage of the interrupt execution program, the closing of the DMA is completed in the time less than 1us, the register of the data port is reassigned and transmitted to the second buffer area, and then the DMA is restarted; in the second stage, the program searches the maximum value and the minimum value in the AD voltage and current data which are filled in the previous buffer area, and calculates the average value; in phase iii, the MCU may execute other programs. The invention can realize loss-free continuous full sampling of voltage and current by using the simplest circuit diagram, and thereby realize voltage and current peak value and ripple measurement.)

1. A method for controlling the peak value sampling of an AD converter based on the DMA function of an MCU is characterized by comprising the following steps:

firstly, configuring a timer DMA function of an MCU according to the time sequence requirement of an AD converter;

step two, after the MCU timer is configured, a port register connected with the AD converter is configured to point to a first data buffer area, MCU intervention is not needed after the timer is started, the AD converter data is transmitted to the first data buffer area through a port of the MCU, when the DMA count reaches a set count value n, DMA interruption is triggered, and an interruption execution program is entered;

step three, interrupting the I stage of the executive program, finishing the closing of the DMA, reassigning the data port register to transmit to the second data buffer area in the time less than 1us, and then restarting the DMA; in the second stage, the program searches the maximum value and the minimum value in the AD voltage and current data which are filled in the previous data buffer area, and calculates the average value; in the third stage, the MCU can execute other programs; waiting until the next DMA interrupt begins, the reassigned data port register is transferred to the second data buffer and the process is repeated.

2. The MCU-based DMA function control AD converter peak value sampling method of claim 1, wherein in the step one, the timer DMA of the MCU is configured to use the frequency of 1MHz generated by the timer output in the MCU to control the/CNVST and A/B ports of the AD converter, the up and down counting mode of the timer triggers DMA data transmission, the DMA data transmission is transmitted to the defined buffer area from the MCU port, the DMA counting interruption is adopted, and the interruption program is entered every n counting; the/CNVST triggers an AD conversion process once by a falling edge, and converts data of two channels once, which takes 2us in total; and then defining two data buffer areas with the same size, and switching and reading the AD data between the two buffer areas continuously once the timing DMA mode sampling is started so as to realize the voltage and current sampling without loss.

3. The MCU-based DMA function controlled AD converter peak sampling method of claim 1, wherein the AD converter is an analog-to-digital converter AD 7655.

4. An MCU based DMA function controlled AD converter peak sampling method according to claim 1, characterized in that the MCU is STM32F103 VCT.

The technical field is as follows:

the invention relates to the field of instruments and meters and electronic measurement, in particular to a method for sampling a peak value of an AD converter controlled by a DMA function based on an MCU.

Background art:

in the field of electronic measurement, peak value and ripple measurement of voltage or current is realized, and a method of sampling by separately connecting a hardware peak value sample-and-hold circuit or an FPGA/CPLD to an AD analog-to-digital converter and then transmitting the sampled signal to an MCU through the FPGA/CPLD is generally adopted, as shown in fig. 1 and 2. These methods have their own drawbacks, and it is difficult to achieve peak and ripple measurements within a loss-free and arbitrarily controllable time period of peak sampling. And the method of adding a CPLD or FPGA increases the complexity of the circuit and increases the cost.

The invention content is as follows:

the invention aims to overcome the defects of the prior art and provides a method for realizing peak value and ripple measurement by using a sampling technology of controlling an AD converter by using a DMA function of an MCU (microprogrammed control Unit) to realize no loss of voltage and current.

The invention provides a method for controlling the peak value sampling of an AD converter based on the DMA function of an MCU, which comprises the following steps:

firstly, configuring a timer DMA function of an MCU according to the time sequence requirement of an AD converter;

after the MCU timer is configured, firstly configuring a port register connected with the AD converter to point to a first data buffer area, starting the timer without MCU intervention, transmitting the AD converter data to the first data buffer area through a port of the MCU, and triggering DMA interruption when the DMA count reaches a set count value n to enter an interruption execution program;

step three, interrupting the I stage of the executive program, finishing the closing of the DMA, reassigning the data port register to transmit to the second data buffer area in the time less than 1us, and then restarting the DMA; in the second stage, the program searches the maximum value and the minimum value in the AD voltage and current data which are filled in the previous buffer area, and calculates the average value; in the third stage, the MCU can execute other programs; wait until the next DMA interrupt begins and repeat the process.

In the first step, a timer DMA of the MCU is configured, the timer DMA in the MCU is used for outputting and generating 1MHz frequency to control a/CNVST port and an A/B port of an AD converter, the up-counting mode and the down-counting mode of the timer trigger DMA data transmission, the DMA data transmission is transmitted to a defined buffer area from the MCU port, DMA counting interruption is adopted, and an interruption program is entered when every n counts; the/CNVST triggers an AD conversion process once by a falling edge, and converts data of two channels once, which takes 2us in total; and then defining two data buffer areas with the same size, and switching and reading the AD data between the two data buffer areas continuously once the timing DMA mode sampling is started so as to realize the voltage and current sampling without loss.

Preferably, the AD converter is an analog-to-digital converter AD7655, and the MCU is STM32F103 VCT.

The invention has the beneficial effects that:

(1) the invention uses DMA data transmission technology of MCU to read the data of AD converter into MCU;

(2) the method can realize no loss of AD sampling data and overcome the defect of the traditional discontinuous sampling;

(3) the whole program flow is completed in a mode of DMA interruption, and voltage and current peak value sampling and ripple wave measurement are realized;

(4) the invention can realize loss-free continuous full sampling of voltage and current by using the simplest circuit diagram, and thereby realize voltage and current peak value and ripple measurement.

Description of the drawings:

FIG. 1 is a schematic block diagram of a general method of voltage current sampling;

FIG. 2 is a timing diagram of a general method of voltage current sampling;

FIG. 3 is a schematic block diagram of the circuit of the MCU-based DMA function control AD converter peak sampling method of the present invention;

fig. 4 is an operation timing and program diagram of the MCU-based DMA function controlling AD converter peak sampling method of the present invention.

The specific implementation mode is as follows:

the following detailed description of the preferred embodiments of the present invention, taken in conjunction with the accompanying drawings, will make the advantages and features of the invention more readily understood by those skilled in the art, and thus will more clearly and distinctly define the scope of the invention.

The invention relates to a DMA (direct Memory access) technology of an MCU (microprogrammed control Unit), wherein the DMA is direct Memory storage and is a data transmission mode without intervention of the MCU, and the transmission data does not occupy the work of the MCU.

As shown in fig. 3, the basic circuit of the MCU-based DMA function controlling AD converter peak sampling method of the present invention includes: the device comprises a voltage and current input unit, an MCU control unit and an AD analog-to-digital conversion unit.

The connection signals of the sampled voltage and current models which are processed by an analog circuit and input into the analog-to-digital converter AD7655, the AD7655 and the STM32F103VCT6 mainly comprise 16-bit data lines (D0-D15), a conversion starting signal (/ CNVST) and a channel selection model (A/B) connection.

The method and timing shown in fig. 4 is the core of the present invention.

Firstly, configuring the timer DMA function of the MCU according to the time sequence requirement of the AD converter, the method is that the internal timer T output of the MCU generates the frequency of 1MHz to control the/CNVST and A/B ports of the AD7655, the up-counting mode and the down-counting mode of the timer trigger the DMA data transmission, the DMA data transmission is transmitted to the defined data buffer buf1[ n ] and buf2[ n ] from the MCU port, the DMA counting interrupt is adopted, and the interrupt program is entered when every n counts. the/CNVST is an AD conversion process triggered once by a falling edge, and data of two channels are converted at a time, which takes 2us in total, that is, the sampling rate of each channel is 500 kSPS. Then, two data buffers buf1[ n ] and buf2[ n ] with the same size are defined, which is a necessary condition for realizing the DMA mode non-loss reading of the AD converter to convert data each time, and once the timing DMA mode sampling is started, the reading of the AD data is switched between the two buffers buf1 and buf2 continuously, so that the non-loss voltage and current sampling is realized. Where n can be freely set according to the specific situation of the program, for example, n is 100 in this embodiment, and the time interval corresponding to each interrupt is 100 × 1us — 100 us.

The sampling process is as follows: after the MCU timer is configured, firstly configuring a port register connected with the AD to point to buf1, starting the timer without intervention of the MCU, transmitting AD7655 data to a designated buf1 through a port of the MCU, and triggering DMA interruption to enter an interruption execution program when the DMA count reaches a set count value n.

The interrupt handler in phase i of fig. 4 must complete the DMA shutdown, reassign the data port register transfer to buf2 address, and then restart the DMA in less than 1us, thus ensuring that the next AD data is not lost for transfer to buf2 n. In the phase ii of fig. 4, the program searches for the maximum value and the minimum value in the AD voltage and current data that have been filled in the buf1[ n ], and calculates the average value, the processing time of the program can be reduced to 60us, and in the phase iii of fig. 4, the MCU can execute other programs such as responding to the key, communicating, etc. within the remaining 40us of idle time. Wait until the next DMA interrupt begins and repeat the above process, but reassign the data port register transfer to buf1 address and then restart the DMA. Let the voltage-current data sampled by AD be transmitted alternately in buf1 and buf 2.

The value of the counting number n can be freely set according to specific requirements, the sampling interval is small when the value of n is small, and the response speed can be improved by matching with PID algorithms with requirements on speed.

Also, because the peak and ripple values are programmed, it may be specified to measure the peak and ripple values over a period of time.

In summary, the present invention provides a method for sampling and measuring the peak value of a voltage or current signal by controlling an AD (analog-to-digital converter) with the DMA function of an MCU.

Finally, it should be noted that: although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art will understand that: any person skilled in the art can modify or easily conceive the technical solutions described in the foregoing embodiments or equivalent substitutes for some technical features within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

9页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种运行电能计量装置RFID密钥管理方法及系统

网友询问留言

已有0条留言

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

精彩留言,会给你点赞!