Auto Triggering Using Timer0 Compare Event as Trigger Source

Task: Auto triggered conversion on ADC channel 0 by using Timer as trigger source.

In this program, the initialize_adc() routine is used to initialize the ADC module. The initialize_timer() routine configures the Timer0 for comparing A match event. The ADC result is read inside the corresponding ISR as soon as the conversion is completed. The ADC module will start the conversion whenever the timer reaches its compare match value (that is, in this example, every 10 milliseconds).

Note that by changing the 'OCR0A' compare register and timer0 clock prescaler bits in 'TCCR0B' register, the conversion interval (from 10 milliseconds) can be changed as per the application needs.

  1. Repeat steps 1-4 from the Single Conversion Mode.
  2. Set the ADC Interrupt Enable bit (ADIE) in ADCSRA to enable the ADC interrupt.
  3. Set the Auto Trigger Enable bit (ADATE) in ADCSRA to enable the auto triggered mode.
  4. Set the Auto Trigger Source bit fields (ADTS2:0) in ADC Control and Status Register B (ADCSRB) to 011 to use the Timer0 Compare Match A event as an ADC start trigger.
  5. Set the Waveform Generation Mode bit fields (WGM1:0) in TCCR0A to '10' (Clear Timer on Compare Match).
  6. Set the Timer0 Clock Select bit fields (CS2:0) in TCCR0B to '011' (ClkIO/64 → Prescaler).
  7. Set the Output Compare register A to the desired value (in this example 156) so that the ADC will convert the analog value to a 10 milliseconds (compare match event) interval.
  8. After the conversion is done (ADIF bit becomes high) the CPU executes an ADC interrupt service routine where the ADC data register pair (ADCL/ADCH) is read to get the 10-bit ADC result. An ADC conversion is triggered whenever the configured Timer0 compare match happens.

Test Steps

Refer to Test Steps.