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.
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.
Value | Description |
---|---|
11 |
Reserved |
10 |
FVR buffer |
01 |
FVR+ (External Positive Voltage Reference) |
00 |
AVDD (Microcontroller VCC) |
Value | Description |
---|---|
1 |
VREF- (External Negative Voltage Reference) |
0 |
AVSS (Microcontroller GND) |
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.
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.
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.