Free Running mode

Task: Free running conversion on ADC channel 0. Use of conversion complete interrupt.

In this program, the ADC module is initialized and runs in free running mode in the adc_free_run_mode() routine. As the ADC conversion complete interrupt is enabled, the Interrupt Service Routine for this interrupt will be triggered as soon as a conversion is completed. In Free Running mode, a new conversion will be started immediately after a conversion completes. The ADSC bit remains high during a conversion. The time between two consecutive ADC samples depends on the ADC conversion time.

  1. 1.Select ADC channel 0 by writing the Analog Channel Selection bit group in the ADC Multiplexer Selection register (ADMUX.MUX) to '0b0000'.
  2. 2.Select internal reference to 1.1V by writing the Reference Selection bit in ADMUX (ADMUX.REFS0) to '0'.
  3. 3.Enable the ADC module by writing the ADC Enable bit in the ADC Control and Status A register (ADCSRA.ADEN) to '1'.
  4. 4.Select system clock prescaling to 16 by writing the ADC Prescaler Select bit group in ADCSRA (ADCSRA.ADPS) to '0b100'.
  5. 5.Enable auto triggering by writing the ADC Auto Trigger Enable bit in ADCSRA (ADCSRA.ADATE) to '1'.
  6. 6.Enable free running mode by writing the ADC Auto Trigger Source bit group in the ADC Control and Status B register (ADCSRB.ADTS) to '0b000'.
  7. 7.Start the first conversion by writing the ADC Start Conversion bit in ADCSRA (ADCSRA.ADSC) to '1'.
  8. 8.Optionally, wait for the Interrupt Flag bit in the ADCSRA register to be set, indicating that a new conversion is finished.
  9. 9.After the conversion is over (ADIF bit becomes high) the CPU executes the ADC interrupt service routine where the ADC data register pair (ADCL/ADCH) is read to get the 10-bit ADC result.
Note: It is not necessary to wait for the interrupt flag when using free-running mode. However, to make sure of a fresh conversion, wait for the flag to set, clear it and then read the result.

Test Steps

Refer to Test Steps.