1. How does it work?
1.1 Summary
While most microcontrollers are equipped with built-in ADCs, these are generally limited to 10-bit resolution and can only accept a maximum input voltage equal to their supply voltage (VCC), which is typically 3.3V or 5V. However, many sensors output signals in the 0-10V range, necessitating additional circuitry to scale these signals down for accurate reading by the microcontroller’s ADC. This module simplifies the process by providing two channels of 12-bit ADC capable of directly handling 0-10V inputs. It utilizes a precision op-amp for signal conditioning, coupled with a 12-bit SPI ADC for high-resolution conversions. Designed to operate on either 3.3V or 5V VCC, the module ensures compatibility with a wide range of microcontrollers, eliminating the need for complex external circuitry to scale sensor outputs.
1.2 Analog to Digital Converter
This module incorporates an MCP3202, a 12-bit Analog to Digital Converter (ADC), featuring dual-channel inputs capable of reading signals in the 0-5V range. To ensure consistent performance regardless of whether the supply voltage (VIO) is 5V or 3.3V, the module generates its required 5V through an onboard voltage regulator. This design choice allows the ADC to operate correctly and provide accurate conversions under varying VIO conditions.
1.3 Scaling Inputs
To scale inputs from a 0-10V range to fit the ADC’s 0-5V range, the module initially employs a precision op-amp configured as a buffer (or level follower) to convert the high-impedance signal to low impedance. This step ensures that the signal can be handled more effectively without significant loading on the source. Following this impedance matching, the signal undergoes attenuation through a simple voltage divider, effectively halving its voltage to align with the ADC’s input range.
1.4 Level Shifters
Given that the ADC operates at 5V, the module must ensure that the SPI communication signals are compatible with the VCC of the connected microcontroller, which may be either 3.3V or 5V. To achieve this, the module employs MOSFETs as level shifters. These MOSFETs adjust the SPI signal levels to match the VCC provided, ensuring reliable data exchange between the ADC and the microcontroller regardless of the VCC level.
2. Specification
2.2. Pinout
2.3. Electrical Characteristics
Coming Soon...
2.5. BOM
Coming Soon...
3. Code
Overview
This example demonstrates how to use the MODSPI_AnalogInputs class to control a set of analog inputs channels. The code initializes a MODSPI_AnalogInputs instance, reading the analog input as a value and a voltage.
Prerequisites
Ensure you have the MODSPI library installed in your Arduino IDE. If not, you can download and install it from the Library Manager or GITHUB.
Available Functions
Void begin (int chipSelect)
Starts the Initializes the analog input module with the specified chip select pin. If you're using a MODSPI controller you can also put in "BAY1" and select your desired bay.
int readValue (int channel)
Returns the specified input channel (from 0 - 1) as a value (between 0 - 4095)
float readVoltage (int channel)
Returns the specified input channel (from 0 - 1) as a voltage (between 0 - 10.0V)
Example Code Breakdown
Include the MODSPI Library
First, we need to include the MODSPI library to access the necessary functions and classes.
#include <MODSPI.h>
Create an Instance of MODSPI_AnalogInputs
Next you create an instance of the MODSPI_AnalogInputs class and name it whatever you want, for example analogInputs1.
If you have multiple analog Input modules, you will need to create additional instances.
MODSPI_AnalogInputs analogInputs1;
Setup Function
The setup function is called once when the Arduino starts. Here, we initialize the instance and perform some initial actions.
void setup() {
// Initialize the analogInputs1 instance with D5 as the chip select pin.
analogInputs1.begin(D5); // D5 is the chip select pin.
}
Main Loop
In the main loop function we cycle through the two analog input channels, printing both the ADC value and the voltage.
void loop() {
// Loop through analog inputs 0 to 1 and read their values and voltages.
for (int a = 0; a <= 1; a++) {
// Print the ADC value to the serial monitor.
int readADCValue = analogInputs1.readValue(a); // Read the raw ADC value of input 'a'.
Serial.print("Analog Input ");
Serial.print(a);
Serial.print(": ADC Value = ");
Serial.println(readADCValue);
// Print the ADC voltage to the serial monitor.
float readADCVoltage = analogInputs1.readVoltage(a); // Read the voltage of input 'a'.
Serial.print("Analog Input ");
Serial.print(a);
Serial.print(", Voltage = ");
Serial.println(readADCVoltage);
}
delay(500); // Wait for 500 milliseconds before repeating the loop.
}