ADC configuration

Hello, I’m using the xDot plattform and I would like to configure the sampling frequency of the ADC but I can’t find any library to do that. It reads values only setting the analog pin but there are not functions to configure the parameters of the ADC. I’d appreciate any help.

Regards,

Luis

Unfortunately, the ADC API does not currently support continuous sampling rates. You can see the API documentation here:
https://os.mbed.com/docs/mbed-os/v5.14/apis/analogin.html

There are a couple options, depending on your required sampling rate:
1.) You can use a Ticker object to periodically trigger a sample using the existing ADC API. This will be sufficient only for low sampling rates and isn’t ideal because it will take time away from the processor.

2.) You will have to set up continuous ADC sampling in the hardware yourself. Since the xDot is based on an STM32L1-series processor, you can do this by directly accessing the hardware through the STM32-L1 hardware abstraction layer (HAL) API(look at *_hal_adc.h and *_hal_adc_ex.h). Just be careful if you’re also using Mbed’s ADC API to configure other ADC inputs. Depending on the implementation, the Mbed ADC API may change your ADC configuration.

Thank you for your help. I’ll try both options.