NetBurner 3.5.6
PDF Version
Periodic ADC

Periodic ADC - DMA-Driven High-Speed Sampling

Overview

This NetBurner application demonstrates advanced analog-to-digital conversion using DMA-driven periodic sampling on MCF5441X-based platforms. The application continuously samples an ADC channel at 8 kHz, buffers the data using DMA transfers, and saves the captured audio data as WAV files to external flash storage.

Supported Platforms

  • MOD5441X - Full DMA and external flash support
  • NANO54415 - Full DMA and external flash support

Hardware Requirements

  • NetBurner MOD5441X or NANO54415 module
  • External SD flash card (mounted on development board)
  • Analog signal source connected to ADC channel 0
  • Serial console connection for status monitoring

Key Features

Advanced ADC Capabilities

  • DMA-Driven Sampling: Hardware-triggered transfers without CPU intervention
  • High-Speed Acquisition: 8 kHz sampling rate with precise timing
  • Circular Buffering: Continuous data capture with ping-pong buffers
  • Interrupt-Driven: Half-buffer and full-buffer interrupt handling
  • Loop Mode ADC: Continuous conversion without restart overhead

Data Processing

  • Real-Time Buffering: 2048-byte circular sample buffer in fast SRAM
  • Large Data Buffer: 8MB data buffer for extended recording
  • WAV File Generation: Direct conversion to standard audio format
  • File System Integration: EFFS FAT file system support
  • Automatic File Naming: Sequential file numbering (adc8k0.wav, adc8k1.wav, etc.)

Technical Specifications

Sampling Configuration

  • Sample Rate: 8 kHz (8000 samples per second)
  • ADC Channel: Channel 0 (configurable)
  • Buffer Size: 2048 bytes circular buffer
  • Data Buffer: 8MB total storage
  • DMA Timer: Timer 0 for precise triggering
  • Recording Length: ~128 buffer cycles per file

File Output

  • Format: WAV audio files
  • Channels: 1 (mono)
  • Sample Rate: 8 kHz
  • Bit Depth: 16-bit (from ADC resolution)
  • File Size: ~131 KB per recording cycle
  • Storage: External SD flash card

Application Architecture

Program Flow

  1. System Initialization
    • Initialize network stack and diagnostics
    • Initialize DMA semaphore for synchronization
    • Mount external flash file system
    • Configure ADC for continuous loop mode
    • Setup DMA timer for 8 kHz triggering
  2. ADC and DMA Setup
    • Configure single-ended ADC on channel 0
    • Start ADC in continuous loop mode
    • Initialize DMA channel for ADC-to-memory transfers
    • Set DMA timer frequency to 8 kHz
  3. Data Acquisition Loop
    • Start DMA transfers to circular buffer
    • Wait for half-buffer fill interrupts
    • Copy data to large storage buffer
    • Continue until major sample count reached
    • Stop DMA and write WAV file
  4. File Management
    • Create sequential WAV files
    • Write captured data with proper WAV headers
    • Close files and increment counter
    • Repeat indefinitely

Memory Architecture

+----------------+ DMA +------------------+ Copy +----------------+
| ADC Result | ---------> | Circular Buffer | ---------> | Data Buffer |
| Register | Transfer | (2KB SRAM) | on IRQ | (8MB RAM) |
+----------------+ +------------------+ +----------------+
^ |
| |
+----------+ +-------------+
| DMA IRQ | | WAV File |
|Half/Full | | on Flash |
+----------+ +-------------+

Key Components

Files Structure

PeriodicADC/
|-- src/
| |-- main.cpp # Main application logic
| |-- PeriodicAD.cpp # ADC configuration functions
| |-- PeriodicAD.h # ADC function declarations
| |-- PeriodicAD_DMA.cpp # DMA setup and control
| |-- PeriodicAD_DMA.h # DMA function declarations
| |-- wavWriter.cpp # WAV file format handling
| |-- wavWriter.h # WAV writer declarations
| |-- FileSystemUtils.cpp # Flash file system utilities
+-- FileSystemUtils.h # File system declarations

Core Functions

ADC Control:**

  • InitSingleEndAD(): Configure ADC hardware for single-ended operation
  • StartADLoop(): Start ADC in continuous conversion mode
  • initADC_DMA(): Setup DMA channel for ADC transfers
  • setSampleFreq(): Configure DMA timer for desired sample rate

    DMA Management:**

  • startADC_DMA(): Begin DMA transfers with callback
  • stopADC_DMA(): Halt DMA operations
  • dmaTriggerFunc(): Interrupt callback for buffer management

    File Operations:**

  • openNewWav(): Create new WAV file with proper headers
  • setUpFlash(): Initialize external flash file system

Callback Function

void dmaTriggerFunc(void *start, void *end) {
frontFilled = !frontFilled; // Toggle buffer half indicator
AdcDmaSem.Post(); // Signal main loop
}

Hardware Connections

