ADCSRA – ADC Control and Status Register A

Hi guys§
I need to work with low frequency, so I need an ADC clock slower. The higher prescaler is 128.
The best for me would be 1024 but it is not present in ADCSRA.
So I read in ATmega48A/PA/88A/PA/168A/PA/328/P [DATASHEET] at Pag 249.

“The first conversion after ADSC has been written after the ADC has been
enabled, or if ADSC is written at the same time as the ADC is enabled, will take 25 ADC clock cycles instead of
the normal 13. This first conversion performs initialization of the ADC.”

I don’t really understand what does it mean. Can you explain me?
Because if it means that I can have 25 ADC clock cycle instead of 13 for me is amazing!!
thank you all!

taken from this all description:

<<ADCSRA – ADC Control and Status Register A
• Bit 7 – ADEN: ADC Enable
Writing this bit to one enables the ADC. By writing it to zero, the ADC is turned off. Turning the ADC off while a
conversion is in progress, will terminate this conversion.
• Bit 6 – ADSC: ADC Start Conversion
In Single Conversion mode, write this bit to one to start each conversion. In Free Running mode, write this bit to
one to start the first conversion. The first conversion after ADSC has been written after the ADC has been
enabled, or if ADSC is written at the same time as the ADC is enabled, will take 25 ADC clock cycles instead of
the normal 13. This first conversion performs initialization of the ADC.
ADSC will read as one as long as a conversion is in progress. When the conversion is complete, it returns to
zero. Writing zero to this bit has no effect.
• Bit 5 – ADATE: ADC Auto Trigger Enable
When this bit is written to one, Auto Triggering of the ADC is enabled. The ADC will start a conversion on a
positive edge of the selected trigger signal. The trigger source is selected by setting the ADC Trigger Select bits,
ADTS in ADCSRB.
• Bit 4 – ADIF: ADC Interrupt Flag
This bit is set when an ADC conversion completes and the Data Registers are updated. The ADC Conversion
Complete Interrupt is executed if the ADIE bit and the I-bit in SREG are set. ADIF is cleared by hardware when
executing the corresponding interrupt handling vector. Alternatively, ADIF is cleared by writing a logical one to
the flag. Beware that if doing a Read-Modify-Write on ADCSRA, a pending interrupt can be disabled. This also
applies if the SBI and CBI instructions are used.
• Bit 3 – ADIE: ADC Interrupt Enable
When this bit is written to one and the I-bit in SREG is set, the ADC Conversion Complete Interrupt is activated.
• Bits 2:0 – ADPS[2:0]: ADC Prescaler Select Bits
These bits determine the division factor between the system clock frequency and the input clock to the ADC. >>

Giulialiuyi: I need to work with low frequency, so I need an ADC clock slower.

No, that has very little to do with each other. You can use delayMicroseconds() for a delay. If you want to sample data at a certain frequency, use a timer. For low frequency sample, millis() can be used. It is also possible to take 10 ADC samples and calculate the average.

Can you tell us about your project ? What kind of sample rate do you want, and how accurate should it be ?

After the registers are set, the first ADC conversion takes more time. However, that can be trivial because the after the mux is set, that might need some time to settle as well.

http://www.instructables.com/id/Arduino-Frequency-Detection/?ALLSTEPS

I am doing this, but I want to detect low frequency, and if I use only the 32 prescaler for frequency between à to 10 I have a lot of noise. He gives me frequency like 1000Hz instead of 1, 2 ect, I have seen that more I slow it down more it is precise! Using frequency detection of a sinusoide. I prefer not to use delay because I want to avoid as much as possible the use of timer0.

I would prefer using a simple rate of 1000Hz but I think it is impossible, is it?

Do you want the measure the frequency of a certain (digital) signal ? There are libraries for frequency counters. Google for : pjrc freqmeasure Or do you want to know the base frequency of an audio signal, then a FFT calculation should be used.

That code at instructables is so-so. It uses the ADC in free running mode, so a lower clock for the ADC will indeed slow it down. However I would not prefer that to make your project work. Could you use a RC filter at the input, to get rid of noise ? I don't know what the lowest possible detected frequency for that sketch is, there might be a limit somewhere.

I want measure the frequency of any kind of signal but analog! If I put a RC filter it is possible to avoid noise. I am sure there is a limit somewhere ( bad real world) but I don't know which one is it. Let me check about free running mode.. i didn't pay a lot of attention on it.

https://www.pjrc.com/teensy/td_libs_FreqMeasure.html

the code

void loop() {
  if (FreqMeasure.available()) {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 30) {
      float frequency FreqMeasure.countToFrequency(sum / count);
      Serial.println(frequency);
      sum = 0;
      count = 0;
    }

doesn't work...

what is float frequency FreqMeasure.countToFrequency(sum / count); ???

The FreqMeasure is for digital signals. Perhaps an opamp and filter should be used to get a clean digital signal.
I’m still not sure if you need to measure the frequency or measure the base frequeny in a audio signal with FFT.
You say that you want to measure any kind of signal but analog. That means : yes analog signal, or no analog signal ?
The sketch at instructables is for an analog signal, and the FreqMeasure is not.

Can you tell more about your project, and the lowest frequency that you want to measure ?

I accidently called it “free running mode”, but in the datasheet it is called “continuous mode”. The ADC runs on its own and generates an interrupt.

Can you tell more about your project, and the lowest frequency that you want to measure ?

I just have a generator (so I am talking about analog signal). My bandwith of frequency is from 0Hz to 50Hz. and it can be a square wave a sine wave a triangular wave and what else function can go out from the generator, and what I want to be able to do is to apply it to analog signal that are not with fixed shape or fixed frequency.

Is that clear?

I accidently called it "free running mode", but in the datasheet it is called "continuous mode".

Can you please indicate to me where is in the data sheet this part? Thank you!

Yes, that is clear :P Your signal is (sort of) analog, but it contains only one frequency. It is not an audio signal with multiple frequencies. You have to filter the signal and make a good digital signal. What about the amplitude ? Is it always a fixed amplitude ?

You need a good and proven library that can measure low frequencies. The FreqMeasure can do 0.1Hz to 1000Hz. Is that okay ? https://www.pjrc.com/teensy/td_libs_FreqMeasure.html

Guess what ? It is called "Free Running" after all :o In the complete datasheet, page 240: "In Free Running mode, a new conversion will be started immediately after the conversion completes" The register ADCSRB on page 251 shows the bits for the mode. It is like a trigger source that is always on.