Precision PCB Fabrication, High-Frequency PCB, High-Speed PCB, Standard PCB, Multilayer PCB and PCB Assembly.
The most reliable PCB & PCBA custom service factory.
PCB News

PCB News - How to convert PWM signal into analog signal?

PCB News

PCB News - How to convert PWM signal into analog signal?

How to convert PWM signal into analog signal?

2021-09-23
View:536
Author:Kavie

There is a position sensor for measuring position change. I use the voltage range of the multimeter to measure the output signal of the sensor. The result shows the analog signal, that is, the position has a linear relationship with the signal output. However, when I use an oscilloscope (PicoScope 4227) to measure the output signal of the sensor, it shows the PWM signal (pulse width modulation), that is, the duty cycle of the output PWM signal is different with different positions.

The parameters of PWM signal are: 200 Hz, low level is 0V, high level is 18V.

Now it can be determined that my sensor output signal is PWM signal. The PWM signal needs to be input into the controller I / O, but the controller I / O port does not have the function of directly collecting PWM signal.

2, Solution:

A circuit is designed to convert PWM signal into analog signal, and then input the converted analog signal to the analog I / O port of the controller.

3, Conversion circuit

1. Second order voltage controlled active low-pass filter circuit.

Design a depth filter circuit. The filter circuit diagram is:

The low-pass filter frequency formula is: F = 1 / (2 π * RC). I choose r = 1K, C = 10uF, and the calculated low-pass cut-off frequency is f = 15.9hz.

The back end of the filter circuit is an operational amplifier, and the magnification formula is: a = 1 + RF / R1. I don't want the voltage to be amplified, so I choose a = 1.1. Because R1 / / RF = 2R (the parallel value of R1 and RF is equal to the series value of R), the final value: RF = 220 Ω, R1 = 2.2k, r = 1K.

circuit board

2. Integrating circuit (passive filter circuit)

In front of the low-pass filter circuit is a two-stage integrating circuit (grounding both capacitors), r = 1K, C = 10uF. The following figure shows the integration circuit, which is designed by connecting two circuits in series to form a two-level integration:

For the test to verify the circuit effect, the equipment I use is PicoScope 4227. Since the equipment can only generate positive and negative 1V voltage signals, it generates a PWM signal with amplitude of 1V (low level 0V, high level 1V) and frequency of 200Hz as the input signal of the integrating circuit. Various renderings are as follows:

1. The oscilloscope directly collects the PWM signal generated by the generator, and the waveform is as follows:

2. The oscilloscope collects the signal from the input of the second-order filter circuit, and the waveform is as follows. It is found that the waveform has changed compared with the waveform in the figure above.

3. The signal waveform collected by the oscilloscope from the output of the first-order filter circuit, that is, the output waveform of the filter circuit from left to right and the intersection of resistors and capacitors:

4. The signal waveform collected by the filter from the output of the second-order filter circuit is the final output signal waveform

5. Parameters of final output waveform:

4, Question

1: Why is the output signal of the sensor measured by the voltage range of the multimeter, the result is an analog signal, and what the oscilloscope sees is a PWM signal? Which result should I believe?

A: this problem involves the resolution of the measurement input port. The resolution of the input port of the multimeter is low (lower than 200Hz in this example), while the resolution of the input port of the oscilloscope is high, up to several thousand or even several megahertz, so the output results are different. We should trust the results displayed by the oscilloscope. I understand that the essence of PWM signal still hopes to achieve the effect of analog quantity, but the manifestations are different.

2: About calculation formula

A: in the low-pass filter circuit, there is a frequency formula F = 1 / (2 π * RC), which calculates the low-pass cut-off frequency (- 3dB). In the integrating circuit, there is a formula t = RC. This t refers to the time required for capacitor charging and discharging. When t is selected, according to the general empirical formula, t > 10 * t '(t' represents the signal period).

In the integrating circuit of this example, RC = 10ms, only twice the signal period, but through the test, the signal effect is still ideal. If more integrating circuits are connected in series, the effect will be better.

3: Is there any other scheme for PWM signal to be collected by the controller?

A: scheme 1: doubling the PWM signal is to increase the frequency of the PWM signal, but the duty cycle does not change. If the frequency after PWM frequency doubling is greater than the resolution of the controller I / O, it can be defaulted as analog by the controller, so it can be input to the analog I / O.

Scheme 2: calculate the duty cycle of PWM by software. Write a program in the controller. First, measure the time of high level in PWM signal during this period, so as to calculate the duty cycle.