ADC Input

  • Channel 0: Primary analog input (see platform datasheet for pin location)
  • Input Range: 0V to 3.3V
  • Input Impedance: High (suitable for audio signals)
  • Signal Conditioning: May require amplification for low-level signals

External Flash

  • SD Card: Required for WAV file storage
  • File System: FAT format recommended
  • Capacity: Minimum 1GB for extended recording

Building and Deployment

Required Libraries

This example requires the FatFile library for file system operations:

For NBEclipse:**

  1. Right-click project > Properties
  2. C/C++ Build > Settings
  3. GNU C/C++ Linker > Libraries
  4. Add "FatFile" to Libraries list

    For Command Line:**

    XTRALIB += -lFatFile

Additional Files Required

Copy these files from \nburn\examples\_common\EFFS\FAT:

  • cardtype.h
  • FileSystemUtils.cpp
  • FileSystemUtils.h

Build Commands

# Build for specific platform
make PLATFORM=MOD5441X
# or
make PLATFORM=NANO54415
# Load to device
make load DEVIP=<device_ip_address>

Usage and Operation

Startup Sequence

  1. Connect analog signal to ADC channel 0
  2. Insert formatted SD card
  3. Load and run application
  4. Monitor serial output for status

Expected Output

Initializing External Flash...
External Flash opened.
Starting log: adc8k0.wav
Wrote 131072 bytes to disk, in file adc8k0.wav.
Starting log: adc8k1.wav
Wrote 131072 bytes to disk, in file adc8k1.wav.

File Analysis

Generated WAV files can be:

  • Played in standard audio software
  • Analyzed in audio/signal processing tools
  • Converted to other formats as needed
  • Opened in oscilloscope software for waveform analysis

Performance Characteristics

Timing Precision

  • DMA Timer: Hardware-based precise timing
  • Jitter: Minimal due to hardware triggering
  • CPU Loading: Low due to DMA operation
  • Real-Time: Deterministic sample intervals

Memory Usage

  • Fast SRAM: 2KB circular buffer for real-time operation
  • Main RAM: 8MB data buffer for file preparation
  • Stack Usage: WAV writer requires significant stack space
  • File System: Standard EFFS overhead

Throughput

  • Sample Rate: 8000 samples/second
  • Data Rate: 16 KB/s (assuming 16-bit samples)
  • File Rate: One file every ~16 seconds
  • Sustained Rate: Limited by flash write speed

Troubleshooting

Common Issues

  1. **"FAILED TO OPEN EXTERNAL FLASH"**
    • Check SD card insertion and formatting
    • Verify card compatibility (FAT16/FAT32)
    • Ensure proper card mounting on development board
  2. No audio in WAV files
    • Verify analog signal connection to correct ADC pin
    • Check signal amplitude (0-3.3V range)
    • Confirm ADC channel configuration matches hardware
  3. DMA timing issues
    • Verify DMA timer configuration
    • Check for timer conflicts with other peripherals
    • Monitor CPU loading for interference
  4. File system errors
    • Reformat SD card with FAT32
    • Check available disk space
    • Verify file system initialization

Debug Techniques

Signal Verification:**

// Add to main loop for signal monitoring
printf("ADC Value: %d\r\n", GetADResult(ADC_CHANNEL));

Buffer Status:**

// Monitor buffer fill status
printf("Buffer half: %s\r\n", frontFilled ? "back" : "front");

DMA Status:**

// Check DMA operation
printf("DMA active: %s\r\n", isDMAActive() ? "yes" : "no");

Application Extensions

Audio Processing

  • Real-time filtering (high-pass, low-pass, band-pass)
  • Signal analysis (FFT, spectral analysis)
  • Compression/decompression algorithms
  • Echo/reverb effects

Multi-Channel Recording

  • Simultaneous sampling of multiple ADC channels
  • Stereo WAV file creation
  • Channel synchronization
  • Mixed-signal analysis

Advanced Features

  • Triggered recording (threshold-based)
  • Continuous streaming over network
  • Real-time audio playback
  • Data compression before storage

Integration Examples

  • Audio monitoring systems
  • Vibration analysis
  • Environmental sound recording
  • Signal quality measurement

Performance Optimization

High-Speed Modifications

// Increase sample rate to 16 kHz
#define SAMPLE_FREQ 16000
// Larger buffers for reduced interrupt frequency
#define BUFFERSIZE 4096

Memory Optimization

// Use external RAM for data buffer if available
uint8_t *dataBuffer = (uint8_t*)EXTERNAL_RAM_BASE;

Real-Time Processing

// Process data in DMA callback for minimum latency
void dmaTriggerFunc(void *start, void *end) {
// Immediate signal processing here
processAudioData(sampleBuffer + (frontFilled ? HALFBSIZE : 0));
frontFilled = !frontFilled;
AdcDmaSem.Post();
}

Related Examples

  • SimpleADC: Basic ADC polling operation
  • WavPlayer: Audio playback functionality
  • DSPI Examples: High-speed serial data acquisition
  • DAC Examples: Analog output generation
  • Timer Examples: Precise timing control