Author Topic: Measuring 0-14V PWM Signal using Microcontroller  (Read 558 times)

0 Members and 1 Guest are viewing this topic.

Offline x4ceTopic starter

  • Contributor
  • Posts: 32
  • Country: pk
Measuring 0-14V PWM Signal using Microcontroller
« on: August 12, 2024, 04:48:43 pm »
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
 

Offline PGPG

  • Regular Contributor
  • *
  • Posts: 137
  • Country: pl
Re: Measuring 0-14V PWM Signal using Microcontroller
« Reply #1 on: August 12, 2024, 06:57:47 pm »
MCU analog inputs have typically high input impedance so the resistor voltage divider + capacitor should be enough.
 
The following users thanked this post: x4ce

Offline x4ceTopic starter

  • Contributor
  • Posts: 32
  • Country: pk
Re: Measuring 0-14V PWM Signal using Microcontroller
« Reply #2 on: August 13, 2024, 04:00:43 am »
MCU analog inputs have typically high input impedance so the resistor voltage divider + capacitor should be enough.

Thank 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
« Last Edit: August 13, 2024, 04:07:13 am by x4ce »
 

Online BennoG

  • Regular Contributor
  • *
  • Posts: 140
  • Country: nl
Re: Measuring 0-14V PWM Signal using Microcontroller
« Reply #3 on: August 13, 2024, 05:32:10 am »
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
 
The following users thanked this post: x4ce

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10188
  • Country: nz
Re: Measuring 0-14V PWM Signal using Microcontroller
« Reply #4 on: August 13, 2024, 05:48:03 am »
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.
« Last Edit: August 13, 2024, 05:57:46 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 
The following users thanked this post: x4ce

Offline PGPG

  • Regular Contributor
  • *
  • Posts: 137
  • Country: pl
Re: Measuring 0-14V PWM Signal using Microcontroller
« Reply #5 on: August 13, 2024, 01:44:02 pm »
Please see attached preliminary circuit for the desired function. Any discrepancy/ suggestion for the given circuit will be appreciated.

In 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.
 
The following users thanked this post: x4ce

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 4248
  • Country: nl
Re: Measuring 0-14V PWM Signal using Microcontroller
« Reply #6 on: August 13, 2024, 04:08:33 pm »
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.

Offline x4ceTopic starter

  • Contributor
  • Posts: 32
  • Country: pk
Re: Measuring 0-14V PWM Signal using Microcontroller
« Reply #7 on: August 13, 2024, 07:36:27 pm »
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.

Thanks 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.
 

Offline x4ceTopic starter

  • Contributor
  • Posts: 32
  • Country: pk
Re: Measuring 0-14V PWM Signal using Microcontroller
« Reply #8 on: August 13, 2024, 07:40:32 pm »
Please see attached preliminary circuit for the desired function. Any discrepancy/ suggestion for the given circuit will be appreciated.

In 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.

Thanks, 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.
 

Offline x4ceTopic starter

  • Contributor
  • Posts: 32
  • Country: pk
Re: Measuring 0-14V PWM Signal using Microcontroller
« Reply #9 on: August 13, 2024, 07:43:56 pm »
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.

Thanks, 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
 

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 4248
  • Country: nl
Re: Measuring 0-14V PWM Signal using Microcontroller
« Reply #10 on: August 14, 2024, 06:22:08 am »
Moreover, the capacitor of 100nF would be fine to stabilize the PWM'ed input?

This 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.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf