2.5 Measurement of Bandgap Reference Voltage
Task: Measure the bandgap reference voltage.
The measure_gnd() routine measures the ground value. The
                measure_bandgap() routine measures the internal band gap reference
            voltage.
- Repeat steps 1-3 from the Single Conversion Mode.
 - Set the Voltage Reference bit fields (REFS1:0) in ADMUX equal to 01 to select AVCC as ADC voltage reference.
 - Set the ADC Interrupt Enable bit (ADIE) in ADCSRA equal to 1 to enable the ADC interrupt.
 - If the switch is pressed, wait till the switch is released, then it starts to measure GND by setting MUX bit fields (MUX3:0) equal to 1111. This is done to discharge the capacitor of the ADC.
 - While measuring the ground the ADC interrupt and auto trigger (free-running) modes are disabled.
 - Set the Start Conversion bit (ADSC) in ADCSRA to start the conversion.
 - After the conversion is done (ADIF bit becomes high) read the ADC data register pair (ADCL/ADCH) to get the 10-bit ADC result value.
 - Configure the MUX bit field (MUX3:0) equal to 1110 to select the bandgap reference voltage as ADC input. It should be measured after a 70 µs delay, because of the start-up time for the Bandgap reference.
 - Polling method is used for checking conversion complete. The Auto triggering mode is disabled.
 - Set the Start Conversion bit (ADSC) in ADCSRA to start the conversion.
 - After the ADIF bit becomes high, read the ADC data register pair (ADCL/ADCH) to get the 10-bit ADC result.
 
Test Steps
- Connect PB5 to one of the switches available on STK600.
 - Open the project in Atmel Studio 7. Press Alt+F5 to start debugging.
 - If debugWIRE is not already enabled, Atmel Studio will prompt to enable debugWIRE.
 - After it goes to debug mode, set
                    a breakpoint at the end of the function 
measure_bandgap. - Run the code and press the switch connected to PB5 and release it shortly.
 - At this point, execution will hit
                    the breakpoint set inside the 
measure_bandgapfunction. - Add the variable
                        
bg_valto the debug watch window to see the ADC reading. The ADC result register can also be checked via I/O view (using the menu Debug → Windows → I/O). 
