In all previous tutorial about NuttX we used some type of digital interface (I2C, SPI, etc), so today we will see how to use an analog interface to re

How to use analog input (ADC) on NuttX RTOS

submited by
Style Pass
2024-09-21 20:30:04

In all previous tutorial about NuttX we used some type of digital interface (I2C, SPI, etc), so today we will see how to use an analog interface to read some analog sensor or other analog device. In fact we live in an analog world and sometimes we need to read some analog voltage to make sense of some external analog signal. Today we will see how to use the ADC (Analog Digital Converter) from Raspberry Pi Pico RP2040 to read analog voltages.

First let me explain what is an ADC (Analog to Digital Converter). An ADC is basically a peripheral that "translate" analog voltage to a digital value (a number) representing that voltage. Let's suppose we have an ADC able to read 0V to 3.3V, so it could display a value from 0 to 1023 (assuming a 10-bit ADC) to represent this range of voltage. So, when you put 0V in the analog input pin your ADC will report the value 0 and when you put 3.3V it will return 1023. And any other value between 0V e 3.3V will return a proportional value between 0 and 1023. There are more details involved, but you got the idea.

Nowadays almost all microcontrollers have some ADC peripheral internally and it can read analog inputs with different bit resolutions (RP2040 has a 12-bit ADC resolution). The ADC's resolution is only a small part of its characteristic. There are many details related to ADC that will interfere to its "quality", such as its bandwidth, quantization error, nonlinearity error, signal-to-noise ratio (SNR), accuracy, etc. The wikipedia is a good starting point to understanding more about ADC intricacies.

Leave a Comment