A Digital-to-Analog Converter (DAC) transforms digital signals into analog signals by mapping digital values to specific voltages. This process effectively creates continuous analog waveforms from discrete digital data. DACs play a vital role in electronic systems by enabling the generation of diverse waveforms.
Initialization sequence
Note
1. First start by calling the initialization function of the DAC spin.dac.initConsValue(DAC_NUM)
.
2. Second enter the integer value to send to the DAC spin.dac.setConstValue(DAC_NUM, DAC_CHAN, DAC_VALUE)
Conversion from numerical to analog value
The value we can send to the DAC is an integer between 0 and 4096, this value is then converted to voltage between 0 and 2.048V. For example :
Generate a 1.024V signal.Example
For a pratical example of the DAC see the example : - Signal generation
API Reference
Class DacHAL
Public Functions
Type | Name |
---|---|
void | currentModeInit (uint8_t dac_number, hrtim_tu_t tu_src) Update slope compensation settings on a DAC using voltage values. |
void | initConstValue (uint8_t dac_number) Initialize a DAC device in constant output mode. |
void | setConstValue (uint8_t dac_number, uint8_t channel, uint32_t const_value) Set a constant analog output value on a DAC channel. |
void | slopeCompensation (uint8_t dac_number, float32_t peak_voltage, float32_t low_voltage) Configure a DAC to operate in sawtooth waveform mode for current-mode control. |
Public Functions Documentation
function currentModeInit
Update slope compensation settings on a DAC using voltage values.
Converts the given voltage values into digital DAC values and sets the DAC's sawtooth waveform reset and step parameters accordingly.
Parameters:
dac_number
The DAC number (1 or 3).peak_voltage
The peak voltage value for the sawtooth ramp (reset level).low_voltage
The valley (starting) voltage of the ramp.
function initConstValue
Initialize a DAC device in constant output mode.
Configures the specified DAC (1, 2, or 3) to output a constant analog value.
This includes setting the value to 0, enabling external output, and starting the DAC.
Parameters:
dac_number
The DAC number (1, 2, or 3).
function setConstValue
Set a constant analog output value on a DAC channel.
Writes a raw 12-bit value to the selected DAC channel, provided the DAC is ready.
Parameters:
dac_number
The DAC number (1, 2, or 3).channel
The DAC output channel index (usually 1).const_value
The constant value to set (0–4095).
function slopeCompensation
Configure a DAC to operate in sawtooth waveform mode for current-mode control.
void DacHAL::slopeCompensation (
uint8_t dac_number,
float32_t peak_voltage,
float32_t low_voltage
)
Initializes the DAC to produce a decrementing sawtooth waveform.
The DAC is triggered by the selected HRTIM timer unit to synchronize waveform generation with the PWM cycle.
Reset and step triggers are selected based on the tu_src
.
Parameters:
dac_number
The DAC number (1 or 3).tu_src
The HRTIM timer unit (TIMB to TIMF) used for synchronization.
The documentation for this class was generated from the following file docs/core/zephyr/modules/owntech_spin_api/zephyr/src/DacHAL.h