ADC Synchronous Driver

The Analog to Digital Converter (ADC) synchronous driver will block (i.e. not return) there until the requested data has been read. Functionality is therefore synchronous to the calling thread, i.e. the thread will wait for the result to be ready. The adc_sync_read_channel function will perform a conversion of the voltage on the specified channel and return the result when it is ready.

Summary of the API's Functional Features

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

  • Select single shot or free running conversion modes

  • Configure major ADC properties such as resolution and reference source

  • Read back conversion results

Summary of Configuration Options

Below is a list of the main ADC parameters that can be configured in START. Many of these parameters are used by the adc_sync_init function when initializing the driver and underlying hardware. Most of the initial values can be overridden and changed runtime by calling the appropriate API functions, such as adc_sync_set_resolution.
  • Selecting which ADC input channels to enable for positive and negative input

  • Which clock source and prescaler the ADC uses

  • Various aspects of Event control

  • Single shot or free running conversion modes

  • Sampling properties such as resolution, window mode, and reference source

  • Run in Standby or Debug mode

Driver Implementation Description

The functions in the ADC synchronous driver will block (i.e. not return) until the operation is done.

Example of Usage

The following shows a simple example of using the ADC. The ADC must have been initialized by adc_sync_init. This initialization will configure the operation of the ADC, such as single-shot or continuous mode, etc.

The example enables channel 0 of ADC0, and finally starts a conversion on this channel.

          /**
           * Example of using ADC_0 to generate waveform.
           */
          void ADC_0_example(void)
          {
              uint8_t buffer[2];
              adc_sync_enable_channel(&ADC_0, 0);
              while (1) {
                  adc_sync_read_channel(&ADC_0, 0, buffer, 2);
              }
          }
        

Dependencies

  • ADC peripheral and its related I/O lines and clocks