Bandgap Measurement

Task: Measure bandgap reference from Internal bandgap reference channel

In this program the initialize() routine is used to initialize the ADC module, and the SetREF2VCC() is used to configure Voltage Reference to VCC. MeasureGND() and MeasureCurrentBGsingle() respectively, are used to do dummy GND measurement and to measure the internal bandgap reference voltage.

  1. 1.Initialize the ADC module as mentioned in Temperature Measurement.
  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 connected to PB5 is pressed, configure the ADC to measure GND by setting MUX bit fields (MUX3:0) equal to 1111. This is done to discharge the capacitor of ADC.
  5. 5.While measuring the ground the ADC interrupt and auto trigger (free running) mode 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. Auto triggering mode is disabled.
  10. 10.Set the Start Conversion bit (ADSC) in ADCSRA to start the conversion.
  11. 11.After 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 switch SW0 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 measure_bandgap function.
  5. 5.Run the code, press switch SW0, and shortly release it.
  6. 6.At this point, the execution will hit the breakpoint set inside the measure_bandgap function.
  7. 7.Add the bg_val variable to watch window to see the ADC reading. The ADC result register can also be checked via the I/O view (using the menu DebugWindowsI/O).