Using a Microcontroller to read peak values

In summary, the individual is experiencing a problem with the analogRead feature of an Arduino microcontroller. They have written a function to sample the analog signal and save the highest read value, but the Arduino always returns the highest resolution value of 1023. They have tried using DC voltages for testing and it works perfectly. Suggestions are given to use a debugger and provide code, as well as to bias the signal and verify its value. The next step is to print analogRead directly to the Serial Monitor and check for bugs in the max algorithm.
  • #1
sherrellbc
83
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
  • #2
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...
 
  • #3
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.
 
  • #4
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?
 
  • #5
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.
 

1. What is a microcontroller and how does it work?

A microcontroller is a small computer chip that is designed to control and manage electronic devices. It contains a processor, memory, and other components that allow it to execute instructions and perform tasks. Microcontrollers are used in a wide range of applications, from simple household appliances to complex industrial machinery.

2. How can a microcontroller be used to read peak values?

A microcontroller can be programmed to read analog signals from sensors and convert them into digital values. By continuously sampling the signal and comparing the values, the microcontroller can determine the peak value of the signal and provide this information to the user.

3. What are the benefits of using a microcontroller to read peak values?

Using a microcontroller allows for precise and accurate measurement of peak values, as well as the ability to continuously monitor and record this data. It also eliminates the need for external circuitry and can be easily integrated into existing systems.

4. What types of sensors can be used with a microcontroller to read peak values?

There are various types of sensors that can be used with a microcontroller, such as temperature sensors, pressure sensors, light sensors, and more. The type of sensor used will depend on the specific application and the type of signal being measured.

5. What are some potential applications of using a microcontroller to read peak values?

Microcontrollers can be used in a wide range of applications, such as monitoring and controlling environmental conditions, managing power usage, and detecting anomalies in complex systems. They are also commonly used in data logging and analysis, as well as in the development of IoT devices.

Similar threads

  • Electrical Engineering
Replies
19
Views
2K
Replies
7
Views
4K
Replies
3
Views
1K
  • Computing and Technology
Replies
1
Views
6K
  • General Engineering
Replies
1
Views
763
  • Introductory Physics Homework Help
Replies
17
Views
384
Replies
9
Views
1K
  • Electrical Engineering
4
Replies
138
Views
22K
Replies
7
Views
8K
  • Electrical Engineering
Replies
3
Views
1K
Back
Top