DAC Asynchronous Driver

In the Digital-to-Analog Converter (DAC) asynchronous driver, the callback functions can be registered in the driver by the application and triggered when the DAC convention is done or an error happens.

Summary of the API's Functional Features

The API provides functions to:
  • Initialize and deinitialize the driver and associated hardware

  • Hookup callback handlers on DAC conversion done or error

  • Enable and disable DAC channel

  • Write buffers with multiple digital data to DAC

Summary of Configuration Options

Below is a list of the main DAC parameters that can be configured in START. Many of these parameters are used by the dac_async_init function when initializing the driver and underlying hardware.
  • Select which DAC output signals are to be enabled

  • Which clock source and prescaler the DAC uses

  • Reference voltage selection

  • Various aspects of Event control, such as "Start Conversion on Event Input"

  • Run in Standby or Debug mode

Driver Implementation Description

The driver can convert a serial digital value. The pre-defined data should be put in a data array. Application can invoke dac_async_write to start the conversion, and get a notice by the registered callback function.

Implementation of dac_async_write is based on the underlying DAC peripheral. Normally, there is a FIFO buffer for writing conversion data. Take SAM D21 for example, the Data Buffer register (DATABUF) and the Data register (DATA) are linked together to form a two-stage FIFO. The DAC uses the Start Conversion event to load data from DATABUF into DATA and start a new conversion. In the SAM D21 case, dac_async_write will write data to the DATABUF register, so the Start Conversion event should be configured properly to use this asynchronous driver.

Example of Usage

The following shows a simple example of using the DAC. The DAC must have been initialized by dac_async_init. This initialization will configure the operation of the DAC, such as reference voltage and Start Conversion Event Input, etc.

The example registers a callback function for conversion done and enables channel 0 of DAC0, and finally starts a D/A conversion to output a waveform.

Tip:
Normally it is also necessary to configure the Event system to trigger the DAC conversion. Take SAM D21 for example, the RTC period 0 event can be used to trigger loading data from DATABUF into DATA and start a new conversion in the DAC peripheral. These drivers are needed for this example, with some configurations in START:
  • Calendar driver (RTC)
    • Select 32.768kHz as RTC clock input

    • Enable "Periodic Interval 0 Event Output"

  • Event driver
    • Enable one event channel for DAC and configure it

    • Select "RTC period 0" as Event generator and choose Event channel for DAC

    • Select Event path "Asynchronous path"

  • DAC
    • Enable "Start Conversion on Event Input"

          static uint16_t example_DAC_0[10] = {
              0, 100, 200, 300, 400,
              500, 600, 700, 800, 900
          };
          static void tx_cb_DAC_0(struct dac_async_descriptor *const descr, const uint8_t ch)
          {
              dac_async_write(descr, 0, example_DAC_0, 10);
          }
          /**
           * Example of using DAC_0 to generate waveform.
           */
          void DAC_0_example(void)
          {
              dac_async_enable_channel(&DAC_0, 0);
              dac_async_register_callback(&DAC_0, DAC_ASYNC_CONVERSION_DONE_CB, tx_cb_DAC_0);
              dac_async_write(&DAC_0, 0, example_DAC_0, 10);
          }
        

Dependencies

  • The DAC peripheral and its related I/O lines and clocks

  • The NVIC must be configured so that DAC interrupt requests are periodically serviced

  • The Event Driver

  • The driver (e.g RTC) of Event generator, which is used to trigger DAC convention