DAC - Digital to Analog Converter Example
Overview
This NetBurner application demonstrates the use of the integrated Digital-to-Analog Converter (DAC) on MCF5441X-based platforms. The application provides two operating modes: manual DAC output control and automatic waveform generation using DMA timer triggering.
Supported Platforms
- MOD5441X - DAC0 output on J2.9, Timer0 output on J2.36
- NANO54415 - DAC0 output on J2.9, Timer0 output on Pin 19
Hardware Requirements
- NetBurner module with DAC capability
- CRITICAL: Analog reference voltage connection required
- Oscilloscope or voltmeter for output monitoring
- Optional: Load resistor for current measurement
Analog Reference Voltage Setup
MOD5441X Platforms:**
WARNING: The DAC will not function without proper analog reference connection!
DAC Specifications
- Resolution: 12-bit (4096 levels: 0x000 to 0xFFF)
- Output Range: 0V to Vref (typically 3.3V when properly configured)
- Output Pin: J2.9 (DAC0 output)
- Reference Input: Platform-specific analog reference pin
- Update Rate: Software controlled (Mode 1) or hardware triggered (Mode 2)
Application Functionality
Mode 1: Manual DAC Output Control
Operation:**
Mode 2: Hardware-Triggered Waveform Generation
Operation:**
Technical Implementation
DAC Configuration Registers
Control Register (DAC_CR):**
Hardware Configuration
sim1.ccm.misccr2 |= MISCCR2_DAC0SEL;
sim1.ccm.misccr2 &= ~(MISCCR2_ADC3EN);
sim2.adc.cal = ADC_CAL_DAC0;
sim2.dac[0].cr &= ~DAC_CR_PDN;
DMA Timer Setup
float frequency = 100000;
float toggleTime = (1.0 / frequency) * 0.5;
float cpuClockPeriod = (1.0 / (CPU_CLOCK / 2));
uint32_t refTimerCount = (uint32_t)(toggleTime / cpuClockPeriod);
sim2.timer[0].tmr = 0x002A;
sim2.timer[0].trr = refTimerCount;
sim2.timer[0].tmr |= 0x0001;
User Interface
Menu System
1. Simple DAC output writing to DAC data register
2. DAC waveform generation using DMA Timer 0
Operation Flow
- Select operating mode (1 or 2)
- Monitor DAC output on J2.9 with oscilloscope/voltmeter
- Press any key to stop current operation
- Return to menu for mode selection
Expected Outputs
Mode 1 - Manual Control:**
Hardware Connections and Testing
Basic Setup
- Power connections: Ensure proper 3.3V and ground
- Reference voltage: Connect analog reference as specified above
- DAC output: Monitor J2.9 with oscilloscope or voltmeter
- Timer output (Mode 2): Monitor timer pin for trigger signal
Test Procedures
Voltage Verification:**
Load Testing
Troubleshooting
Common Issues
- No DAC output
- Check analog reference voltage connection
- Verify DAC power-on (PDN bit = 0)
- Confirm J2.9 pin configuration
- Measure reference voltage at analog input pin
- Incorrect output voltage range
- Verify reference voltage is exactly 3.3V
- Check for voltage divider loading
- Confirm DAC data register values (0x000-0xFFF)
- Mode 2 not working
- Verify DMA timer configuration and frequency
- Check timer output pin assignment
- Confirm DAC sync configuration
- Monitor timer output signal
- Noisy output
- Add bypass capacitors near DAC output
- Check power supply stability
- Verify proper grounding
- Use appropriate load impedance
Debug Techniques
Register Monitoring:**
iprintf("DAC Value: 0x%04X\r\n", sim2.dac[0].data);
iprintf("DAC CR: 0x%04X\r\n", sim2.dac[0].cr);
Timer Verification:**
iprintf("Timer TMR: 0x%04X\r\n", sim2.timer[0].tmr);
iprintf("Timer TCN: 0x%04X\r\n", sim2.timer[0].tcn);
Advanced Features
Custom Waveform Generation
if(sim2.dac[0].cr & DAC_CR_UP) {
if(sim2.dac[0].data >= 0x0FFF) {
sim2.dac[0].cr &= ~DAC_CR_UP;
sim2.dac[0].cr |= DAC_CR_DOWN;
}
} else {
if(sim2.dac[0].data <= 0x0000) {
sim2.dac[0].cr &= ~DAC_CR_DOWN;
sim2.dac[0].cr |= DAC_CR_UP;
}
}
Arbitrary Waveform Playback
const uint16_t sineWave[256] = { };
static uint8_t index = 0;
sim2.dac[0].data = sineWave[index++];
if(index >= 256) index = 0;
Multiple Channel Support
sim1.ccm.misccr2 |= MISCCR2_DAC1SEL;
sim2.dac[1].cr &= ~DAC_CR_PDN;
sim2.dac[1].data = value1;
Performance Characteristics
Timing Specifications
- Settling Time: Typically <1 microsecond to 0.1% accuracy
- **Update Rate**: Limited by CPU (Mode 1) or timer frequency (Mode 2)
- **Resolution**: 12-bit (0.8mV steps with 3.3V reference)
- **Linearity**: Dependent on reference voltage stability
CPU Loading
- **Mode 1**: High CPU usage for continuous updates
- **Mode 2**: Low CPU usage with hardware triggering
- **Interrupt Overhead**: Minimal with DMA timer
Application Extensions
Signal Generation
- Function generators (sine, square, triangle)
- Audio signal synthesis
- Test pattern generation
- Calibration reference signals
Control Systems
- Analog control loops
- Servo motor control
- Variable reference generation
- Offset/bias voltage generation
Communication
- FSK modulation
- Analog data transmission
- Level shifting
- Interface voltage generation
Integration Examples
void SetDACFromWeb(uint16_t value) {
if(value <= 0x0FFF) {
sim2.dac[0].data = value;
}
}
void ADCControlledDAC() {
uint16_t adcValue = GetADResult(0);
uint16_t dacValue = ProcessControlLoop(adcValue);
sim2.dac[0].data = dacValue;
}
Related Examples
- ADC Examples: Analog input measurement and feedback control
- PWM Examples: Alternative analog output methods
- Timer Examples: Precise timing and triggering
- Waveform Generation: Advanced signal synthesis techniques