Using a Microcontroller to read peak values

AI Thread Summary
The discussion focuses on using an Arduino microcontroller to read the peak value of a sinusoidal signal via the analogRead feature. The user encounters an issue where the Arduino consistently returns the maximum value of 1023, even with a 1V peak input. Suggestions include testing the analog-to-digital converter (ADC) with DC voltages to verify functionality and ensuring proper biasing of the AC signal within the 0-5V range. It is recommended to print the raw analogRead values directly to the Serial Monitor for debugging, and to check the signal source for accuracy. Proper signal conditioning and debugging steps are essential for resolving the issue.
sherrellbc
Messages
83
Reaction score
0
I need to use the analogRead feature of an Arduino microcontroller to read the peak value of a sinusoidal signal. I wrote a function that sampled the analog signal many times more than the frequency of the input signal and saves the highest read value.

The problem being, the Arduino always returns the highest resolution value of 1023. Even when a smaller signal(1Vpeak) is fed in, the arduino only returns 1023.

Any suggestions?
 
Engineering news on Phys.org
sherrellbc said:
I need to use the analogRead feature of an Arduino microcontroller to read the peak value of a sinusoidal signal. I wrote a function that sampled the analog signal many times more than the frequency of the input signal and saves the highest read value.

The problem being, the Arduino always returns the highest resolution value of 1023. Even when a smaller signal(1Vpeak) is fed in, the arduino only returns 1023.

Any suggestions?

I'd suggest you test the ADC out using DC voltages at first, to see how it behaves. You can just use the wiper of a potentiometer to feed different DC voltages into it and see what the ADC reads out...
 
berkeman said:
I'd suggest you test the ADC out using DC voltages at first, to see how it behaves. You can just use the wiper of a potentiometer to feed different DC voltages into it and see what the ADC reads out...

It reads DC perfectly. I did exactly what you suggested.
 
So then it sounds like a bug in the program that is reading the AC waveform. What kind of debugger resources does the Arduino offer?
 
Post your code, as well as how you are getting this number to begin with. Are you having it reported by Serial.println() to the Serial Monitor? Is this the output of your max function, or printed straight from analogRead() with no other processing?

Also, a basic drawing of how your ADC is hooked up. If you're just hooking up a straight AC source to the ADC input, that's not the best. The ATmega's inputs are meant for 0-5V range, so you'll need to bias the signal somewhere in that range. 2.5V, being the midpoint of the range, is usually the best.

What is the source of your signal? Have you verified its value with an independent measurement to make sure it's actually the value you want it to be?

If it's biased properly, then the next step would be to program your board to print analogRead directly to the Serial Monitor. If you're coming up with sensible data from that, then start combing through your max algorithm for bugs.
 
Very basic question. Consider a 3-terminal device with terminals say A,B,C. Kirchhoff Current Law (KCL) and Kirchhoff Voltage Law (KVL) establish two relationships between the 3 currents entering the terminals and the 3 terminal's voltage pairs respectively. So we have 2 equations in 6 unknowns. To proceed further we need two more (independent) equations in order to solve the circuit the 3-terminal device is connected to (basically one treats such a device as an unbalanced two-port...
suppose you have two capacitors with a 0.1 Farad value and 12 VDC rating. label these as A and B. label the terminals of each as 1 and 2. you also have a voltmeter with a 40 volt linear range for DC. you also have a 9 volt DC power supply fed by mains. you charge each capacitor to 9 volts with terminal 1 being - (negative) and terminal 2 being + (positive). you connect the voltmeter to terminal A2 and to terminal B1. does it read any voltage? can - of one capacitor discharge + of the...
Thread 'Weird near-field phenomenon I get in my EM simulation'
I recently made a basic simulation of wire antennas and I am not sure if the near field in my simulation is modeled correctly. One of the things that worry me is the fact that sometimes I see in my simulation "movements" in the near field that seems to be faster than the speed of wave propagation I defined (the speed of light in the simulation). Specifically I see "nodes" of low amplitude in the E field that are quickly "emitted" from the antenna and then slow down as they approach the far...
Back
Top