Microchip® Advanced Software Framework

Quick Start Guide for Using DMA with ADC/DAC

The supported board list:

  • SAM D21 Xplained Pro
  • SAM D11 Xplained Pro
  • SAM L21 Xplained Pro
  • SAM DA1 Xplained Pro
  • SAM C21 Xplained Pro
  • SAM HA1G16A Xplained Pro

This quick start will convert an analog input signal from AIN4 and output the converted value to DAC on PA2. The data between ADC and DAC with be transferred through DMA instead of a CPU intervene.

The ADC will be configured with the following settings:

  • 1/2 VDDANA
  • Div 16 clock prescaler
  • 10-bit resolution
  • Window monitor disabled
  • No gain
  • Positive input on ADC AIN4
  • Averaging disabled
  • Oversampling disabled
  • Right adjust data
  • Single-ended mode
  • Free running enable
  • All events (input and generation) disabled
  • Sleep operation disabled
  • No reference compensation
  • No gain/offset correction
  • No added sampling time
  • Pin scan mode disabled

The DAC will be configured with the following settings:

  • Analog VCC as reference
  • Internal output disabled
  • Drive the DAC output to PA2
  • Right adjust data
  • The output buffer is disabled when the chip enters STANDBY sleep mode

The DMA will be configured with the following settings:

  • Move data from peripheral to peripheral
  • Using ADC result ready trigger
  • Using DMA priority level 0
  • Beat transfer will be triggered on each trigger
  • Loopback descriptor for DAC conversion

Setup

Prerequisites

There are no special setup requirements for this use-case.

Code

Add to the main application source file, outside of any functions:

Copy-paste the following setup code to your user application:

Add to user application initialization (typically the start of main()):

Workflow

Configure the ADC

  1. Create a module software instance structure for the ADC module to store the ADC driver state while it is in use.
    Note
    This should never go out of scope as long as the module is in use. In most cases, this should be global.
  2. Configure the ADC module.
    1. Create an ADC module configuration struct, which can be filled out to adjust the configuration of a physical ADC peripheral.
    2. Initialize the ADC configuration struct with the module's default values.
      Note
      This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
    3. Set extra configurations.
    4. Set ADC configurations.
    5. Enable the ADC module so that conversions can be made.

Configure the DAC

  1. Create a module software instance structure for the DAC module to store the DAC driver state while it is in use.
    Note
    This should never go out of scope as long as the module is in use. In most cases, this should be global.
  2. Configure the DAC module.
    1. Create a DAC module configuration struct, which can be filled out to adjust the configuration of a physical DAC peripheral.
    2. Initialize the DAC configuration struct with the module's default values.
      Note
      This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
    3. Set extra DAC configurations.
    4. Set DAC configurations to DAC instance.
    5. Enable the DAC module so that channels can be configured.
  3. Configure the DAC channel.
    1. Create a DAC channel configuration struct, which can be filled out to adjust the configuration of a physical DAC output channel.
    2. Initialize the DAC channel configuration struct with the module's default values.
      Note
      This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
    3. Configure the DAC channel with the desired channel settings.
    4. Enable the DAC channel so that it can output a voltage.

Configure the DMA

  1. Create a DMA resource configuration structure, which can be filled out to adjust the configuration of a single DMA transfer.
  2. Initialize the DMA resource configuration struct with the module's default values.
    Note
    This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  3. Set extra configurations for the DMA resource. ADC_DMAC_ID_RESRDY trigger causes a beat transfer in this example.
  4. Allocate a DMA resource with the configurations.
  5. Create a DMA transfer descriptor configuration structure, which can be filled out to adjust the configuration of a single DMA transfer.
  6. Initialize the DMA transfer descriptor configuration struct with the module's default values.
    Note
    This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  7. Set the specific parameters for a DMA transfer with transfer size, source address, and destination address.
  8. Create the DMA transfer descriptor.
  9. Add DMA descriptor to DMA resource.

Use Case

Code

Copy-paste the following code to your user application:

Workflow

  1. Start ADC conversion.
  2. Start the transfer job.
  3. Enter endless loop.