Microchip® Advanced Software Framework

Quick Start Guide for SDADC - Basic

In this use case, the SDADC will be configured with the following settings:

  • GCLK generator 0 (GCLK main) clock source
  • Internal bandgap reference 1V
  • Div 2 clock prescaler
  • Over Sampling Ratio is 64
  • Skip 2 samples
  • MUX input on SDADC AIN1
  • All events (input and generation) disabled
  • Free running disabled
  • Run in standby disabled
  • On command disabled
  • Disable all positive input in sequence
  • Window monitor disabled
  • No gain/offset/shift correction

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:

void configure_sdadc(void)
{
struct sdadc_config config_sdadc;
sdadc_get_config_defaults(&config_sdadc);
sdadc_init(&sdadc_instance, SDADC, &config_sdadc);
}

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

Workflow

  1. Create a module software instance structure for the SDADC module to store the SDADC 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 SDADC module.
    • Create a SDADC module configuration struct, which can be filled out to adjust the configuration of a physical SDADC peripheral.
      struct sdadc_config config_sdadc;
    • Initialize the SDADC configuration struct with the module's default values.
      sdadc_get_config_defaults(&config_sdadc);
      Note
      This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
    • Set SDADC configurations.
      sdadc_init(&sdadc_instance, SDADC, &config_sdadc);
    • Enable the SDADC module so that conversions can be made.

Use Case

Code

Copy-paste the following code to your user application:

int32_t result;
do {
/* Wait for conversion to be done and read out result */
} while (sdadc_read(&sdadc_instance, &result) == STATUS_BUSY);
while (1) {
/* Infinite loop */
}

Workflow

  1. Start conversion.
  2. Wait until conversion is done and read result.
    int32_t result;
    do {
    /* Wait for conversion to be done and read out result */
    } while (sdadc_read(&sdadc_instance, &result) == STATUS_BUSY);
  3. Enter an infinite loop once the conversion is complete.
    while (1) {
    /* Infinite loop */
    }