S6.13.1 Read a Timer Capture

EasyImplement12 minIcarus Verilog · serverReview the topic

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

SignalWidthRole
question8input of each check
Full specification
EdgeSlotPrescaler countPWM pinmatchCapture inputCAPTURED holdsRead of CAPTURED
00000000
10000000
20000000
30000000
40010000
50110000
60210000
71011000
81111000
91211000
102010000
112110000
122210000
133000000
143100000
153200000
160010000
170110000
180210000
191011000
201111000
211211000
222010000
232110100
242210020
253000020
263100020
273200020
280010020
290110020
300210020
311011020
321111020
331211021
342010020

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.

EntryYour decision
START_EDGEFirst edge that sees the timer running. The PWM pin is 1 from then on.
DIV_TOP_VALUEValue that software wrote to DIV_TOP.
SLOT_CLOCKSNumber of edges that see one slot, while the timer runs.
FRAME_CLOCKSNumber of edges in one frame.
SECOND_FRAMEFirst edge of the second frame.
HIGH_CLOCKSNumber of edges of one frame that see the PWM pin at 1.
DUTY_VALUEValue that software wrote to DUTY.
DUTY_PERCENTDuty cycle of the PWM pin, in percent.
MATCH_EDGEFirst edge that sees match at 1.
COMPARE_VALUEValue that software wrote to COMPARE.
EVENT_EDGEEdge that sees the pulse on the capture input.
SAVED_SLOTSlot number that capture saved.
READ_SLOTSlot the counter is in at the edge of the read of CAPTURED.
LATE_CLOCKSNumber of clocks from the pulse to the read.
HIGH_NHow 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

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

START EDGE

Input
First edge that sees the timer running. The PWM pin is 1 from then on.
Expected output
matches = 1

Edge 4 is the first edge with the PWM pin at 1. From there the prescaler count moves.

Run samples executes all 3 public checks. Check all tests runs 15 checks on the server.

Icarus Verilog · server