Connect with us

Measuring peak voltage of square wave - ATmega328p

Discussion in 'Microcontrollers, Programming and IoT' started by Calloutman, Nov 26, 2014.

Scroll to continue with content
  1. Calloutman

    Calloutman

    2
    0
    Nov 26, 2014
    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:
    [​IMG]

    Thanks in advance,

    Calloutman
     
  2. BobK

    BobK

    7,682
    1,688
    Jan 5, 2010
    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
     
  3. hevans1944

    hevans1944 Hop - AC8NS

    4,647
    2,169
    Jun 21, 2012
    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.
     
  4. Calloutman

    Calloutman

    2
    0
    Nov 26, 2014
    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.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-