∿
MPMC Lab · Experiment 12 · 8051 · DAC

DAC Interfacing and Waveform Generation

Generate square, ramp and triangular waveforms (plus a sine table) with a DAC0808.

☰ All experiments

Aim

To interface a DAC (DAC0808) with the microcontroller and write programs to generate square, ramp and triangular waveforms.

Learning objectives

1
DAC principle
Explain how a digital code becomes an analogue voltage and calculate Vout.
2
Resolution
Calculate the step size (Vref/256) and the full-scale output.
3
Waveforms
Generate square, ramp (sawtooth) and triangular waves in software.
4
Frequency
Relate the loop timing to the waveform frequency and adjust it.
5
Measurement
Measure amplitude and frequency on an oscilloscope.
6
Extension
Generate a sine wave from a look-up table.

What this experiment demonstrates

  • Digital-to-analogue conversion with an R-2R/current-steering DAC.
  • That waveform frequency is set by instruction timing.
  • The trade-off between resolution (steps) and frequency.

Sub-tasks

  • 12.1 A Square wave
  • 12.1 B Ramp (sawtooth) wave
  • 12.1 C Triangular wave
  • 12.1 D (Extension) Sine wave from a table

DAC0808 interface

8051 P1.7…P1.0 DAC0808I = Iref·D/256 op-amp Vout square ramp triangle Vout = Vref × D / 256 (0 ≤ D ≤ 255)Resolution = Vref / 256 = 19.5 mV at Vref = 5 V
Fig 3. DAC0808 interface and the three basic waveforms.

Output voltage

Vout = Vref × D / 256 (D = 0 … 255) Step (resolution) = 5 V / 256 = 19.5 mV D = 80H (128) → 2.50 V D = FFH → 4.98 V

Waveform frequency

Square: f = 1 / (2 × t_half) Ramp: f = 1 / (256 × t_step) t_step = time per loop pass Triangle: f = 1 / (2 × 255 × t_step) Sine (32 points): f = 1 / (32 × t_point)

To lower the frequency add a delay in the loop. To raise it, use fewer, larger steps (for example v += 4), which costs resolution.

Board wiring (this lab)

DAC08088051
D7 (MSB) … D0P1.7 … P1.0
Vref+5 V via 5 k
Ioutop-amp I→V converter → CRO

Apparatus & environment

ItemSpecificationQty
PC with Keil µVisionC51/A51 tool chain (evaluation version is fine)1
8051 trainer boardNuvoton W78E052D, 11.0592 MHz crystal1
Nuvoton ISP-ICP utilityAPROM programming over USB-UART (CH340)—
USB cableUSB-A to the board's serial/ISP port1
Power supply+5 V regulated (board adapter)1
DAC moduleDAC0808 + op-amp (LM741/TL082)1
CRO / DSO≥ 20 MHz oscilloscope1

Safety rules & good practice

  • ⚡ Switch the board off before connecting or removing modules, ribbon cables or jumpers.
  • 🔌 Check the supply: +5 V only. Reverse polarity or more than 6 V destroys the controller.
  • 🧲 Handle ICs by the edges and touch a grounded surface first (ESD).
  • 🔁 Do not drive a port pin connected to a switch with 0 while the switch is pressed to VCC. Read inputs only after writing 1s.
  • 🔥 If a component gets hot or smells, switch off immediately and inform the instructor.
  • 📟 Ground the oscilloscope probe to the board ground only.

Procedure (hardware / real tools)

  1. Connect P1 to the DAC inputs and the op-amp output to CRO channel 1 (power off).
  2. Build and program 12.1 A (square). Measure the amplitude and frequency.
  3. Repeat for ramp (12.1 B) and triangle (12.1 C).
  4. Change the delays or step sizes and record the new frequency.
  5. Optional: 12.1 D sine from a table.
Click a step to tick it off. Your progress is saved in this browser.

Doing it in this virtual lab

  1. Choose a sub-task chip. The program opens in the µVision window.
  2. Press 🔨 Build (F7). Errors are listed in Build Output: click one to jump to the line.
  3. Press ▶ Run (F5) and watch the board. Use ¼× to 1/1000× slow motion to see fast events.
  4. Use Step (F11) and Step Over (F10), and click line numbers to set breakpoints.
  5. Edit the code (delay, pattern, pins), rebuild, and observe the change. Press ● Record to log results.
  6. The scope card auto-scales to 3 periods. Choose a fixed time/div to compare waveforms.

Pre-Lab Test 6 questions · diagnostic

Check your prerequisite knowledge. Each answer gets instant feedback. Score at least 4/6 before using the simulator.

Observation table

Rows are added by ● Record in the simulator: inputs, the expected (theoretical) value and the simulator result. Type your own hand calculation in "Your value" to check it. Add rows by hand for hardware-bench readings. The table is saved in this browser.

#Sub-taskInputsExpectedSimulatorYour valueCheckNote

Edge cases to test

  1. 12.1 B: change v++ to v += 4: what happens to the frequency and the step size?
  2. 12.1 C: use v <= 255 in the first loop (unsigned char): an endless loop with a C294 warning.
  3. 12.1 A: make the high and low times unequal (25 % duty).
  4. Switch to the 1T core: how does the frequency change?
  5. Set the time/div to 0.1 ms and count the steps of the ramp.
  6. 12.1 D: use only every second table entry: what frequency do you get?

Analysis & conclusion

Saved automatically in this browser.

Post-Lab Test 9 questions · instant hints

A wrong answer shows a hint so you can try again. Only first attempts count towards the score.

9. Numerical: Vout (in volts) for D = C0H with Vref = 5 V?

Self-evaluation

Tick what you can now do confidently.

Overall confidence:

Feedback summary

Finish the post-lab test to see your personalised summary.