CC26xx Driver Library
[aux_dac.h] AUX Digital to Analog Converter

Functions

void AUXDACSetVref (uint8_t refSource)
 Sets the voltage reference source. More...
 
void AUXDACEnablePreCharge (void)
 Enables DAC precharge. More...
 
void AUXDACDisablePreCharge (void)
 Disables DAC precharge. More...
 
uint32_t AUXDACCalcMax (void)
 Calculates the upper limit voltage the DAC can output. More...
 
uint32_t AUXDACCalcMin (void)
 Calculates the lower limit voltage the DAC can output. More...
 
uint32_t AUXDACCalcCode (uint32_t uVoltOut, uint32_t uVoltOutMin, uint32_t uVoltOutMax)
 Calculates the appropriate DAC code for a specific voltage value. More...
 
void AUXDACSetSampleClock (uint8_t dacClkDiv)
 Configures and sets the DAC sample clock. More...
 
void AUXDACSetCode (uint8_t dacCode)
 Updates the current DAC code. More...
 
void AUXDACEnable (uint8_t dacPinId)
 Enables the DAC. More...
 
void AUXDACDisable (void)
 Disables the DAC. More...
 

Detailed Description

Function Documentation

§ AUXDACCalcCode()

uint32_t AUXDACCalcCode ( uint32_t  uVoltOut,
uint32_t  uVoltOutMin,
uint32_t  uVoltOutMax 
)

Calculates the appropriate DAC code for a specific voltage value.

Once a voltage reference source has been selected with AUXDACSetVref and the DAC's output voltage range has been defined with AUXDACCalcMin and AUXDACCalcMax, a DAC code can be derived.

Parameters
uVoltOutThe desired output voltage in millivolts [mV].
uVoltOutMinThe minimum output voltage in millivolts [mV] which can be output by the DAC in the current configuration. It should be the value returned by AUXDACCalcMin.
uVoltOutMaxThe maximum output voltage in millivolts [mV] which can be output by the DAC in the current configuration. It should be the value returned by AUXDACCalcMax.
Returns
The dac code corresponding to the desired output value.
188 {
189  uint32_t dacCode = 0;
190 
191  if(uVoltOut != 0)
192  {
193  // Rounding (by adding 0.5 before truncating)
194  dacCode = (((254 * (uVoltOut - uVoltOutMin) * 2) / (uVoltOutMax - uVoltOutMin) + 1) / 2) + 1;
195  }
196  return (uint32_t)dacCode;
197 }

§ AUXDACCalcMax()

uint32_t AUXDACCalcMax ( void  )

Calculates the upper limit voltage the DAC can output.

This function uses calibration coefficients stored in the factory configuration area (FCFG1) to determine the DAC's output voltage that corresponds to DAC code 255. This voltage depends on the selected voltage reference source.

