Each internal peripheral system consists of one IE (interrupt Enable) bit which activates the internal interrupts of that peripheral. For example, in-built ADC of AVR consists of ADIE (ADC interrupt Enable) bit in ADCSRA register.
In addition, the I-bit of SREG is also activated to activate interrupts. SREG is a status register of AVR microcontroller which contains information about the result of most recently executed arithmetic instructions.
SREG (Status Register):
Bit 7-I: (Global interrupt Enable):
To activate Global Interrupts this bit must be set to high. If this bit is not enabled, none of the interrupts will work. “sei ()” command is used to enable the Global Interrupt, and “cli()” command is used to disable global interrupt.
For better clarification of internal interrupts, ADC interrupts is explained below:
In the article of AVR ADC, polling method is used to receive converted value. During the polling of a signal, microcontroller cannot perform another task. Hence, it is better to use interrupt method. ADC system consists of ADIE bit in ADCSRA register. ADIE bit is enabled to use ADC interrupts.
ADC in auto-triggering mode:
In A/D conversion ADSC bit remains high till the conversion is not completed. As soon as the, conversion gets completed, ADSC automatically gets cleared by hardware. Before starting the next conversion, ADSC must be set high again. Alternatively, auto triggering can be used to enable the ADSC bit after each conversion. The ADATE (ADC Auto Triggering Enable) bit in ADCSRA register is used to activate auto-triggering mode. There are various triggering options available in AVR ADC, which can be selected by configuring ADTS (ADC Triggering Select) bits in SFIOR register.
SFIOR (Special Function I/O register):
The following table shows the combination of ADTS [2:0] bits to select triggering source:
Objective: A/D conversion using interrupt method and display 10-bit digital output on LCD as integer form.
To initiate ADC:
1. Set the value in ADMUX register according to the ADC channel and the reference voltage.
2. Set the Prescaler bits accordingly in ADCSRA register.
3. Set the ADEN bit to enable the ADC.
4. Set ADIE bit to enable ADC interrupt.
5. Set ADATE bit to enable auto triggering.
6. Set ADSC bit to start conversion.
7. Configure SFIOR register to select trigger source.
void adc_init()// ADC configuration
// ADSC=1 ADC Enable
// ADPS[2:0]=111, prescaler=128
// ADIE=1, ADC interrupt Enable
//ADATE=1, ADC Auto Triggering Enable
//ADTS[2:0]= 100 , Timer0 overflow select as trigger source
To read converted value:
1. Start Trigger Source for auto-triggering of ADC.
2. Enable I-bit of SREG register to enable global Interrupt.
3. Store 10-bit converted data into 16-bit variable.
4. Convert the digital value to its corresponding ASCII value.
5. Display the converted value on LCD.