Maker Pro
Maker Pro

Measuring peak voltage of square wave - ATmega328p

Hi all,

I'm a bit of a newbie at electronics so please be patient :)

I need to measure the peak voltage of a square wave oscillating at approximately 8kHz, I need to take a reading 100 times a second. I am already using an ATmega328p in my circuit and was hoping that one of the ADC pins would do the job.

I am not sure if the MCU will simply measure the average voltage in which case I'd need to multiply whatever voltage by some factor to get the actual voltage? The speed of the ADC is much higher than 8kHz I think, so would the MCU resolve the zero voltage sections and I'd have to do something clever in my code to ignore the lows and find the peak voltage? Am I thinking about this the wrong way completely?

A beautifully drawn representation of the signal I want to measure:
hxLGTtE.png


Thanks in advance,

Calloutman
 
The ADC will not measure an average voltage, it samples quickly and then measures that instantaneous voltage.

To get peak voltage, you would sample maybe 8 times in one period and then just choose the highest.

Bob
 

hevans1944

Hop - AC8NS
If these are square wave pulses of varying amplitudes but pretty much constant frequency (8 kHz), you could trigger an A/D conversion to occur a few microseconds after the leading edge of each pulse. I think the ATmega328p has the capability of triggering a single A/D conversion on the positive-going edge of a trigger pulse. Subsequent trigger pulses are ignored until you re-initiate the A/D conversion. A variable pulse-width monostable (one-shot) multivibrator could be used to "center" the A/D conversion near the middle of each pulse, but that probably isn't necessary if the pulse amplitude is stable after the positive transition.
 
I'm not sure how stable the signal will be or how noisy it'll be either yet. I need to do a bunch of testing when I get it all wired up. If my noise is low and pulses well defined, I'll probably be able to get away with hevans1944 suggestion. If I can't properly resolve the rising edge I'll probably end up taking 8-16 samples in a period and doing some statistics on them.

Thanks for the input, that was very helpful.
 
Top