Teach Remote lab lessons

Teach lesson

Pause a clocked counter · Verilog

A stopwatch must pause as soon as its run switch goes low. Build a two-bit timer that preserves both the displayed count and the unfinished part of the second.

  • RealDigital BooleanBoard FPGA
  • 50 min
  • Upper secondary, technical college or first-year engineering
  • English
  • Electronics · Technology

Sign in with an educator account to prepare a class session. Students join with a class code.

RealDigital BooleanBoard FPGA
RealDigital BooleanBoard FPGA

Learning Outcomes

  • Implement a clock enable and verify pause, resume, wrap and reset.

Student activity preview

Activity Content

Preview only. In a class session, students can fill in responses and submit their work to the teacher.

1

Predict

8 min

A stopwatch must pause as soon as its run switch goes low. Build a two-bit timer that preserves both the displayed count and the unfinished part of the second.

The board clock is 100 MHz, so a second contains 100,000,000 rising edges. The phase register counts from zero through 99,999,999. At the final edge it returns to zero and advances the displayed two-bit count. Both registers share one clock. SW0 enables counting and SW15 requests reset.

Imagine a divider of four edges per displayed tick. Run for three edges, pause for six and resume for one. What should the display show before and after that last edge?

2

Build and test

35 min

Starting circuit

The starter always advances its divider. Add a run enable around both updates so pause preserves the partial interval.

In a clocked if/else if, registers retain their current values when no branch assigns to them.

Start with this complete file. The marked line is the part to change.

module leds_mirror(
    input wire mclk,
    input wire [15:0] sw,
    output wire [15:0] led
);

// The operator sets one switch at a time and lets each setting settle.
(* ASYNC_REG = "TRUE" *) reg [15:0] meta = 0, stable = 0;
always @(posedge mclk) begin
    meta <= sw;
    stable <= meta;
end
localparam integer CYCLES = 100000000;
reg [26:0] phase = 0;
reg [1:0] count = 0;
always @(posedge mclk) begin
    if (stable[15]) begin
        phase <= 0;
        count <= 0;
    end else begin // *
        if (phase == CYCLES - 1) begin
            phase <= 0;
            count <= count + 1'b1;
        end else begin
            phase <= phase + 1'b1;
        end
    end
end
assign led = {14'd0, count};

endmodule
  1. Open the editable Boolean Board lab. Paste the starting circuit into the main file (leds_mirror.v) and keep leds_mirror as the top-level design.

  2. Repair the run condition between reset and the divider. Keep the hardware divisor at 100,000,000 for the physical test.

  3. Check that the interface is Standard. Wait for the edit to save, choose Synthesize, wait for success, then choose Upload to FPGA. The board can open directly. If the board picker stays open, choose Upload now under Boolean Board. If it reports temporary unavailability, wait briefly and retry there. Your saved HDL stays in the editor. Find the numbered switches and the board camera.

  4. For each reset, switch SW15 on, wait until the control shows 1, then switch it off and wait for 0. Keep SW0 still during reset. Let the camera refresh before reading the LEDs. Reset with SW0 low. Raise SW0 and watch LED1 LED0. Lower SW0 at a nonzero reading and note it twice at least three seconds apart. Resume until 11 wraps to 00. Assert reset while paused.

  5. After your last reading, leave the board and return to this activity. Choose Attach saved code and check that a file appears. Select Mark practice as done and confirm. After filling in your bench notes and explanation, choose Submit work and confirm your submission.

Available in a class session

Bench notes

On the pause row write both readings and the approximate wait. On the resume row write consecutive states including wrap.

Test Observed output

Tested source

Capture the project you synthesized using the activity's code snapshot control.

3

Defend your result

7 min

Use your pause and resume readings to justify what the LEDs prove. Can a camera reading alone show how much of a second remained? Explain using the four-edge prediction.

Turn this preview into a live class session

Continue to LabsLand Teach to use this lesson with your students and review the access available to your account.