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
- System Clock Management (Sysclock)
Setup steps
Example code
Add to application C-file:
Workflow
- Enable AFEC Module:
- Get the AFEC default configurations:
- Initialize the AFEC Module:
- Configure conversion trigger and free run mode:
- Enable Channel:
Usage steps
Example code
Add to, e.g., main loop in application C-file:
Workflow
- Start AFEC conversion on channel:
- Wait for the conversion over:
- Get the conversion result: