The functions in Digital-to-Analog Converter (DAC) synchronous driver will block (i.e. not return) until the operation is done.
The dac_sync_write function will perform a conversion of digital value to analog voltage and return the result when it is ready.
Initialize and deinitialize the driver and associated hardware
Enable and disable the DAC channel
Write buffers with multiple digital data to DAC
Select which DAC output signals to be enabled
Which clock source and prescaler the DAC uses
Reference voltage selection
Run in Standby or Debug mode
In DAC synchronous driver, new digital values will be written directly to the DAC hardware and returned when all digital data has been converted.
The following shows a simple example of using the DAC. The DAC must have been initialized by dac_sync_init. This initialization will configure the operation of the DAC, such as reference voltage, etc.
The example enables channel 0 of DAC0, and finally starts a D/A conversion to output a waveform.
/** * Example of using DAC_0 to generate waveform. */ void DAC_0_example(void) { uint16_t i = 0; dac_sync_enable_channel(&DAC_0, 0); for(;;) { dac_sync_write(&DAC_0, 0, &i, 1); i = (i+1) % 1024; } }
The DAC peripheral and its related I/O lines and clocks