Location: examples/PlatformSpecific/SOMRT1061/ADC_Simple
Supported Platforms: SOMRT1061
Simple A/D Example for SOMRT1061
This example demonstrates analog-to-digital conversion on the NetBurner SOMRT1061 platform using two different approaches: the simplified PinIO analog functions and direct register-level ADC control.
Overview
The application reads 8 analog input channels and displays both raw hexadecimal sample values and calculated decimal voltages. Output is sent to the serial console at approximately 5 Hz.
File Structure
SimpleAD/
|-- main.cpp - Application entry point and main loop
|-- SimpleAD.cpp - Low-level ADC driver implementation
|-- SimpleAD.h - ADC driver function declarations
Hardware Configuration
Analog Input Pins
| Pin Index | ADC Module | ADC Channel | Physical Pin |
| Pins[40] | ADC1 | Channel 5 | AD0 |
| Pins[41] | ADC1 | Channel 6 | AD1 |
| Pins[42] | ADC1 | Channel 7 | AD2 |
| Pins[43] | ADC1 | Channel 8 | AD3 |
| Pins[44] | ADC2 | Channel 9 | AD4 |
| Pins[45] | ADC2 | Channel 10 | AD5 |
| Pins[46] | ADC2 | Channel 11 | AD6 |
| Pins[47] | ADC2 | Channel 12 | AD7 |
ADC Specifications
- Resolution: 12-bit (0-4095)
- Reference Voltage: 3.3V (VREFH/VREFL)
- Sample Rate: ~5 samples per second (configurable)
Two Operating Modes
Mode 1: PinIO Analog Functions (Default)
Enabled when USE_PIN_IO_ANALOG is defined (default).
#define USE_PIN_IO_ANALOG 1
This mode uses the simplified PinIO class methods:
analogPins[i].analogEnableSampleWait(true);
PinIO::analogSetAveraging(PinIO::ANALOG_AVG_4);
Mode 2: Direct Register Access
Enabled by commenting out or setting USE_PIN_IO_ANALOG to 0.
This mode uses the functions in SimpleAD.cpp/h:
SimpleAD Driver Details
Initialization (InitSingleEndAD)
- Enables ADC and XBAR peripheral clocks
- Resets and configures ADC_ETC (External Trigger Controller)
- Configures ADC1 and ADC2 with identical settings:
- 12-bit resolution
- Low power mode (higher input impedance)
- Software trigger initially (for calibration)
- Async clock always enabled
- Runs calibration sequence on both ADC modules
- Switches to hardware trigger mode
- Configures trigger chains for ADC_ETC
ADC Configuration Settings
CFG Register:
- OVWREN = 1 : Overwrite previous data
- REFSEL = 0 : VREFH/VREFL reference
- ADHSC = 0 : Normal speed conversion
- ADSTS = 1 : 4 ADC clock sample period
- ADLPC = 1 : Low power mode enabled
- ADIV = 3 : Clock divider
- MODE = 2 : 12-bit resolution
- ADICLK = 0 : Peripheral clock source
GC Register:
- ADCO = 0 : Single conversion (no continuous)
- AVGE = 0 : Hardware averaging disabled
- DMAEN = 0 : DMA disabled
- ADACKEN = 1 :
Async clock enabled
@ Async
Asynchronous mode. Timing based on fixed delays. No clock synchronization required....
Channel Configuration (ADConfigCh)
- Configures GPIO pin for analog input (disables pull-up/down)
- Sets up ADC_ETC trigger chain entry
- Supports up to 8 channels per ADC module
- Uses back-to-back conversion mode for efficiency
Conversion Flow
StartAD()
|
V
Clear Done/Error flags
|
V
Set SW_TRIG bit in TRIG[0].CTRL
|
V
ADC_ETC triggers chained conversions
|
V
ADDone() returns true when complete
|
V
GetADResult() reads from TRIG[n].RESULT registers
Console Output Format
The application outputs two lines per sample cycle:
0xNNN, 0xNNN, 0xNNN, 0xNNN, 0xNNN, 0xNNN, 0xNNN, 0xNNN,
X.XXXX, X.XXXX, X.XXXX, X.XXXX, X.XXXX, X.XXXX, X.XXXX, X.XXXX,
- Line 1: Raw hexadecimal ADC values (0x000 to 0xFFF)
- Line 2: Calculated voltage values (0.0000V to 3.3000V)
Notes
- The PinIO analog methods use only ADC1, leaving ADC2 available for other purposes such as DMA-based sampling or dedicated sensor input.
- When using direct register access mode, both ADC1 and ADC2 are used with synchronized triggering via ADC_ETC.
- Available ADC channels are limited by DRAM usage on the SOMRT1061. The
chAvail bitmask in SimpleAD.cpp defines which channels are available: channels 5-12 on both ADC modules.
- For higher effective resolution, enable hardware averaging using
PinIO::analogSetAveraging() with values:
- ANALOG_AVG_4
- ANALOG_AVG_8
- ANALOG_AVG_16
- ANALOG_AVG_32
- The default continuous background conversion provides the fastest response time but returns slightly stale samples. Enable sample wait mode for guaranteed fresh samples at the cost of longer read times.