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.

  1. 1.Repeat steps 1-3 from the Single Conversion Mode.
  2. 2.Set the Voltage Reference bit fields (REFS1:0) in ADMUX equal to 01 to select AVCC as ADC voltage reference.
  3. 3.Set the ADC Interrupt Enable bit (ADIE) in ADCSRA equal to 1 to enable the ADC interrupt.
  4. 4.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.
  5. 5.While measuring the ground the ADC interrupt and auto trigger (free-running) modes are disabled.
  6. 6.Set the Start Conversion bit (ADSC) in ADCSRA to start the conversion.
  7. 7.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.
  8. 8.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.
  9. 9.Polling method is used for checking conversion complete. The Auto triggering mode is disabled.
  10. 10.Set the Start Conversion bit (ADSC) in ADCSRA to start the conversion.
  11. 11.After the ADIF bit becomes high, read the ADC data register pair (ADCL/ADCH) to get the 10-bit ADC result.
Test Steps
  1. 1.Connect PB5 to one of the switches available on STK600.
  2. 2.Open the project in Atmel Studio 7. Press Alt+F5 to start debugging.
  3. 3.If debugWIRE is not already enabled, Atmel Studio will prompt to enable debugWIRE.
  4. 4.After it goes to debug mode, set a breakpoint at the end of the function measure_bandgap.
  5. 5.Run the code and press the switch connected to PB5 and release it shortly.
  6. 6.At this point, execution will hit the breakpoint set inside the measure_bandgap function.
  7. 7.Add the variable bg_val to the debug watch window to see the ADC reading. The ADC result register can also be checked via I/O view (using the menu DebugWindowsI/O).