ADC HAL API.
For the sake of simplicity this API implements only small subset of what ADC is actually capable of. Feel free to visit Reference Manual for STM32WB series and implement any other modes by your self.
Couple things to keep in mind:
- ADC resolution is 12 bits, but effective number of bits is ~10 at the best and further depends on how you use and configure it.
- Analog domain is fed from SMPS which is quite noisy.
- Because of that we use internal on-chip voltage reference for ADC.
- It's capable of producing 2 voltages: 2.5V and 2.048V. This is the scale for your signal.
- Only single ended mode is available. But you can implement differential one by using low level controls directly.
- No DMA or interrupt API available at this point. But can be implemented with low level controls.
How to use:
- furi_hal_gpio_init - Configure your pins in
GpioModeAnalog
- furi_hal_adc_acquire - acquire ADC handle to work with
- furi_hal_adc_configure - configure ADC block
- furi_hal_adc_read - read value
- furi_hal_adc_release - release ADC handle
Configure with default parameters and enable ADC.
Parameters used:
- FuriHalAdcScale2048 - 2.048V VREF Scale. Your signal should be in 0 - 2.048V range.
- FuriHalAdcClockSync64 - Clocked from sysclk bus at 64MHz in synchronous mode. Fast, no delay on data bus access.
- FuriHalAdcOversample64 - Going to acquire and average 64 samples. For circuits with slowly or not changing signal. Total time per one read: (1/64)*(12.5+247.5)*64 = 260us. The best results you'll get if your signal will stay on the same level all this time.
- FuriHalAdcSamplingtime247_5 - Sampling(transfer from source to internal
sampling capacitor) time is 247.5 ADC clocks: (1/64)*247.5 = 3.8671875us. For relatively high impedance circuits.
Also keep your measurement circuit impedance under 10KOhm or oversampling results will be compromised. Verify your signal with oscilloscope(you may need fast oscilloscope: 200MHz bandwidth, 125MS/s), ensure that signal is not distorted by sampling.
Those parameters were optimized for 0 - 2.048 voltage measurement with ~0.1% precision. You can get more, but it will require some magic.
- Parameters
-