4.1 DAC Output as Reference Voltage

The following configuration can be used in an application where it is required to access the DAC output from an external pin.

Figure 4-1. DAC Output on DACxOUT1/2 Pin with Internal Reference Voltage Configuration

Here, the DAC positive and negative reference voltage is configured as microcontroller AVDD and AVSS, respectively. This configuration is required for the functionalities, where variable analog voltage is required as output from the DAC.

Table 4-1. DAC1CON0.PSS[1:0] DAC Positive Select Bit
Value Description
11 Reserved
10 FVR buffer
01 FVR+ (External Positive Voltage Reference)
00 AVDD (Microcontroller VCC)
Table 4-2. DAC1CON0.NSS DAC Negative Source Select Bit
Value Description
1 VREF- (External Negative Voltage Reference)
0 AVSS (Microcontroller GND)
Table 4-3. DAC1CON0.OE1 DAC Voltage Output Enable Bit
Value Description
1 DAC voltage level is output on the DAC1OUT1 pin
0 DAC voltage level is disconnected from the DAC1OUT1 pin

The DAC positive reference input source is configured as the microcontroller AVDD, the negative input source is configured as AVSS, and the output of the DAC is connected to the microcontroller Pin (GPIO Pin). The DAC1OUT1 pin must be configured as output and analog pin.

Table 4-4. Pin Allocation Table
28-Pin SPDIP, SOIC, SSOP 28-Pin (V)QFN A/D Reference Comparator
RA0 2 27 ANA0 C1IN0- C2IN0-
RA1 3 28 ANA1 C1IN1- C2IN1-
RA2 4 1 ANA2 DAC1OUT1 VREF-(DAC) VREF-(ADC) C1IN0+ C2IN0+
RA3 5 2 ANA3 VREF+(DAC) VREF+(ADC) C1IN1+
RA4 6 3 ANA4

The MCC is a graphical programing environment that generates code seamlessly. Easy-to-use GUI helps to generate the desired code, which can be easily inserted into the project. Figure 4-2 shows how to use the MCC for the DAC configuration.

Figure 4-2. MCC Configuration - DAC Output on DACxOUT1 Pin with Internal Reference Voltage
Figure 4-3. Pin Manager in MCC Configuration

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

void DAC1_Initialize(void)
{
    // DAC1EN enabled; NSS VSS; PSS VDD; OE1 enabled; OE2 disabled; 
    DAC1CON0 = 0xA0;
    // DAC1R 31; 
    DAC1CON1 = 0x1F; //Default input value 
}

The DAC output value is set by using the DACxCON1 register. The following MCC-generated API/function can be used for the same purpose.

void DAC1_SetOutput (uint8_t inputData)
{
    DAC1CON1 = inputData;
}

After initializing this configuration, the DAC output can be connected to the DAC1CON1 (i.e., the RA2 pin). This DAC configuration can be used as a reference voltage generator and waveform/signal generator. Some of the examples are listed in the MPLAB Xpress code Examples.