2.1.4 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.
- Initialize the ADC module as mentioned in Temperature Measurement.
- 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 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.
- While measuring the ground the ADC interrupt and auto trigger (free running) mode 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. Auto triggering mode is disabled.
- Set the Start Conversion bit (ADSC) in ADCSRA to start the conversion.
- After ADIF bit becomes high, read the ADC data register pair (ADCL/ADCH) to get the 10-bit ADC result.
Test Steps
- Connect PB5 to switch SW0 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
measure_bandgap
function. - Run the code, press switch SW0, and shortly release it.
- At this point, the execution will
hit the breakpoint set inside the
measure_bandgap
function. - 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 Debug → Windows → I/O).