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.
202 {
203  uint32_t dacCode = 0;
204 
205  if(uVoltOut != 0)
206  {
207  // Rounding (by adding 0.5 before truncating)
208  dacCode = (((254 * (uVoltOut - uVoltOutMin) * 2) / (uVoltOutMax - uVoltOutMin) + 1) / 2) + 1;
209  }
210  return (uint32_t)dacCode;
211 }

§ 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.
99 {
100  uint32_t prechargeStatus;
101  uint32_t refSource;
102  uint32_t dacMax;
103 
104  // Depending on the selected DAC voltage reference, obtain calibration value C2 in millivolts.
105  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);
106 
107  switch (refSource)
108  {
109  // Nothing connected. Input is floating.
110  case AUXDAC_VREF_SEL_NC:
111 
112  dacMax = 0;
113  break;
114 
115  // Core Voltage Decoupling pin as the DAC's voltage reference source.
117 
118  prechargeStatus = ((HWREG( AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) & AUX_ANAIF_DACCTL_DAC_PRECHARGE_EN_M) >> AUX_ANAIF_DACCTL_DAC_PRECHARGE_EN_S);
119  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) \
120  : ((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);
121  break;
122 
123  // ADC reference voltage as the DAC's voltage reference source.
125 
126  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);
127  break;
128 
129  // Main supply voltage VDDS as the DAC's voltage reference source.
131 
132  // Note: The calibration value is measured at a VDDS of 3.0V. If VDDS is selected as reference,
133  // measure VDDS and scale the calibration value.
134  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);
135  break;
136 
137  // Nothing connected. Input is floating.
138  default:
139 
140  dacMax = 0;
141  }
142 
143  return dacMax;
144 }
#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.
153 {
154  uint32_t refSource;
155  uint32_t prechargeStatus;
156  uint32_t dacMin;
157 
158  // Depending on the selected DAC voltage reference, obtain calibration value C1 in millivolts.
159  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);
160 
161  switch (refSource)
162  {
163  // Nothing connected. Input is floating.
164  case AUXDAC_VREF_SEL_NC:
165  dacMin = 0;
166  break;
167 
168  // Core Voltage Decoupling pin as the DAC's voltage reference source.
170 
171  prechargeStatus = ((HWREG(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) & AUX_ANAIF_DACCTL_DAC_PRECHARGE_EN_M) >> AUX_ANAIF_DACCTL_DAC_PRECHARGE_EN_S);
172  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) \
173  : ((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);
174  break;
175 
176  // ADC reference voltage as the DAC's voltage reference source.
178  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);
179  break;
180 
181  // Main supply voltage VDDS as the DAC's voltage reference source.
183  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);
184  break;
185 
186  // Nothing connected. Input is floating.
187  default:
188 
189  dacMin = 0;
190  }
191 
192  return dacMin;
193 }
#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.
288 {
289  // Disable the DAC sample clock
290  HWREGB(AUX_ANAIF_BASE + AUX_ANAIF_O_DACSMPLCTL) = 0x0;
291 
292  // Disable DAC, the DAC's buffer, and disconnect internally.
293  HWREGB(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) &= ~(0x1 << AUX_ANAIF_DACCTL_DAC_EN_S) & \
294  ~(0x1 << AUX_ANAIF_DACCTL_DAC_BUFFER_EN_S) & \
295  ~(AUX_ANAIF_DACCTL_DAC_VOUT_SEL_M << AUX_ANAIF_DACCTL_DAC_VOUT_SEL_S);
296 
297  // Disconnect COMPA_IN from DIOs
298  HWREGB(AUX_ADI4_BASE + ADI_4_AUX_O_MUX1) = 0x0;
299 
300  // Set operational mode to Power-Down
301  HWREG(AUX_SYSIF_BASE + AUX_SYSIF_O_OPMODEREQ) = AUX_SYSIF_OPMODEREQ_REQ_PDA;
302 
303  // Set the peripheral operational rate to the SCE rate
304  HWREGB(AUX_SYSIF_BASE + AUX_SYSIF_O_PEROPRATE) = AUX_SYSIF_PEROPRATE_ANAIF_DAC_OP_RATE_SCE_RATE;
305 }

§ 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().
88 {
89  HWREG(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) &= ~(0x1 << AUX_ANAIF_DACCTL_DAC_PRECHARGE_EN_S);
90 }