Note
This function must only be called after AUXDACSetVref has been called.
Returns
The maximum voltage in mV that the DAC can output given a specific reference voltage.
85 {
86  uint32_t prechargeStatus;
87  uint32_t refSource;
88  uint32_t dacMax;
89 
90  // Depending on the selected DAC voltage reference, obtain calibration value C2 in millivolts.
91  refSource = ((HWREGB(AUX_ADI4_BASE + ADI_4_AUX_O_MUX2) & ADI_4_AUX_MUX2_DAC_VREF_SEL_M) >> ADI_4_AUX_MUX2_DAC_VREF_SEL_S);
92 
93  switch (refSource)
94  {
95  // Nothing connected. Input is floating.
96  case AUXDAC_VREF_SEL_NC:
97 
98  dacMax = 0;
99  break;
100 
101  // Core Voltage Decoupling pin as the DAC's voltage reference source.
103 
104  prechargeStatus = ((HWREG( AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) & AUX_ANAIF_DACCTL_DAC_PRECHARGE_EN_M) >> AUX_ANAIF_DACCTL_DAC_PRECHARGE_EN_S);
105  dacMax = (prechargeStatus == 0) ? ((HWREG(FCFG1_BASE + FCFG1_O_DAC_CAL0) & FCFG1_DAC_CAL0_SOC_DAC_VOUT_CAL_DECOUPLE_C2_M) >> FCFG1_DAC_CAL0_SOC_DAC_VOUT_CAL_DECOUPLE_C2_S) \
106  : ((HWREG(FCFG1_BASE + FCFG1_O_DAC_CAL1) & FCFG1_DAC_CAL1_SOC_DAC_VOUT_CAL_PRECH_C2_M) >> FCFG1_DAC_CAL1_SOC_DAC_VOUT_CAL_PRECH_C2_S);
107  break;
108 
109  // ADC reference voltage as the DAC's voltage reference source.
111 
112  dacMax = ((HWREG(FCFG1_BASE + FCFG1_O_DAC_CAL2) & FCFG1_DAC_CAL2_SOC_DAC_VOUT_CAL_ADCREF_C2_M) >> FCFG1_DAC_CAL2_SOC_DAC_VOUT_CAL_ADCREF_C2_S);
113  break;
114 
115  // Main supply voltage VDDS as the DAC's voltage reference source.
117 
118  // Note: The calibration value is measured at a VDDS of 3.0V. If VDDS is selected as reference,
119  // measure VDDS and scale the calibration value.
120  dacMax = ((HWREG(FCFG1_BASE + FCFG1_O_DAC_CAL3) & FCFG1_DAC_CAL3_SOC_DAC_VOUT_CAL_VDDS_C2_M) >> FCFG1_DAC_CAL3_SOC_DAC_VOUT_CAL_VDDS_C2_S);
121  break;
122 
123  // Nothing connected. Input is floating.
124  default:
125 
126  dacMax = 0;
127  }
128 
129  return dacMax;
130 }
#define AUXDAC_VREF_SEL_VDDS
Definition: aux_dac.h:99
#define AUXDAC_VREF_SEL_NC
Definition: aux_dac.h:102
#define AUXDAC_VREF_SEL_DCOUPL
Definition: aux_dac.h:101
#define AUXDAC_VREF_SEL_ADCREF
Definition: aux_dac.h:100

§ AUXDACCalcMin()

uint32_t AUXDACCalcMin ( void  )

Calculates the lower limit voltage the DAC can output.

This function uses calibration coefficients stored in the factory configuration area (FCFG1) to determine the DAC's output voltage that corresponds to DAC code 1. This voltage depends on the selected voltage reference source.

DAC Code 0 corresponds to 0 V. Therefore, the DAC can only output 0 V and values between the lower limit defined by this function and the upper limit defined by AUXDACCalcMax.

