Abstract:ADC sampling AC waveform is an important application of embedded system. When the collected voltage waveform is not the standard function waveform (such as sine wave, triangle wave, etc.), it cannot be directly calculated by simplified mathematical formula or average response method. in order to get the root mean square value of any waveform, it first need to calculate the frequency (or period) of the waveform; in the traditional algorithm, it need to perform FFT (fast Fourier transform), which requires a large number of Memory space and high time complexity, and only 2N points can be calculated, so the accuracy and resolution are limited; due to the limited resources on the single-chip microcomputer, the algorithm is not suitable for multi-channel and real-time calculation; in order to improve the above deficiencies, propose a Peak (valley) search algorithm, which has O(n) time complexity and good real-time performance; use this algorithm to find three peak points in the sampled waveform, determine one of the cycles of the waveform, and then calculate the root mean square value; Compared with the FFT algorithm, the running speed of this algorithm is increased by 93 times, the space complexity is reduced to 1/300, and it runs stably and reliably in practical applications, with an average error of less than 0.6%.