Challenge - 5 Problems
Clock Divider Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of a simple clock divider with enable
What is the output frequency of the clock signal 'clk_out' if the input clock 'clk_in' is 100 MHz and the divider is set to 4 with enable always high?
VHDL
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity clk_div is Port ( clk_in : in STD_LOGIC; enable : in STD_LOGIC; clk_out : out STD_LOGIC); end clk_div; architecture Behavioral of clk_div is signal count : integer range 0 to 3 := 0; signal clk_reg : STD_LOGIC := '0'; begin process(clk_in) begin if rising_edge(clk_in) then if enable = '1' then if count = 3 then count <= 0; clk_reg <= not clk_reg; else count <= count + 1; end if; end if; end if; end process; clk_out <= clk_reg; end Behavioral;
Attempts:
2 left
💡 Hint
Think about how many input clock cycles it takes to toggle the output clock once.
✗ Incorrect
The clock output toggles every 4 input clock cycles, so one full output clock period is 8 input clock cycles. Since input is 100 MHz, output frequency is 100 MHz / 8 = 12.5 MHz. But the code toggles clk_reg every 4 cycles, so frequency is 100 MHz / (2 * 4) = 12.5 MHz. Wait, the code toggles clk_reg when count reaches 3 (4 cycles), so output frequency is 100 MHz / 8 = 12.5 MHz. The correct answer is 12.5 MHz.
❓ Predict Output
intermediateEffect of enable signal on clock divider output
Given the same clock divider code as before, what happens to 'clk_out' if 'enable' is held low permanently?
VHDL
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity clk_div is Port ( clk_in : in STD_LOGIC; enable : in STD_LOGIC; clk_out : out STD_LOGIC); end clk_div; architecture Behavioral of clk_div is signal count : integer range 0 to 3 := 0; signal clk_reg : STD_LOGIC := '0'; begin process(clk_in) begin if rising_edge(clk_in) then if enable = '1' then if count = 3 then count <= 0; clk_reg <= not clk_reg; else count <= count + 1; end if; end if; end if; end process; clk_out <= clk_reg; end Behavioral;
Attempts:
2 left
💡 Hint
Consider what happens when enable is never '1'.
✗ Incorrect
Since enable is never '1', the count and clk_reg signals never change after initialization. clk_reg was initialized to '0', so clk_out remains at '0' indefinitely.
🔧 Debug
advancedIdentify the error in clock divider with enable
What error will this VHDL code produce when synthesizing a clock divider with enable?
VHDL
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity clk_div is Port ( clk_in : in STD_LOGIC; enable : in STD_LOGIC; clk_out : out STD_LOGIC); end clk_div; architecture Behavioral of clk_div is signal count : integer range 0 to 3 := 0; signal clk_reg : STD_LOGIC := '0'; begin process(clk_in) begin if rising_edge(clk_in) then if enable = '1' then if count = 4 then count <= 0; clk_reg <= not clk_reg; else count <= count + 1; end if; end if; end if; end process; clk_out <= clk_reg; end Behavioral;
Attempts:
2 left
💡 Hint
Check the range of the count signal and the comparison value.
✗ Incorrect
The count signal is declared with range 0 to 3, but the code compares count to 4, which is outside the declared range. This causes a synthesis error.
📝 Syntax
advancedSyntax error in clock divider process
Which option contains a syntax error in the clock divider process with enable?
VHDL
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity clk_div is Port ( clk_in : in STD_LOGIC; enable : in STD_LOGIC; clk_out : out STD_LOGIC); end clk_div; architecture Behavioral of clk_div is signal count : integer range 0 to 3 := 0; signal clk_reg : STD_LOGIC := '0'; begin process(clk_in) begin if rising_edge(clk_in) then if enable = '1' then if count = 3 then count <= 0; clk_reg <= not clk_reg; else count <= count + 1; end if; end if; end if; end process; clk_out <= clk_reg; end Behavioral;
Attempts:
2 left
💡 Hint
Check the line with multiple sequential assignments inside the if block.
✗ Incorrect
In VHDL, each assignment statement must end with a semicolon. The line 'count <= 0' is missing a semicolon, causing a syntax error.
🚀 Application
expertDesign modification for variable clock division with enable
You want to modify the clock divider to allow dynamic division by a value 'N' (integer input) with enable. Which code snippet correctly implements this behavior?
Attempts:
2 left
💡 Hint
Remember the output clock toggles after counting N input clock cycles, so count should reset at N-1.
✗ Incorrect
The output clock toggles when count reaches N-1, then resets count to 0. Option A correctly uses 'if count = N-1' to toggle clk_reg and reset count. Other options use incorrect comparison values causing wrong division.
