Measuring 0-14V PWM Signal using Microcontroller - Page 1
Forum section: electronics / beginners

author: x4ce
author_rank: Contributor
timestamp: August 12, 2024, 04:48:43 pm
content: Hi,I require suggestion regarding measurement of PWM signal of fixed frequency (50% DC) with 0 - 14V using a 3V3 MCU. I need to measure the average voltage of this signal.For this, I think a VDR with op-amp to scale it down then a bulk capacitor to get a stable output of this PWM? Any other efficient idea or circuit to accomplish this?Thanks

author: PGPG
author_rank: Frequent Contributor
timestamp: August 12, 2024, 06:57:47 pm
content: MCU analog inputs have typically high input impedance so the resistor voltage divider + capacitor should be enough.

author: x4ce
author_rank: Contributor
timestamp: August 13, 2024, 04:00:43 am
content: Quote from: PGPG on August 12, 2024, 06:57:47 pmThank you for your valuable input. Please see attached preliminary circuit for the desired function. Any discrepancy/ suggestion for the given circuit will be appreciated.Thanks

author: BennoG
author_rank: Frequent Contributor
timestamp: August 13, 2024, 05:32:10 am
content: at a that high resistance divider you have to take the input resistance of you analog input of the MCU into account.So you probably need to make some table (measured ADC value versus real input voltage)Benno

author: Psi
author_rank: Super Contributor
timestamp: August 13, 2024, 05:48:03 am
content: Normally you use resistors around 10k in the divider, since most MCU adc's can handle 10k input impedance without losing any speed. (The sample and hold cap inside the ADC can pull enough current through 10k before the sample time is over). But this does depend on the speed and specs of your specific ADC. I just remember it's around 10k on AVR's. It's probably different on more modern super fast MCU.If you don't need the full ADC sampling speed you can get away with a higher resistance without any issues.10k also provides a decent amount of protection for general low voltage stuff, as you need over 300V to push more than 30mA into the MCU input and exceed its rating.

author: PGPG
author_rank: Frequent Contributor
timestamp: August 13, 2024, 01:44:02 pm
content: Quote from: x4ce on August 13, 2024, 04:00:43 amIn first post you said that you need to measure average voltage.You will have guarantee to get average if voltage divider will give output voltage lower than Zener diode voltage.When Zener starts to conduct you loose average information from your output signal.As an example consider input signal having 100% fill. If it will be 12V it will certainly have different average voltage than when it is 14V.But in your circuit for 12V you will get 5.1V then limited to 3.3V and for 14V you will get 6V then limited to 3.3V.So for two signals of different average voltage you get the same output voltage - you lost average information.

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 13, 2024, 04:08:33 pm
content: Best to first do calculation on your divider such that the highest input voltage (14V) gives at most a say 10% lower voltage than the maximum input voltage of your ADC. The 10% lower is to allow for some headroom in the conversion.See if your MCU uses internal protection diodes and if not two Schottky diodes in the right orientation to VCC and ground might result in less distortion than when using a zener diode that close to the supply voltage rating. To verify this find the datasheet of the zener diode in question. It can be that it already starts to become a resistive load before the 3.3V limit.

author: x4ce
author_rank: Contributor
timestamp: August 13, 2024, 07:36:27 pm
content: Quote from: Psi on August 13, 2024, 05:48:03 amThanks for your valuable input. A combination of 10kohm & 2.7kohm consumes 1.1mA at 14V input which seems fine and may not be comparable to resistance of analog input.

author: x4ce
author_rank: Contributor
timestamp: August 13, 2024, 07:40:32 pm
content: Quote from: PGPG on August 13, 2024, 01:44:02 pmThanks, I used resistances to get 3V on the simulation which is an average voltage as shown in the schematic. Instead, I should have used resistances based on Vpeak i.e. 14V. According to this, a combination of 10kohm & 2.7kohm seems good.

author: x4ce
author_rank: Contributor
timestamp: August 13, 2024, 07:43:56 pm
content: Quote from: pcprogrammer on August 13, 2024, 04:08:33 pmThanks, based on calculations a 10kohm & 2.7kohm gives 3V (nearly 10% less than 3V3). Besides, nRF52811 has internal protection diodes so a zener may not be required.Moreover, the capacitor of 100nF would be fine to stabilize the PWM'ed input?Thanks

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 14, 2024, 06:22:08 am
content: Quote from: x4ce on August 13, 2024, 07:43:56 pmThis depends on the carrier frequency of the PWM signal and the max low frequency bandwidth you want to measure.In combination with the input resistor it forms a low pass filter that you can do calculations on.