Note
This function must only be called after AUXDACSetVref has been called.
Returns
The minimum voltage (other than 0 V) in mV that the DAC can output given a specific reference voltage.
139 {
140  uint32_t refSource;
141  uint32_t prechargeStatus;
142  uint32_t dacMin;
143 
144  // Depending on the selected DAC voltage reference, obtain calibration value C1 in millivolts.
145  refSource = ((HWREGB(AUX_ADI4_BASE + ADI_4_AUX_O_MUX2) & ADI_4_AUX_MUX2_DAC_VREF_SEL_M) >> ADI_4_AUX_MUX2_DAC_VREF_SEL_S);
146 
147  switch (refSource)
148  {
149  // Nothing connected. Input is floating.
150  case AUXDAC_VREF_SEL_NC:
151  dacMin = 0;
152  break;
153 
154  // Core Voltage Decoupling pin as the DAC's voltage reference source.
156 
157  prechargeStatus = ((HWREG(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) & AUX_ANAIF_DACCTL_DAC_PRECHARGE_EN_M) >> AUX_ANAIF_DACCTL_DAC_PRECHARGE_EN_S);
158  dacMin = (prechargeStatus == 0) ? ((HWREG(FCFG1_BASE + FCFG1_O_DAC_CAL0) & FCFG1_DAC_CAL0_SOC_DAC_VOUT_CAL_DECOUPLE_C1_M) >> FCFG1_DAC_CAL0_SOC_DAC_VOUT_CAL_DECOUPLE_C1_S) \
159  : ((HWREG(FCFG1_BASE + FCFG1_O_DAC_CAL1) & FCFG1_DAC_CAL1_SOC_DAC_VOUT_CAL_PRECH_C1_M) >> FCFG1_DAC_CAL1_SOC_DAC_VOUT_CAL_PRECH_C1_S);
160  break;
161 
162  // ADC reference voltage as the DAC's voltage reference source.
164  dacMin = ((HWREG( FCFG1_BASE + FCFG1_O_DAC_CAL2) & FCFG1_DAC_CAL2_SOC_DAC_VOUT_CAL_ADCREF_C1_M) >> FCFG1_DAC_CAL2_SOC_DAC_VOUT_CAL_ADCREF_C1_S);
165  break;
166 
167  // Main supply voltage VDDS as the DAC's voltage reference source.
169  dacMin = ((HWREG( FCFG1_BASE + FCFG1_O_DAC_CAL3) & FCFG1_DAC_CAL3_SOC_DAC_VOUT_CAL_VDDS_C1_M) >> FCFG1_DAC_CAL3_SOC_DAC_VOUT_CAL_VDDS_C1_S);
170  break;
171 
172  // Nothing connected. Input is floating.
173  default:
174 
175  dacMin = 0;
176  }
177 
178  return dacMin;
179 }
#define AUXDAC_VREF_SEL_VDDS
Definition: aux_dac.h:99
#define AUXDAC_VREF_SEL_NC
Definition: aux_dac.h:102
#define AUXDAC_VREF_SEL_DCOUPL
Definition: aux_dac.h:101
#define AUXDAC_VREF_SEL_ADCREF
Definition: aux_dac.h:100

§ AUXDACDisable()

void AUXDACDisable ( void  )

Disables the DAC.

This function disables the DAC sample clock, the DAC buffer, the DAC. It also disconnects COMPA_IN internally.

Note
This function must be called only after AUXDACEnable has been called.
258 {
259  // Disable the DAC sample clock
260  HWREGB(AUX_ANAIF_BASE + AUX_ANAIF_O_DACSMPLCTL) = 0x0;
261 
262  // Disable DAC, the DAC's buffer, and disconnect internally.
263  HWREGB(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) &= ~(0x1 << AUX_ANAIF_DACCTL_DAC_EN_S) & \
264  ~(0x1 << AUX_ANAIF_DACCTL_DAC_BUFFER_EN_S) & \
265  ~(AUX_ANAIF_DACCTL_DAC_VOUT_SEL_M << AUX_ANAIF_DACCTL_DAC_VOUT_SEL_S);
266 
267  // Disconnect COMPA_IN from DIOs
268  HWREGB(AUX_ADI4_BASE + ADI_4_AUX_O_MUX1) = 0x0;
269 
270  // Set operational mode to Power-Down
271  HWREG(AUX_SYSIF_BASE + AUX_SYSIF_O_OPMODEREQ) = AUX_SYSIF_OPMODEREQ_REQ_PDA;
272 
273  // Set the peripheral operational rate to the SCE rate
274  HWREGB(AUX_SYSIF_BASE + AUX_SYSIF_O_PEROPRATE) = AUX_SYSIF_PEROPRATE_ANAIF_DAC_OP_RATE_SCE_RATE;
275 }

§ AUXDACDisablePreCharge()

void AUXDACDisablePreCharge ( void  )

Disables DAC precharge.

If AUXDAC_VREF_SEL_DCOUPL has been selected as a voltage reference source, the DAC's output voltage range can be further controlled by enabling or disabling precharge.

When precharge is disabled the DAC's output voltage will range from 0 V to 1.28 V.

Note
This function must only be called if AUXDAC_VREF_SEL_DCOUPL has been selected as a voltage reference source and while the DAC is disabled, before calling AUXDACEnable().
74 {
75  HWREG(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) &= ~(0x1 << AUX_ANAIF_DACCTL_DAC_PRECHARGE_EN_S);
76 }

§ AUXDACEnable()

void AUXDACEnable ( uint8_t  dacPinId)

Enables the DAC.

This function enables the DAC sample clock and the DAC buffer. It selects COMPA_IN as output, and it routes the DAC's output to the given I/O pin.

Parameters
dacPinIdAnalog capable I/O pin:
234 {
235  // Set the operational mode to active
236  HWREG(AUX_SYSIF_BASE + AUX_SYSIF_O_OPMODEREQ) = AUX_SYSIF_OPMODEREQ_REQ_A;
237 
238  // Disable the low power bias control
239  HWREGB(AUX_ANAIF_BASE + AUX_ANAIF_O_LPMBIASCTL) = 0x0;
240 
241  // Enable the DAC sample clock
242  HWREGB(AUX_ANAIF_BASE + AUX_ANAIF_O_DACSMPLCTL) = AUX_ANAIF_DACSMPLCTL_EN;
243 
244  // Enable DAC and buffer and set COMPA_IN
245  HWREGB(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) |= AUX_ANAIF_DACCTL_DAC_EN | AUX_ANAIF_DACCTL_DAC_BUFFER_EN | AUX_ANAIF_DACCTL_DAC_VOUT_SEL_COMPA_IN;
246 
247  // Select COMPA output (0 will disconnect from DIOs)
248  HWREGB(AUX_ADI4_BASE + ADI_4_AUX_O_MUX1) = dacPinId;
249 }

§ AUXDACEnablePreCharge()

void AUXDACEnablePreCharge ( void  )

Enables DAC precharge.

If AUXDAC_VREF_SEL_DCOUPL has been selected as a voltage reference source, the DAC's output voltage range can be further controlled by enabling or disabling precharge.

When precharge is enabled the DAC's output voltage will range from 1.28 V to 2.56 V.

Note
This function must only be called if AUXDAC_VREF_SEL_DCOUPL has been selected as a voltage reference source and while the DAC is disabled, before calling AUXDACEnable().
63 {
64  HWREG(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) |= AUX_ANAIF_DACCTL_DAC_PRECHARGE_EN;
65 }

§ AUXDACSetCode()

void AUXDACSetCode ( uint8_t  dacCode)

Updates the current DAC code.

This function is meant to be used after AUXDACEnable has been called. It allows to update the DAC code by rapidly disabling the DAC, setting the new DAC code, and then rapidly re-enabling the DAC.

Parameters
dacCodeThe new DAC code
222 {
223  // Update the DAC's output value.
224  HWREGB(AUX_ANAIF_BASE + AUX_ANAIF_O_DACVALUE) = dacCode;
225 }

§ AUXDACSetSampleClock()

void AUXDACSetSampleClock ( uint8_t  dacClkDiv)

Configures and sets the DAC sample clock.

This function determines the sample clock base frequency considering that the operational rate for the DAC sample clock state machine is the AUX Bus Rate.

AUX Bus Rate divided by (dacClkDiv + 1) determines the sample clock base frequency.

Note
This function must be called before AUXDACEnable.
Parameters
dacClkDivThe clock division factor
206 {
207 
208  // Set the peripheral operational rate to the AUX bus rate of 24 MHz.
209  HWREGB(AUX_SYSIF_BASE + AUX_SYSIF_O_PEROPRATE) |= AUX_SYSIF_PEROPRATE_ANAIF_DAC_OP_RATE_BUS_RATE;
210 
211  // Set sample clock frequency considering a clock base frequency of 24 MHz and the given clock divider.
212  HWREGB(AUX_ANAIF_BASE + AUX_ANAIF_O_DACSMPLCFG0) = dacClkDiv;
213 }

§ AUXDACSetVref()

void AUXDACSetVref ( uint8_t  refSource)

Sets the voltage reference source.

The DAC's output range depends on the selection of a voltage reference source. This function must be called before enabling the DAC using AUXDACEnable() or before setting a DAC code using AUXDACCalcCode().

Parameters
refSourceDAC voltage reference source:
46 {
47  HWREGB(AUX_ADI4_BASE + ADI_4_AUX_O_MUX2) = refSource;
48 
49  if(refSource == AUXDAC_VREF_SEL_ADCREF)
50  {
51  // Enable the ADC reference module.
52  HWREGB(AUX_ADI4_BASE + ADI_4_AUX_O_ADCREF0) |= ADI_4_AUX_ADCREF0_REF_ON_IDLE | ADI_4_AUX_ADCREF0_EN;
53  }
54 }
#define AUXDAC_VREF_SEL_ADCREF
Definition: aux_dac.h:100

Macro Definition Documentation

§ AUXDAC_COMPA_IN_AUXIO0

#define AUXDAC_COMPA_IN_AUXIO0   AUXDAC_COMPA_IN_AUXIO19

§ AUXDAC_COMPA_IN_AUXIO1

#define AUXDAC_COMPA_IN_AUXIO1   AUXDAC_COMPA_IN_AUXIO20

§ AUXDAC_COMPA_IN_AUXIO19

#define AUXDAC_COMPA_IN_AUXIO19   0x80

§ AUXDAC_COMPA_IN_AUXIO2

#define AUXDAC_COMPA_IN_AUXIO2   AUXDAC_COMPA_IN_AUXIO21

§ AUXDAC_COMPA_IN_AUXIO20

#define AUXDAC_COMPA_IN_AUXIO20   0x40

§ AUXDAC_COMPA_IN_AUXIO21

#define AUXDAC_COMPA_IN_AUXIO21   0x20

§ AUXDAC_COMPA_IN_AUXIO22

#define AUXDAC_COMPA_IN_AUXIO22   0x10

§ AUXDAC_COMPA_IN_AUXIO23

#define AUXDAC_COMPA_IN_AUXIO23   0x08

§ AUXDAC_COMPA_IN_AUXIO24

#define AUXDAC_COMPA_IN_AUXIO24   0x04

§ AUXDAC_COMPA_IN_AUXIO25

#define AUXDAC_COMPA_IN_AUXIO25   0x02

§ AUXDAC_COMPA_IN_AUXIO26

#define AUXDAC_COMPA_IN_AUXIO26   0x01

§ AUXDAC_COMPA_IN_AUXIO3

#define AUXDAC_COMPA_IN_AUXIO3   AUXDAC_COMPA_IN_AUXIO22

§ AUXDAC_COMPA_IN_AUXIO4

#define AUXDAC_COMPA_IN_AUXIO4   AUXDAC_COMPA_IN_AUXIO23

§ AUXDAC_COMPA_IN_AUXIO5

#define AUXDAC_COMPA_IN_AUXIO5   AUXDAC_COMPA_IN_AUXIO24

§ AUXDAC_COMPA_IN_AUXIO6

#define AUXDAC_COMPA_IN_AUXIO6   AUXDAC_COMPA_IN_AUXIO25

§ AUXDAC_COMPA_IN_AUXIO7

#define AUXDAC_COMPA_IN_AUXIO7   AUXDAC_COMPA_IN_AUXIO26

§ AUXDAC_COMPA_IN_NC

#define AUXDAC_COMPA_IN_NC   0x00

§ AUXDAC_VREF_SEL_ADCREF

#define AUXDAC_VREF_SEL_ADCREF   ADI_4_AUX_MUX2_DAC_VREF_SEL_ADCREF

§ AUXDAC_VREF_SEL_DCOUPL

#define AUXDAC_VREF_SEL_DCOUPL   ADI_4_AUX_MUX2_DAC_VREF_SEL_DCOUPL

Referenced by AUXDACCalcMax(), and AUXDACCalcMin().

§ AUXDAC_VREF_SEL_NC

#define AUXDAC_VREF_SEL_NC   ADI_4_AUX_MUX2_DAC_VREF_SEL_NC

Referenced by AUXDACCalcMax(), and AUXDACCalcMin().

§ AUXDAC_VREF_SEL_VDDS

#define AUXDAC_VREF_SEL_VDDS   ADI_4_AUX_MUX2_DAC_VREF_SEL_VDDS

Referenced by AUXDACCalcMax(), and AUXDACCalcMin().