DAC RTOS Driver

The convert functions of the Digital-to-Analog Converter (DAC) RTOS driver are optimized for RTOS support. That is, the convert functions will not work without RTOS, the convert functions should only be called in an RTOS task or thread.

Summary of the API's Functional Features

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

  • Enable and disable the 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_os_init function when initializing the driver and underlying hardware.
  • Select which DAC output signals 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. The Application can invoke dac_os_write to start the conversion (asyn mode). The task/thread will be blocked until the conversion is done.

During data conversion, the DAC convert process is not protected, so that a more flexible way can be chosen in the application.

Example of Usage

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

The example creates one convert task for channel 0 of DAC0 and finally starts the RTOS task scheduler.

Tip:

Normally it is also necessary to configure the Event system to trigger the DAC conversion. See the example in DAC Asynchronous Driver for reference.

          static uint16_t example_DAC_0[10] = {
              0, 100, 200, 300, 400,
              500, 600, 700, 800, 900
          };
          /**
           * Example task of using DAC_0 to generate waveform.
           */
          void DAC_0_example_task(void *p)
          {
              (void)p;
              dac_os_enable_channel(&DAC_0, 0);
              for(;;) {
                  if (dac_os_write(&DAC_0, 0, example_DAC_0, 10) == 10) {
                      /* convert OK */;
                  } else {
                      /* error. */;
                  }
              }
          }
          #define TASK_DAC_CONVERT_STACK_SIZE        ( 256/sizeof( portSTACK_TYPE ))
          #define TASK_DAC_CONVERT_PRIORITY          ( tskIDLE_PRIORITY + 1 )
          static TaskHandle_t xDacConvertTask;
          int main(void)
          {
              /* Initializes MCU, drivers and middleware */
              atmel_start_init();
              /* Create DAC convert task */
              if (xTaskCreate(DAC_0_example_task, "DAC convert", TASK_DAC_CONVERT_STACK_SIZE,
                              NULL,
                              TASK_DAC_CONVERT_PRIORITY, &xDacConvertTask) != pdPASS) {
                  while (1) {
                      ;
                  }
              }
              /*  Start RTOS scheduler */
              vTaskStartScheduler();
              /* Replace with your application code */
              while (1) {
              }
          }
        

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

  • RTOS