Teach lesson
Pause a clocked counter · VHDL
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.
Sign in with an educator account to prepare a class session. Students join with a class code.
New to LabsLand? Create your teacher account
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.
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?
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.
Use an elsif condition after the synchronous reset. Omitting an assignment in a clocked process retains the register value.
Start with this complete file. The marked line is the part to change.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity blink is
port (
mclk : in std_logic;
sw : in std_logic_vector(15 downto 0);
led : out std_logic_vector(15 downto 0)
);
end entity;
architecture rtl of blink is
signal meta, stable : std_logic_vector(15 downto 0) := (others => '0');
attribute ASYNC_REG : string;
attribute ASYNC_REG of meta, stable : signal is "TRUE";
constant cycles : positive := 100000000;
signal phase : natural range 0 to cycles - 1 := 0;
signal count : unsigned(1 downto 0) := (others => '0');
begin
process(mclk)
begin
if rising_edge(mclk) then
meta <= sw;
stable <= meta;
end if;
end process;
process(mclk)
begin
if rising_edge(mclk) then
if stable(15) = '1' then
phase <= 0;
count <= (others => '0');
else -- *
if phase = cycles - 1 then
phase <= 0;
count <= count + 1;
else
phase <= phase + 1;
end if;
end if;
end if;
end process;
led <= "00000000000000" & std_logic_vector(count);
end architecture;Open the editable Boolean Board lab. Paste the starting circuit into the main file (blink.vhd) and keep blink as the top-level design.
Repair the run condition between reset and the divider. Keep the hardware divisor at 100,000,000 for the physical test.
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.
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.
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.
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.
New to LabsLand? Create your teacher account