4.2 Reading DAC Output Using ADC
- 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.
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.
// FVRCON enabled; ADFVR [1:0] 2.048V;
void FVR_Initialize(void)
{
// CDAFVR off; FVREN enabled; TSRNG Lo_range; ADFVR 2x; TSEN disabled;
FVRCON = 0x82;
}
FVRCON.CDAFVR Value | Buffer Voltage |
---|---|
ob11 |
4.096V |
ob10 |
2.048V |
ob01 |
1.024V |
ob00 |
Buffer is Off |
The following code is generated:
//code
ADPCH = 0x3E; // ADPCH DAC1;