C · Local Linux terminal
Hold a square wave still on the screen
Online version: https://fpga.labsland.com/altera/embedded-systems/lab-09/part-03/
Your computer
Embedded Systems · Triggered acquisition. A signal generator feeds a 100 Hz square wave into channel 0 of an oscilloscope. Move the trigger switch and the first visible edge should change direction. Your scope ignores the switch. Find the error without changing the generator or the timebase.
You need Linux, a C compiler and Python 3. Unzip the activity. The three input files record output edges from the register bench in the preceding activity, at 10, 100 and 160 Hz. Here a modeled ADC converts the low level to 0 V and the high level to 3.3 V. The visualizer plots a 100 ms window across 320 columns and a vertical range of 0–5 V.
Capture both edges
Compile the program, then take three sweeps with each setting. A value of 1 represents SW0 up (rising trigger). A value of 0 represents SW0 down (falling trigger).
cc -std=c11 -O2 -Wall -Wextra -Werror starter/scope.c -lrt -o scope
export SCOPE_REPLAY_SLOW=8
./scope edges resources/generator-100.csv 1 3 4096 up > up.csv
./scope edges resources/generator-100.csv 0 3 4096 down > down.csv
python3 resources/read_sweep.py up.csv
python3 resources/read_sweep.py down.csv
Open up-01.svg and down-01.svg in a browser. In a rising-trigger sweep, should column zero be high or low? Predict the result for a falling trigger. Compare your two predictions with the first ADC codes in the CSVs.
The figure shows two reference sweeps. Identify their trigger directions from the left edge. Locate one period on each trace. Changing the trigger should change the starting phase while leaving the frequency unchanged.
Repair the trigger
Open starter/scope.c. The two inputs to crossing indicate whether the previous and current conversions are above the trigger threshold of 1.65 V. Make the function accept the requested transition. Holding a constant level must never trigger a sweep. Recompile, repeat both commands and fill in the table.
Record the first ADC code before and after the edit, then two successive rising columns from the repaired capture.
| SW0 | Transition | First code | Fixed code | Rising columns |
|---|---|---|---|---|
| 1 | low to high | |||
| 0 | high to low |
Read the spacing between two successive rising columns in a complete portion of the trace. Each column represents 100 ms ÷ 320, so a separation of 32 columns corresponds to 10 ms. How does that compare with the generator setting? Keep the three separate sweeps separate when counting cycles. The scope rearms between them.
Test the ends of the range
Repeat with generator-10.csv and generator-160.csv. Predict how many periods fit in each window before opening an SVG. In which case might the screen show too little to measure two successive rising edges?
At a 4.096 V ADC span, a code of 3300 represents 3.300 V. Select a 5000 mV span in the command and repeat one sweep. Use code × span / 4096 to recover millivolts. Explain why the high code changes while the trace stays at about the same height.
Account for gaps
The acquisition uses a POSIX interval timer. A late wake-up can skip one or more sample times. The CSV records each missed column as −1, and the drawing leaves a gap. Running the replay at eight times its normal wall-clock duration gives a busy machine more time between notifications. Its 100 ms signal window and column labels stay the same.
Unset the replay adjustment with unset SCOPE_REPLAY_SLOW and repeat a capture. Compare the gap counts. Keep an unbroken region for measuring a period. If both runs have zero gaps, explain what the program would lose if the scheduler delayed a sample.
Turn in your repaired function, the completed table and a labeled sweep. Identify the evidence that the program rearmed for a new trigger, and explain how you distinguished a missing sample from a measured zero.
FPGAcademy exercise · Exercise notice · LabsLand source license
