Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Using a Microcontroller to read peak values

  1. Apr 10, 2013 #1
    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?
     
  2. jcsd
  3. Apr 10, 2013 #2

    berkeman

    User Avatar

    Staff: Mentor

    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...
     
  4. Apr 10, 2013 #3
    It reads DC perfectly. I did exactly what you suggested.
     
  5. Apr 10, 2013 #4

    berkeman

    User Avatar

    Staff: Mentor

    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?
     
  6. Apr 12, 2013 #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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Using a Microcontroller to read peak values
Loading...