In this use case, the ADC will be configured with the following settings:
- 1V from internal bandgap reference
- Div 4 clock prescaler
- 12-bit resolution
- Window monitor disabled
- No gain
- Positive input on ADC PIN x (depend on default configuration)
- Negative input to GND (single ended)
- Averaging disabled
- Oversampling disabled
- Right adjust data
- Single-ended mode
- Free running disabled
- All events (input and generation) disabled
- Sleep operation disabled
- No reference compensation
- No gain/offset correction
- No added sampling time
- Pin scan mode disabled
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_adc(void)
{
#if (SAMC21)
adc_init(&adc_instance, ADC1, &config_adc);
#else
adc_init(&adc_instance, ADC, &config_adc);
#endif
}
Add to user application initialization (typically the start of main()
):
Workflow
- Create a module software instance structure for the ADC module to store the ADC driver state while 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.
- Configure the ADC module.
- Create an ADC module configuration struct, which can be filled out to adjust the configuration of a physical ADC peripheral.
- 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.
- Set ADC configurations.
#if (SAMC21)
adc_init(&adc_instance, ADC1, &config_adc);
#else
adc_init(&adc_instance, ADC, &config_adc);
#endif
- Enable the ADC module so that conversions can be made.
Use Case
Code
Copy-paste the following code to your user application:
uint16_t result;
do {
while (1) {
}
Workflow
- Start conversion.
- Wait until conversion is done and read result.
- Enter an infinite loop once the conversion is complete.