§ 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:
264 {
265  // Set the operational mode to active
266  HWREG(AUX_SYSIF_BASE + AUX_SYSIF_O_OPMODEREQ) = AUX_SYSIF_OPMODEREQ_REQ_A;
267 
268  // Disable the low power bias control
269  HWREGB(AUX_ANAIF_BASE + AUX_ANAIF_O_LPMBIASCTL) = 0x0;
270 
271  // Enable the DAC sample clock
272  HWREGB(AUX_ANAIF_BASE + AUX_ANAIF_O_DACSMPLCTL) = AUX_ANAIF_DACSMPLCTL_EN;
273 
274  // Enable DAC and buffer and set COMPA_IN
275  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;
276 
277  // Select COMPA output (0 will disconnect from DIOs)
278  HWREGB(AUX_ADI4_BASE + ADI_4_AUX_O_MUX1) = dacPinId;
279 }

§ 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().
77 {
78  HWREG(AUX_ANAIF_BASE + AUX_ANAIF_O_DACCTL) |= AUX_ANAIF_DACCTL_DAC_PRECHARGE_EN;
79 }

§ 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
252 {
253  // Update the DAC's output value.
254  HWREGB(AUX_ANAIF_BASE + AUX_ANAIF_O_DACVALUE) = dacCode;
255 }

§ AUXDACSetSampleClock()

void AUXDACSetSampleClock ( uint8_t  dacClkDiv)

Configures and sets the DAC sample clock.

This function determines the sample clock frequency assuming that the operational rate for the DAC sample clock state machine is the AUX Bus Rate. AUX Bus frequency (24 MHz) divided by (dacClkDiv + 1) determines the sample base clock frequency(SBCLK).

In this implementation, the high and low hold period (H_PER and L_PER) are both set to 4 periods, resulting in a DAC sample clock of SBCLK/8.

The formula (24 MHz / (dacCLKDiv +1)) / 8 describes the final DAC Sample Clock Frequency. For example, dacCLKDiv = 11 gives SBCLK frequency = 24 MHz / (11+1) = 2 MHz, which gives DAC sample clock frequency = 2 MHz / 8 = 250 KHz.

Note
The max sample clock frequency supported by the DAC is 1 MHz for internal load and 250 kHz for external load. The current implementation of the DAC driver assumes that it will be used to drive an internal load. Please refer to the register description before changing sample clock configuration settings. The DAC may behave unexpectedly if the sample clock operates at unsupported frequencies.
This function must be called before AUXDACEnable.
Parameters
dacClkDivThe clock division factor
220 {
221 
222  // Set the peripheral operational rate to the AUX bus rate of 24 MHz.
223  HWREGB(AUX_SYSIF_BASE + AUX_SYSIF_O_PEROPRATE) |= AUX_SYSIF_PEROPRATE_ANAIF_DAC_OP_RATE_BUS_RATE;
224 
225  // Configure sample base clock (SBCLK). SBCLK = 24 MHz / (dacClkDiv + 1).
226  // Max possible dacCLKDiv value = 63.
227  HWREGB(AUX_ANAIF_BASE + AUX_ANAIF_O_DACSMPLCFG0) = dacClkDiv;
228 
229  // Configure DAC sample clock:
230  //
231  // - Set 16 active sample clock periods during setup phase.
232  // - Set 0 inactive sample clock periods between each active sample clock
233  // period during hold phase.
234  // - Set high and low hold period to 4, resulting in a DAC sample clock of
235  // SBCLK/8.
236  //
237  // This makes DAC clock frequency = (24 MHz / (dacCLKDiv + 1)) / 8
238 
239  HWREG(AUX_ANAIF_BASE + AUX_ANAIF_O_DACSMPLCFG1) = (SAMPLE_CLK_HOLD_PERIOD)|
243 }
#define SAMPLE_CLK_HOLD_PERIOD
Definition: aux_dac.c:42
#define SAMPLE_CLK_HIGH_PERIOD
Definition: aux_dac.c:51
#define SAMPLE_CLK_LOW_PERIOD
Definition: aux_dac.c:48
#define SAMPLE_CLK_SETUP_COUNT
Definition: aux_dac.c:45

§ 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:
60 {
61  HWREGB(AUX_ADI4_BASE + ADI_4_AUX_O_MUX2) = refSource;
62 
63  if(refSource == AUXDAC_VREF_SEL_ADCREF)
64  {
65  // Enable the ADC reference module.
66  HWREGB(AUX_ADI4_BASE + ADI_4_AUX_O_ADCREF0) |= ADI_4_AUX_ADCREF0_REF_ON_IDLE | ADI_4_AUX_ADCREF0_EN;
67  }
68 }
#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().