6.1 ADC Differential Mode Setup
- Edit adc_init() to configure ADC in Differential mode, with the Force Click board as MUXPOS and DACREF0 as MUXNEG
- Transmit the data to the Data Visualizer
- Set up the DAC voltage reference to about
half of the Force Click board max voltage
or
VDD/2:
VREF.CTRLA = VREF_AC0REFSEL_2V048_gc; /* Voltage reference for AC */ AC0.DACREF = 0xCE; /* Will generate V_DACREF = 1.65V */
- Set up the ADC voltage
reference:
ADC0.CTRLC = ADC_REFSEL_2048MV_gc | ((uint8_t)TIMEBASE_VALUE << ADC_TIMEBASE0_bp);/*ADC voltage reference*/
Info:The ADC voltage reference sets the upper limit for the ADC input range. Any values above this range will be interpreted as VREF. In Differential mode, the upper limit is for the difference between two inputs and not the individual inputs. Therefore, will be interpreted correctly, even if .
- Configure the MUXPOS register to
have the Force Click board as an input
source:
ADC0.MUXPOS = ADC_MUXPOS_AIN5_gc;
- Configure the MUXNEG to have the
DAC reference as an input
source:
ADC0.MUXNEG = ADC_MUXNEG_DAC_gc;
Info:The input signal from MUXPOS will now be measured in relation to MUXNEG. In Single-Ended mode, MUXPOS is measured in relation to ground.
- Configure the ADC in Differential mode, with
the 12-bit Single Operational
mode:
ADC0.COMMAND |= ADC_DIFF_bm | ADC_MODE_SINGLE_12BIT_gc;
- Add the following code in main.c to calculate the voltage difference between
MUXPOS and MUXNEG. The calculation is done in the while(1)
loop:
/* Formula shows how much MUXPOS and MUXNEG differ from each other in Volt */ adc_t.adc_differential_volt = (float)((adc_t.adc_sample * 2.048) / ADC_MAX_VALUE);
Info:For Differential mode, the data format is two’s complement with sign extension. The data type of the sample variable should be int16_t when using Differential mode. The data type of the result variable should be int32_t when using Differential mode. Float is used here to calculate signed decimal numbers.
- Verify that the solution builds with no errors by selecting Build → Build Solution from the top menu bar in Microchip Studio or pressing the F7 key.
- Flash the device by selecting Debug → Start without debugging for the top menu bar in Microchip Studio or pressing the Ctrl+Alt+F5 keys.
- Verify hardware connections. Make sure the Force Click board is connected to socket 3 on the Curiosity Nano Adapter.
- Plot the single ADC sample and voltage
difference using the Data Visualizer by loading the workspace
Assignment5.json. Try changing the DAC voltage reference and study
its effect on the plotted range.Tip: To change VDACREF, either change the DACREF number or the voltage reference for AC. This is described in step 1 of Assignment 3.
Since MUXNEG now is connected to the voltage reference 1.65V, as seen in Figure 6-1 rather than GND, the new zero for the MUXPOS input is 1.65V. For the Force Click board with a range of [0,3.3V], the ADC output will be from [-1.65,1.65V]. See Figure 6-1.
By setting the VDACREF to 1.024V, the measurements are shifted upwards in the measured range. The resulting range is from about [-1.024V, 2.048V]. This range is too small for the Force Click board since the highest difference is 2.276V with the range [0,3.3V]. All the values above 2.048V will therefore be interpreted as 2.048V by the ADC. The clipping that occurs is visible in Figure 6-2, where the top value never exceeds 2.048V.
A convenient property of the differential measurement is that since the signal is measured in relation to DACREF instead of ground, it is possible to adjust DACREF to be in the middle of the expected input for MUXPOS. The necessary range can therefore be tailored to a specific signal if the bounds are known. This can allow for higher gain and lowering the voltage reference used by the ADC.