Teach lesson
One point per press · VHDL
A scorekeeper holds a switch up for a whole second. Make that action count once on a board whose clock ticks 100 million times per 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
Use stored input history to count one event per rising transition.
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 scorekeeper holds a switch up for a whole second. Make that action count once on a board whose clock ticks 100 million times per second.
A register samples its input at a rising clock edge. The two input registers give an external switch time to settle into the clock domain. A third register remembers the previous sampled value. A rising event is present when the current sample is 1 and the previous sample was 0. SW15 resets the score and LED1 LED0 show it in binary.
Starting at zero, predict the recorded scores after SW0 rises, stays high, falls and rises again. Why can a condition that simply tests high count too often?
Build and test
35 min
Starting circuit
The starter calculates a rising-event signal but the scoring register still watches the sustained level. Use the event to decide when to increment.
Inside a clocked process, a signal assigned with <= takes its new value after the process suspends. The previous sample is therefore available for comparison.
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";
signal previous : std_logic := '0';
signal point : std_logic;
signal score : unsigned(1 downto 0) := (others => '0');
begin
process(mclk)
begin
if rising_edge(mclk) then
meta <= sw;
stable <= meta;
end if;
end process;
point <= stable(0) and not previous;
process(mclk)
begin
if rising_edge(mclk) then
previous <= stable(0);
if stable(15) = '1' then
score <= (others => '0');
elsif stable(0) = '1' then -- *
score <= score + 1;
end if;
end if;
end process;
led <= "00000000000000" & std_logic_vector(score);
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.
Change the marked counting condition. Keep reset ahead of the event and leave the synchronizer clocked by mclk.
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. Start with SW0 low. Assert SW15, release SW15, then raise SW0. Hold it up for two seconds, lower it, then raise it again. Read LED1 LED0 after each action.
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
Compare two samples
Read each vertical line from top to bottom. At which samples should the score advance?
Bench notes
Record the two-bit score at each step. On the hold row, compare the beginning and end of the wait.
| Test | Observed output |
|---|---|
Tested source
Capture the project you synthesized using the activity's code snapshot control.
Defend your result
7 min
Which two rows show that a steady high input can coexist with a steady score? Describe what the previous-sample register stores on the next clock edge.
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