4.2 Reading DAC Output Using ADC

This particular configuration, useful for applications such as calibration, involves two peripherals:
  • DAC for providing analog voltage to ADC channel
  • ADC for application functionalities

The user can configure the DAC output as input to ADC, the DAC positive reference input as FVR buffer, the negative reference input source as microcontroller GND (i.e., AVSS), and the DAC output routed to ADC as an input channel. The DAC output can be configured as an analog input channel to ADC by configuring the ADC input selection register.

Figure 4-4. DAC Output as ADC Input Configuration
The DAC1CON0 resister must be configured as per requirements. Figure 4-5 shows code generation using MCC for the DAC configuration.
Figure 4-5. DAC Configuration for Reading DAC Output Using ADC

The following code is generated by the MCC for the DAC configuration:

//DAC0EN enabled; NSS VSS; PSS FVR_buf2; OE1 disabled; OE2 disabled; 
void DAC1_Initialize(void)
{
    // DAC1EN enabled; NSS VSS; PSS FVR_buf2; OE1 disabled; OE2 disabled; 
    DAC1CON0 = 0x88;
    // DAC1R 0; 
    DAC1CON1 = 0x00;
}

Figure 4-6 showcases the block diagram of FVR, which can be used as a DAC positive reference input voltage. The FVRCON register is used to set the fixed reference voltage for DAC.

Figure 4-6. FVR Configuration for DAC Reference Voltage
Figure 4-7 shows how the MCC can be used to generate the code for FVR initialization.
Figure 4-7. MCC Configuration to Set the FVR Voltage as DAC Reference Voltage
The following code is generated by the MCC for the FVR configuration:
// FVRCON enabled; ADFVR [1:0] 2.048V; 
void FVR_Initialize(void)
{
    // CDAFVR off; FVREN enabled; TSRNG Lo_range; ADFVR 2x; TSEN disabled; 
    FVRCON = 0x82;
}
Table 4-5. Fixed Output Voltages from FVR
FVRCON.CDAFVR Value Buffer Voltage
ob11 4.096V
ob10 2.048V
ob01 1.024V
ob00 Buffer is Off
The value of the ADPCH register for configuring the DAC output as an input channel to ADC is 0b111110. Figure 4-8 shows the ADC module configuration to set the DAC output as input to the ADC channel.
Figure 4-8. MCC Configuration for Selecting DAC as an ADC Input

The following code is generated:

//code
ADPCH = 0x3E; // ADPCH DAC1;