Using a Microcontroller to read peak values

Click For Summary

Discussion Overview

The discussion revolves around using an Arduino microcontroller's analogRead feature to measure the peak value of a sinusoidal signal. Participants explore issues related to reading values accurately, debugging code, and ensuring proper signal conditioning for the ADC.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Experimental/applied

Main Points Raised

  • One participant describes a function that samples an analog signal and saves the highest value but consistently receives a maximum reading of 1023, even with a smaller input signal.
  • Another participant suggests testing the ADC with DC voltages to verify its behavior, which the original poster confirms works correctly.
  • There is a suggestion that the issue may stem from a bug in the program processing the AC waveform.
  • A request is made for the original poster to share their code and details on how the readings are being reported, including the setup of the ADC and the signal source.
  • Participants emphasize the importance of biasing the AC signal within the 0-5V range suitable for the ATmega's inputs, recommending a midpoint bias of 2.5V.
  • Questions are raised about the source of the signal and whether it has been independently verified.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the cause of the issue, with multiple competing views on debugging strategies and signal conditioning remaining unresolved.

Contextual Notes

Participants note the need for proper biasing of the AC signal and the potential for bugs in the code, but specific assumptions about the setup and signal characteristics are not fully clarified.

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.
 

Similar threads

  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
7K
Replies
17
Views
3K
Replies
7
Views
9K
Replies
138
Views
26K
  • · Replies 4 ·
Replies
4
Views
6K