LPC2148 DAC (Digital to Analog Converter)
Introduction to DAC
Digital to Analog Converter (DAC) are mostly used to generate analog signals (e.g. sine wave,
triangular wave etc.) from digital values.
LPC2148 has 10-bit DAC with resistor string architecture. It also works in Power down
mode.
LPC2148 has Analog output pin (AOUT) on chip, where we can get digital value in the
form of Analog output voltage.
The Analog voltage on AOUT pin is calculated as ((VALUE/1024) * VREF). Hence,
we can change voltage by changing VALUE (10-bit digital value) field
in DACR (DAC Register).
e.g. if we set VALUE = 512,
then, we can get analog voltage on AOUT pin as ((512/1024) * VREF) = VREF/2.
LPC2148 DAC Pins
AOUT (Analog Output)
This is Analog Output pin of LPC2148 DAC peripheral where we can get Analog output
voltage from digital value.
VREF (Voltage Reference)
Provides Voltage Reference for DAC.
VDDA& VSSA (Analog Power and Ground)
These are the power and ground pins for DAC. These should be same as VDD& VSS.
DAC Register Configuration
DACR (DAC Register)
DACR is a 32-bit register.
It is a read-write register.
DACR (DAC Register)
Bit 5:0 – RESERVED
Bits 15:6 – VALUE
This field contains the 10-bit digital value that is to be converted in to Analog voltage.
We can get Analog output voltage on AOUT pin and it is calculated with the formula
(VALUE/1024) * VREF.
Bit 16 – BIAS
0 = Maximum settling time of 1µsec and maximum current is 700µA
1 = Settling time of 2.5µsec and maximum current is 350µA
Note that, the settling times are valid for a capacitance load on the AOUT pin not
exceeding 100 pF. A load impedance value greater than that value will cause settling
time longer than the specified time.
Bit 31:17 – RESERVED
Programming Steps
First, configure P0.25/AOUT pin as DAC output using PINSEL Register.
Then set settling time using BIAS bit in DACR Register.
Now write 10-bit value (which we want to convert into analog form) in VALUE field
of DACR Register.
Example Program
Let’s write a simple program for LPC2148 DAC.
Here, we will load the DACR value with various values to generate a sine wave, triangular
wave, sawtooth wave, square wave and DC wave.
4 switches are used as inputs on P0.8 (for sine wave), P0.9 (for triangular wave), P0.10 (for
sawtooth wave), and P0.11 (for square wave) pins.
These pins are connected to 3.3 V through pull-up resistors. The switches are connected as
shown below. Only switch for P0.8 is shown in the figure. Switches are connected in a similar
manner to the other 3 pins as well. If we connect the DAC output pin P0.25 to an oscilloscope,
we can observe the different waves.
Interfacing Diagram
Pushbutton Interfacing with LPC2148
#include <lpc214x.h>
#include <math.h>
void DAC_Init() {
PINSEL1 |= (1 << 18); // Configure P0.25 as DAC output
}
void delay() {
for (int i = 0; i < 1000; i++); // Short delay
}
void generateWaveform() {
unsigned int value;
if (!(IO0PIN & (1 << 8))) { // Sine wave (Switch P0.8 pressed)
for (int i = 0; i < 360; i += 10) {
value = (unsigned int)(512 + 512 * sin(i * 3.14159 / 180)); // Scale sine wave
DACR = value << 6; // Load DACR with sine value
delay();
}
} else if (!(IO0PIN & (1 << 9))) { // Triangular wave (Switch P0.9 pressed)
for (value = 0; value < 1023; value += 10) {
DACR = value << 6;
delay();
}
for (value = 1023; value > 0; value -= 10) {
DACR = value << 6;
delay();
}
} else if (!(IO0PIN & (1 << 10))) { // Sawtooth wave (Switch P0.10 pressed)
for (value = 0; value < 1023; value += 10) {
DACR = value << 6;
delay();
}
} else if (!(IO0PIN & (1 << 11))) { // Square wave (Switch P0.11 pressed)
for (int i = 0; i < 2; i++) {
DACR = (i % 2 == 0) ? 1023 << 6 : 0;
delay();
}
}
}
int main() {
DAC_Init(); // Initialize DAC on P0.25
IO0DIR &= ~(0xF << 8); // Set P0.8-P0.11 as inputs for switches
while (1) {
generateWaveform(); // Generate waveform based on switch input
}
}