Read one capture of a timer, clock by clock: find the prescaler value, the frame, the duty cycle, the match and the captured event.
Hardware context: Timer and PWM block of ap_soc: a prescaler, a four-slot counter, compare, capture and PWM. Reading a timer capture during bring-up of a motor or lamp driver
This capture comes from the Timer and PWM block of lesson S6.13, with other register values. Software has written DIV_TOP, COMPARE and DUTY. During the capture it writes 1 to RUN. Later a pulse arrives on the capture input, and later still software reads CAPTURED.
This worksheet uses named constants. The first three entries show how to record your decisions.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
| Edge | Slot | Prescaler count | PWM pin | match | Capture input | CAPTURED holds | Read of CAPTURED |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 4 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 5 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| 6 | 0 | 2 | 1 | 0 | 0 | 0 | 0 |
| 7 | 1 | 0 | 1 | 1 | 0 | 0 | 0 |
| 8 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 9 | 1 | 2 | 1 | 1 | 0 | 0 | 0 |
| 10 | 2 | 0 | 1 | 0 | 0 | 0 | 0 |
| 11 | 2 | 1 | 1 | 0 | 0 | 0 | 0 |
| 12 | 2 | 2 | 1 | 0 | 0 | 0 | 0 |
| 13 | 3 | 0 | 0 | 0 | 0 | 0 | 0 |
| 14 | 3 | 1 | 0 | 0 | 0 | 0 | 0 |
| 15 | 3 | 2 | 0 | 0 | 0 | 0 | 0 |
| 16 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 17 | 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| 18 | 0 | 2 | 1 | 0 | 0 | 0 | 0 |
| 19 | 1 | 0 | 1 | 1 | 0 | 0 | 0 |
| 20 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 21 | 1 | 2 | 1 | 1 | 0 | 0 | 0 |
| 22 | 2 | 0 | 1 | 0 | 0 | 0 | 0 |
| 23 | 2 | 1 | 1 | 0 | 1 | 0 | 0 |
| 24 | 2 | 2 | 1 | 0 | 0 | 2 | 0 |
| 25 | 3 | 0 | 0 | 0 | 0 | 2 | 0 |
| 26 | 3 | 1 | 0 | 0 | 0 | 2 | 0 |
| 27 | 3 | 2 | 0 | 0 | 0 | 2 | 0 |
| 28 | 0 | 0 | 1 | 0 | 0 | 2 | 0 |
| 29 | 0 | 1 | 1 | 0 | 0 | 2 | 0 |
| 30 | 0 | 2 | 1 | 0 | 0 | 2 | 0 |
| 31 | 1 | 0 | 1 | 1 | 0 | 2 | 0 |
| 32 | 1 | 1 | 1 | 1 | 0 | 2 | 0 |
| 33 | 1 | 2 | 1 | 1 | 0 | 2 | 1 |
| 34 | 2 | 0 | 1 | 0 | 0 | 2 | 0 |
Each row is what one rising clock edge sees. The timer does not run in the first rows. The prescaler counts from 0 up to the value in DIV_TOP. The slot counter goes 0, 1, 2, 3 and round again, and four slots are one frame. Enter edges and counts as plain numbers.
| Entry | Your decision |
|---|---|
| START_EDGE | First edge that sees the timer running. The PWM pin is 1 from then on. |
| DIV_TOP_VALUE | Value that software wrote to DIV_TOP. |
| SLOT_CLOCKS | Number of edges that see one slot, while the timer runs. |
| FRAME_CLOCKS | Number of edges in one frame. |
| SECOND_FRAME | First edge of the second frame. |
| HIGH_CLOCKS | Number of edges of one frame that see the PWM pin at 1. |
| DUTY_VALUE | Value that software wrote to DUTY. |
| DUTY_PERCENT | Duty cycle of the PWM pin, in percent. |
| MATCH_EDGE | First edge that sees match at 1. |
| COMPARE_VALUE | Value that software wrote to COMPARE. |
| EVENT_EDGE | Edge that sees the pulse on the capture input. |
| SAVED_SLOT | Slot number that capture saved. |
| READ_SLOT | Slot the counter is in at the edge of the read of CAPTURED. |
| LATE_CLOCKS | Number of clocks from the pulse to the read. |
| HIGH_N | How many edges of one frame would see pwm = 1 if DIV_TOP held N, with every other register as in the capture? |
Examples
Example 1
START EDGE- Input
First edge that sees the timer running. The PWM pin is 1 from then on.
- Output
matches = 1
Edge 4 is the first edge with the PWM pin at 1. From there the prescaler count moves.
Example 2
DIV TOP VALUE- Input
Value that software wrote to DIV_TOP.
- Output
matches = 1
The prescaler count goes 0, 1, 2 and starts again. Its last count is 2.
Example 3
SLOT CLOCKS- Input
Number of edges that see one slot, while the timer runs.
- Output
matches = 1
Edges 4, 5 and 6 see slot 0. That is DIV_TOP + 1.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For HIGH_N, enter a constant expression using N. Only this entry changes with the parameter. The supported integer range is 0 through 15, inclusive.
Hints
Hint 1
Watch the prescaler count once the timer runs. Its largest value is what DIV_TOP holds.
Hint 2
A frame starts at an edge that sees slot 0 with the prescaler count at 0, after slot 3.
Hint 3
The capture input marks the event. The read column marks the moment software looked.
What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.
15 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 1 problem on this path