C · Local Linux terminal
Why does a 3.3 V pulse look like 0.24 V?
Online version: https://fpga.labsland.com/altera/embedded-systems/lab-09/part-01/
Your computer
Embedded Systems · Linux and C. Two instruments disagree. An external oscilloscope connected to a DE1-SoC at the University of Deusto measured a pulse near 3.3 V. A program reading modeled 12-bit conversions of the same trace reports a much smaller high level. Find out where the high bits went.
You need a C compiler and Python 3. The ZIP includes the measured voltage trace, a short register capture with known inputs and the C reader. The analog-to-digital converter (ADC) in this terminal exercise is a model with a 4.096 V span.
Read the register
The controller's channel-0 register contains a 12-bit unsigned conversion in bits 11–0. Bit 15 means a new conversion is ready. A register read consumes that flag. Two fresh samples can have the same value.
At a 4.096 V span, one of the 4,096 equal code intervals is 1 mV wide. Code 4095 represents the final interval, which begins at 4.095 V. The program reports the lower edge of the interval in microvolts. Predict the output for the four register reads below before compiling.
| Raw register | Fresh? | Expected code | Starter output | Repaired output |
|---|---|---|---|---|
| 0x00000400 | ||||
| 0x000083ff | ||||
| 0x00008400 | ||||
| 0x00008fff |
cc -std=c11 -O2 -Wall -Wextra -Werror starter/read_adc.c -o read_adc
./read_adc replay resources/reference-reads.txt 4096 8
Find the first fresh row that disagrees with your prediction. Compare the raw register with the decimal output in that row. Repair adc_code in the starter, recompile and repeat. Why should both occurrences of the fresh word 8800 appear in the output, while 0400 produces no row?
Follow a signal from the remote lab
The green line shows the first 100 measurements of channel 1 on the external instrument. The lower panel shows what the starter reports when those voltages are passed through the ADC model. Both use the same vertical scale and sample numbers.
On Windows with the Python launcher, use py -3 wherever a command starts with python3.
python3 resources/model_input.py resources/deusto-trace-A.csv pulse.txt --full-scale-mv 4096
./read_adc replay pulse.txt 4096 500 > pulse.csv
Find the largest reconstructed voltage and count how many of the 500 samples exceed 1.5 V. Use this command to check both readings:
python3 -c "import csv; a=[int(r['microvolts']) for r in csv.DictReader(open('pulse.csv'))]; print(max(a)/1000000, sum(v>1500000 for v in a))"
Compare your results with the measured voltages in resources/deusto-trace-A.csv. The external scope measured small negative values near ground. Explain why the modeled unipolar ADC returns zero for them. The file's first column is a sample number; use it to locate an edge.
Change the measuring range
Repeat with a new model file, range5.txt, and a full-scale value of 5000 in both commands. This changes a software setting. Predict whether the high pulse will change in code, in reconstructed volts or in both. Turn in the register table, your edit and a comparison of the two reconstructed high voltages. Identify the measurement that came from the physical board and the two results computed by your program.
FPGAcademy exercise · Exercise notice · LabsLand source license
