Aim
To interface a DAC (DAC0808) with the microcontroller and write programs to generate square, ramp and triangular waveforms.
Learning objectives
Explain how a digital code becomes an analogue voltage and calculate Vout.
Calculate the step size (Vref/256) and the full-scale output.
Generate square, ramp (sawtooth) and triangular waves in software.
Relate the loop timing to the waveform frequency and adjust it.
Measure amplitude and frequency on an oscilloscope.
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
Output voltage
Waveform frequency
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)
| DAC0808 | 8051 |
|---|---|
| D7 (MSB) … D0 | P1.7 … P1.0 |
| Vref | +5 V via 5 k |
| Iout | op-amp I→V converter → CRO |
Apparatus & environment
| Item | Specification | Qty |
|---|---|---|
| PC with Keil µVision | C51/A51 tool chain (evaluation version is fine) | 1 |
| 8051 trainer board | Nuvoton W78E052D, 11.0592 MHz crystal | 1 |
| Nuvoton ISP-ICP utility | APROM programming over USB-UART (CH340) | — |
| USB cable | USB-A to the board's serial/ISP port | 1 |
| Power supply | +5 V regulated (board adapter) | 1 |
| DAC module | DAC0808 + op-amp (LM741/TL082) | 1 |
| CRO / DSO | ≥ 20 MHz oscilloscope | 1 |
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)
- Connect P1 to the DAC inputs and the op-amp output to CRO channel 1 (power off).
- Build and program 12.1 A (square). Measure the amplitude and frequency.
- Repeat for ramp (12.1 B) and triangle (12.1 C).
- Change the delays or step sizes and record the new frequency.
- Optional: 12.1 D sine from a table.
Doing it in this virtual lab
- Choose a sub-task chip. The program opens in the µVision window.
- Press 🔨 Build (F7). Errors are listed in Build Output: click one to jump to the line.
- Press ▶ Run (F5) and watch the board. Use ¼× to 1/1000× slow motion to see fast events.
- Use Step (F11) and Step Over (F10), and click line numbers to set breakpoints.
- Edit the code (delay, pattern, pins), rebuild, and observe the change. Press ● Record to log results.
- 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-task | Inputs | Expected | Simulator | Your value | Check | Note |
|---|
Edge cases to test
- 12.1 B: change v++ to v += 4: what happens to the frequency and the step size?
- 12.1 C: use
v <= 255in the first loop (unsigned char): an endless loop with a C294 warning. - 12.1 A: make the high and low times unequal (25 % duty).
- Switch to the 1T core: how does the frequency change?
- Set the time/div to 0.1 ms and count the steps of the ramp.
- 12.1 D: use only every second table entry: what frequency do you get?
Analysis & conclusion
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.
Self-evaluation
Tick what you can now do confidently.