UT.6.03x Embedded Systems  Shape the World  Lab 13: DigitalAnalog Conversion (DAC)
OVERVIEW:
Our world is both digital and analog. We usually see analog things in real life, such as mechanical watches/clocks, light dimmers, and potentiometers. There are also digital devices, such as digital watches/clocks, switches, and buttons. Therefore, the ability of converting from analog to digital and from digital to analog is vital. In this chapter, we will learn about Digitization, Nyquist Theorem, and DigitalAnalog Conversion (DAC).
DIGITIZATION:
Digitization means taking an analog signal and digitize it, using two concepts:
 Amplitude quantization  discrete the signal
 Time quantization  sampling
There are two methods of digitization:
In this chapter, we will cover the rate and analog standpoint. I think how the DAC works is related to how we use Calculus in calculating areas / volumes
, because “how faithful is faithful enough?” is similar to “how small is small enough for a subinterval?”.
NYQUIST THEOREM:
If a signal is oscillating at a frequency f
, in order to capture it faithfully, we must sample at a frequency that is strictly larger than 2f
For example, a runner can complete a circular lab within 60 seconds. I want to track that runner to see if he can run 10 laps without taking breaks. However, I’m a lazy person, so I only want to check him just a number of times, but I need to be sure that I miscount his laps. Based on Nyquist Theorem, in order to do that, I have to check him at most every 30 seconds.
DAC:
DAC stands for DigitalAnalog Conversion. By default, machines work digitally, which means that they only understand TRUE
and FALSE
(That’s why the standard machine language only has 1 and 0). On the other hand, our world is represented by analog signals. Thus, in order to produce analog outputs, computers must have DAC. There are many methods for DAC, but in this chapter, we will only talk about Binary Weighted Circuit and R2R Ladder.

Binary Weighted Circuit:
Has parallel resistors.
Resistor values increase as the number of bits decrease. That means the largest resistor goes on the least significant bit.
As the number of bits decreases, the resistor values get doubled.

R2R Ladder: Has a Tstructure.
Resistors which have value 2R are placed vertically, whereas resistors which have value R are placed horizontally.
The more bits of the DAC, the more accurate the analog signal will be. This is what makes me think DAC is similar to Calculus. The more segments we divide a curve into, the straighter each segment will become.
To solve the DAC circuit, we need to draw equivalent circuits in order to simplify the DAC. Then, we will use the voltage divider method to find V_{out}.
LAB 13:
There is a mistake I made in this lab. It was a deadly mistake, and it took me two days to figure it out. It wasn’t too difficult, but it was imperceptible. It was the integer division.
First, I declared an integer named frequency
, which represents the frequency of the notes. frequency
had big values, so when I took 1 and perform the /
expression, it would return zero. Because / in integer perspective is “divide and take the integer part”, not “divide and take the whole real number”. That was why I couldn’t change the SysTick to vary the output frequency.
PARTS:
 1 x EKTM4C123GXL
 1 x Breadboard
 4 x Switches
 4 x 10kilohm resistors
 3 x 1.5kilohm resistors
 3 x 12kilohm resistors
 I suggest using a buzzer because it has a smaller resistance than the combination of the audio jack and the headphone. The smaller resistance, the louder sound becomes.
 Some jumper wires
BREADBOARD LAYOUT:
There is a trick to wire up a DAC. Using to series and parallel laws, we can make a 3kilohm resistor by wiring two 1.5kilohm resistors in series. Also, we can create a 6kilohm resistor by connecting two 12kilohm resistors in parallel. 1.5 kilohms, 3 kilohms, 6 kilohms, and 12 kilohms altogether make a 4bit DAC.
CODE:
Note that to be able to run and grade the labs, you have to follow the software requirements. Unfortunately, the software and the course don’t support Linux. However, if you follow the official instruction from Texas Instruments, you can upload and run your program on the LaunchPad.
See below for my dac.c, or view all lab files on my GitHub.
/** * UTAustinX: UT.6.03x Embedded Systems  Shape the World * Lab 13: DigitalAnalog Conversion * * File Name: dac.c * * Description: Creates a sinusoid sound wave using 4bit DAC * and simulate C, D, E, and G notes of the piano. * * Author: Phi Luu * Location: Portland, Oregon, United States * Created: April 22, 2016 * Updated: June 23, 2017 */ // 4bit DAC connected to PB3PB0 #include "dac.h" #include "tm4c123gh6pm.h" /** * Initializes 4bit DAC. */ void InitDac(void) { volatile unsigned long delay; SYSCTL_RCGC2_R = 0x02; // unlock port B clock delay = SYSCTL_RCGC2_R; // allow time for clock to start GPIO_PORTB_LOCK_R = 0x4C4F434B; // unlock GPIO Port B GPIO_PORTB_CR_R = 0x0F; // allow change to PB3PB0 GPIO_PORTB_AMSEL_R &= ~0x0F; // disable analog function on PB3PB0 GPIO_PORTB_PCTL_R = 0x00; // clear PCTL register on PB3PB0 GPIO_PORTB_DIR_R = 0x0F; // PB3PB0 outputs GPIO_PORTB_AFSEL_R &= ~0x0F; // disable alternate function on PB3PB0 GPIO_PORTB_DEN_R = 0x0F; // enable digital pins on PB3PB0 GPIO_PORTB_DR8R_R = 0x0F; // enable 8mA drive select on PB3PB0 } /** * Writes output to DAC. * * @param data 4bit data, 0 to 15 */ void OutDac(unsigned long data) { // write every single value from the SineWave array GPIO_PORTB_DATA_R = data; }