Simple ADC - Analog to Digital Converter Example
Overview
This NetBurner application demonstrates basic analog-to-digital conversion on MCF5441X-based platforms. The application continuously reads all 8 ADC channels and displays both raw register values and converted voltage readings on the serial console.
Supported Platforms
- MOD5441X - All 8 ADC channels available
- NANO54415 - All 8 ADC channels available
Note: Refer to your specific platform's datasheet to determine which ADC channels are routed to accessible connector pins.
Hardware Requirements
- NetBurner MOD5441X or NANO54415 module
- Analog voltage sources (0-3.3V) connected to ADC input pins
- Serial console connection for output display
ADC Specifications
- Resolution: 15-bit (32,768 counts)
- Input Range: 0V to 3.3V
- Channels: 8 single-ended inputs (AN0-AN7)
- Conversion Type: Successive approximation
- Reference Voltage: 3.3V
Application Functionality
Main Features
- Single-Ended ADC Configuration: Initializes all 8 channels for single-ended input
- Continuous Conversion: Performs ADC conversions every second
- Dual Output Format: Displays both raw hex values and calculated voltages
- Synchronous Operation: Waits for conversion completion before reading results
Program Flow
- Initialization
- Initialize network stack with
init()
- Enable system diagnostics
- Initialize ADC hardware with
InitSingleEndAD()
- Main Loop (repeats every second)
- Start ADC conversion with
StartAD()
- Wait for conversion completion using
ADDone()
- Read and display all 8 channel results
- Convert raw values to voltage
- Wait 1 second before next cycle
Output Format
The application displays readings in two formats for all 8 channels:
Register values: 0000,0000,4A2B,0000,0000,0000,0000,0000,
Voltage: 0.0000,0.0000,1.5234,0.0000,0.0000,0.0000,0.0000,0.0000,
- Register values: Raw 16-bit hexadecimal ADC readings
- Voltage: Calculated floating-point voltage values (0.0000 to 3.3000V)
Key Components
Files Structure
SimpleADC/
|-- src/
| |-- main.cpp # Main application logic
| |-- SimpleAD.cpp # ADC driver implementation
| +-- SimpleAD.h # ADC function declarations
|-- makefile # Build configuration
+-- README.md # This documentation
Core Functions
- **
InitSingleEndAD()**: Configures ADC hardware for single-ended operation
- **
StartAD()**: Initiates conversion on all enabled channels
- **
ADDone()**: Returns true when current conversion cycle is complete
- **
GetADResult(int ch)**: Returns raw 16-bit result for specified channel (0-7)
Voltage Conversion Formula
voltage = (raw_value * 3.3) / 32768.0
Where:
raw_value: 16-bit ADC result (0-32767)
3.3: Reference voltage
32768.0: Full-scale count (2^15)
Hardware Connections
ADC Channel Mapping
Consult your platform's datasheet for specific pin assignments:
- Channel 0 (AN0): ADC input 0
- Channel 1 (AN1): ADC input 1
- Channel 2 (AN2): ADC input 2
- Channel 3 (AN3): ADC input 3
- Channel 4 (AN4): ADC input 4
- Channel 5 (AN5): ADC input 5
- Channel 6 (AN6): ADC input 6
- Channel 7 (AN7): ADC input 7
Input Requirements
- Voltage Range: 0V to 3.3V (do not exceed 3.3V)
- Input Impedance: High impedance (suitable for most sensors)
- Signal Conditioning: May require buffering for low-impedance sources
Usage Examples
Testing with Known Voltages
- Ground Reference: Connect ADC input to GND (should read ~0.0000V)
- 3.3V Reference: Connect ADC input to 3.3V supply (should read ~3.3000V)
- Variable Voltage: Use potentiometer or voltage divider for variable input
- Sensor Testing: Connect analog sensors (temperature, pressure, etc.)
Monitoring Multiple Channels
Connect different voltage sources to multiple channels to observe simultaneous readings:
Register values: 0000,7FFF,4000,2000,1000,0800,0400,0200,
Voltage: 0.0000,3.3000,1.6500,0.8250,0.4125,0.2063,0.1031,0.0516,
Troubleshooting
Common Issues
- All readings show 0000
- Check that ADC inputs are properly connected
- Verify input voltages are within 0-3.3V range
- Ensure proper ground connections
- Readings are unstable or noisy
- Add input filtering (RC filter recommended)
- Check for proper ground plane connections
- Verify signal source has adequate drive capability
- Incorrect voltage calculations
- Verify reference voltage is exactly 3.3V
- Check ADC resolution settings in code
- Confirm conversion formula matches hardware configuration
Debug Tips
- Use multimeter to verify actual input voltages
- Connect known reference voltages for calibration
- Monitor ADC register values for consistency
- Check platform-specific pin assignments in datasheet
Technical Notes
ADC Characteristics
- Conversion Time: Platform-dependent (typically microseconds)
- Sample Rate: Limited by software delay (1 Hz in this example)
- Accuracy: Dependent on reference voltage stability
- Temperature Drift: Consult datasheet for specifications
Performance Considerations
- Current implementation uses polling for conversion completion
- For high-speed applications, consider interrupt-driven conversions
- Multiple channel readings are sequential, not simultaneous
- Adding input filtering may improve measurement stability
Application Extensions
This basic example can be extended for:
Sensor Integration
- Temperature sensors (thermistors, LM35)
- Pressure transducers
- Light sensors (photodiodes, photoresistors)
- Position sensors (potentiometers)
Advanced Features
- Averaging multiple readings for noise reduction
- Threshold monitoring with alarms
- Data logging to file system
- Web-based real-time monitoring
- Calibration and scaling for specific sensors
Code Modifications
float avgVoltage = 0;
for(int sample = 0; sample < 10; sample++) {
StartAD();
while(!ADDone()) asm("nop");
avgVoltage += ((double)GetADResult(2)) * 3.3 / 32768.0;
}
avgVoltage /= 10;
printf("Channel 2 averaged voltage: %6.4f\r\n", avgVoltage);
#define TICKS_PER_SECOND
System clock ticks per second.
Definition constants.h:49
Related Examples
- PeriodicADC: Interrupt-driven ADC conversions
- DAC Examples: Digital-to-analog output generation
- PWM Examples: Pulse width modulation for analog control