how to find peak voltage in ADC channel on atmega 328p

MrChips

Joined Oct 2, 2009
35,270
Are we allowed to use the internal 10-bit ADC of the ATmega328?

If yes, then keep sampling the analog input and record the highest value.

Edit: Duh, you already said it in your title. I need to read titles more often.:rolleyes:
 

panic mode

Joined Oct 10, 2011
5,420
Many ways to do it...
One is to rectify and filter voltage, that is ill give you peak directly

You could also detect zero crossing my moment and length of halfperiod (if you want to make it work for both 50 and 60 Hz) then take a reading after zero cross and quarter of period

Or use one of chips that are meant for them power management or monitoring

Of course there is a place for voltage divider...
 

-live wire-

Joined Dec 22, 2017
959
What is the source of this analog voltage, and what kind of accuracy do you want? What range is it in, and is it AC or DC? I think this is the best place to start. Then we can help you choose the best circuit.
 

DickCappels

Joined Aug 21, 2008
10,661
I did this on an ATTINY85. The machine runs a tight loop, reading the ADC and comparing it with the highest recorded value. If the ADC exceeds the highest recorded value, the ADC value is written as the highest recorded value. That's is how you find the peak.

It is also useful to use a "bleed down" function to cause the machine to reduce the highest recorded value over time, this too is taken care of in the tight loop. For example, every time through the loop you reduce the value of the highest recorded value by one.

Below is a representation of such a system The input is sent to the ADC. The blue trace is the value of the highest recorded value variable (shown by repeatedly sending the value to a DAC) and the yellow trace is the value of the incoming data (from the ADC)

upload_2018-8-29_23-53-47.png
 

-live wire-

Joined Dec 22, 2017
959
You can use input potential divider to read in higher voltages.
“Potential divider”
I don’t mean to be too technical, but VOLTAGE IS NOT ELECTRIC POTENTIAL ENERGY! Potential energy is measured in joules (watt seconds). Electric potential is the ability to deliver power over time. While as a beginner, it can help you understand it, that’s completely wrong. There is an important distinction. Voltage is an electric field, but it may not be able to supply much current, power, or power over time (real potential). That’s the end of my rant. ;)
 

MrChips

Joined Oct 2, 2009
35,270
“Potential divider”
I don’t mean to be too technical, but VOLTAGE IS NOT ELECTRIC POTENTIAL ENERGY! Potential energy is measured in joules (watt seconds). Electric potential is the ability to deliver power over time. While as a beginner, it can help you understand it, that’s completely wrong. There is an important distinction. Voltage is an electric field, but it may not be able to supply much current, power, or power over time (real potential). That’s the end of my rant. ;)
Then what the heck is a potentiometer?
Isn't that a "potential meter"?

How did this become a potential meter?

Don't be so pedantic!
 

danadak

Joined Mar 10, 2018
4,057
What is max frequency of waveform ? Add that to the prior post questions asked -

What is the source of this analog voltage, and what kind of accuracy do you want?
What range is it in, and is it AC or DC?
Regards, Dana.
 
Top