1

I'm building a frequency meter using as input a sine wave between 0.05V-0.55V (from a peak detector) and a frequency range between 5Khz-10Khz. I tried to change the sampling rate (I need at least 20Khz) to 76Khz (setting 16 prescaler from ADCSRA register), but the resulting data from ADC it's a constant (=255). I didn't find anything which could cause this constant output.

Having a higher sampling rate means that I could find more precisely the max amplitudes and then I could measure the time period between two max amplitudes resulting the frequency.

Any help or tips would be much appreciated! Thanks in advance!

The output: https://www.dropbox.com/s/jyguxpz8k18zsco/output.png?dl=0

The input: https://www.dropbox.com/s/94ou221vn89ndj0/sine_wave.jpg?dl=0

const int MAX_RESULTS = 256;
volatile int results [MAX_RESULTS];
volatile int resultNumber;

void setup() {
  ADMUX = 0x20; // set A0 analog input
  ADCSRA = 0xEC;// set 16 prescaler, enable ADC and interrupts and start ADC measurements
  Serial.begin(115200);
}

  ISR (ADC_vect)
{
    results[resultNumber++] = ADCH;
    if(resultNumber == MAX_RESULTS)
    {
      ADCSRA = 0;  // turn off ADC
    }

}

void loop () {
  while (resultNumber < MAX_RESULTS)
    { }

 for (int i = 0; i < MAX_RESULTS; i++)
  {
    Serial.println (results[i]);
  }
  //start a new conversion
  resultNumber = 0; 
  ADCSRA = 0xEC;
}
Tr19
  • 11
  • 4
  • The problem's here: ADMUX = 0x20, this value means that I disabled the internal reference. I changed 0x20 to 0x60, it works fine, but I'm thinking how to calculate the frequency for this output wave: https://www.dropbox.com/s/9ce297vr7b77d19/out.png?dl=0 – Tr19 Apr 21 '20 at 13:34

0 Answers0