Microchip® Advanced Software Framework

Quickstart guide for SAM AFEC driver

This is the quickstart guide for the SAM AFEC driver with step-by-step instructions on how to configure and use the driver in a selection of use cases.

The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.

Basic use case

In this basic use case, the AFEC module and single channel are configured for:

  • 12 -bit resolution
  • AFEC clock frequency is 6MHz
  • Start Up Time is 64 periods AFEC clock
  • Analog Settling Time is 3 periods of AFEC clock
  • Tracking Time is 3 periods of AFEC clock
  • Transfer Period is 5 periods AFEC clock
  • Allows different analog settings for each channel
  • The controller converts channels in a simple numeric order
  • Appends the channel number to the conversion result in AFE_LDCR register
  • Only a Single Trigger is required to get an averaged value
  • AFE Bias Current Control value is 1
  • Software triggering of conversions
  • Single channel measurement
  • AFEC_CHANNEL_5 of AFEC0 as input

Prerequisites

  1. System Clock Management (Sysclock)

Setup steps

Example code

Add to application C-file:

afec_enable(AFEC0);
afec_init(AFEC0, &afec_cfg);
afec_channel_enable(AFEC0, AFEC_CHANNEL_5);

Workflow

  1. Enable AFEC Module:
  2. Get the AFEC default configurations:
  3. Initialize the AFEC Module:
  4. Configure conversion trigger and free run mode:
  5. Enable Channel:

Usage steps

Example code

Add to, e.g., main loop in application C-file:

while (afec_get_interrupt_status(AFEC0) & (1 << AFEC_CHANNEL_5));
uint32_t result = afec_channel_get_value(AFEC0, AFEC_CHANNEL_5);

Workflow

  1. Start AFEC conversion on channel:
  2. Wait for the conversion over:
  3. Get the conversion result: