Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of using PWM to collect electricity by ADC?

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you PWM to achieve ADC power collection principle is what, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.

1. Description

For the master chip without ADC, if you want to realize the function of ADC, you can use two GPIO and an operational amplifier to solve this problem. For some domestic chips, there is no ADC inside, so in some schemes, PWM circuit is used to measure the analog voltage. Then analyze the basic principle and acquisition process step by step.

two。 Basic principles

Using the integration circuit, the PWM is transformed into a smooth voltage output by adjusting the duty cycle of PWM. Then a comparator is used to compare the voltage to be measured. Continuously adjust the duty cycle of the PWM, when the output of the comparator changes from 0 to 1, recording the duty cycle of the current PWM can realize the measurement of the analog voltage.

two。 Hardware schematic diagram

2.1 integral circuit

The main function of this part of the circuit is to convert the PWM wave into a smooth straight line.

Since the voltage at both ends of the capacitor cannot change suddenly, a third-order integral circuit is used here, so that the voltage output to the comparator is a smooth DC voltage.

Calculation formula

The simulation results are as follows:

The input is 100K and the amplitude is 3.3V PWM wave. When the duty cycle is 70%, the output waveform is a smooth DC voltage. According to the calculation formula, the theoretical value of 2.31V is basically consistent with the simulation value of 2.325V.

2.2 Voltage comparator

This part of the voltage is the circuit schematic of the voltage comparator, in which the function of R6 is to pull up the resistor and improve the output capacity of the operational amplifier.

The voltage is divided by R4 and R5 resistors. 1/3 of the measured voltage is compared with the voltage regulated by PWM. Through the continuous duty cycle of the conditional PWM and detecting the output of the operational amplifier, when the output level of the operational amplifier appears in the opposite direction, the positive input of the operational amplifier can be considered to be the same as the test voltage of 1/3. Through this principle, the value of voltage to be measured is obtained.

3. Software design

For PWM voltage measurement, gpio is required to be able to output PWM waves. You can directly use the gpio output high and low level, and then by calculating the duty cycle to adjust. For Junzheng X1000, you can directly use PWM to output stable waveforms.

Then in the output pin of the comparator, the pin can be set as an interrupt, and when the interrupt occurs, the level of the power amplifier is reversed. By obtaining the current PWM duty cycle, the power of the battery at this time is calculated.

The code can be referred to

Kernel/drivers/power/pwm-battery.c

The voltage measured by this method is not very accurate, and the default accuracy in the code is 50mV. To adjust the precision, you can modify the following code

# define PWM_FREQ (140x1000) / / sampling frequency

# define PWM_STABLE_TIME_US 200

# define PWM_SAMPLE_TIMES 3 / / sampling times

# define PWM_DUTY_NS_STEP 30 / / adjust PWM sampling time each time

4. Summary

In the absence of ADC, two GPIO and one power amplifier can be used to simulate the design of ADC.

The main results are as follows: (1) this method needs to output a stable PWM wave and its duty cycle needs to be accurate, so it is the key to generate a stable PWM wave.

(2) the measured voltage needs to be stable, so for the stability of the voltage, a capacitor can be added to the part of the circuit that needs to be measured.

Increasing the capacitor C162 can make the level more stable and the collected voltage more accurate.

(3) the average value can be obtained by multiple ADC conversion, and the error can be eliminated by digital filtering.

The above content is what is the principle of PWM ADC to collect electricity, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report