Challenge - 5 Problems
Prescaler Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of a simple 4-bit prescaler
What is the output frequency division ratio of this prescaler code snippet?
process(clk)
begin
if rising_edge(clk) then
if count = 3 then
count <= 0;
out_clk <= not out_clk;
else
count <= count + 1;
end if;
end if;
end process;VHDL
signal count : integer range 0 to 3 := 0; signal out_clk : std_logic := '0';
Attempts:
2 left
💡 Hint
Count cycles from 0 to 3 and toggle output clock after count resets.
✗ Incorrect
The counter counts from 0 to 3 (4 cycles). The output clock toggles every 4 input clock cycles, so one full output clock period is 8 input clock cycles, dividing frequency by 8.
🧠 Conceptual
intermediateUnderstanding prescaler reset behavior
In a prescaler design, what is the effect of asynchronously resetting the counter to zero on the output clock?
Attempts:
2 left
💡 Hint
Think about what resetting the counter does to the toggle logic.
✗ Incorrect
Resetting the counter to zero restarts the counting cycle, causing the output clock to reset and begin toggling again from the start.
🔧 Debug
advancedIdentify the error in this prescaler code
What error will this VHDL prescaler code cause?
Given that count is declared as
process(clk)
begin
if rising_edge(clk) then
if count = 4 then
count <= 0;
out_clk <= not out_clk;
else
count <= count + 1;
end if;
end if;
end process;Given that count is declared as
integer range 0 to 3.Attempts:
2 left
💡 Hint
Check the maximum value count can hold versus the comparison value.
✗ Incorrect
The code compares count to 4, but count can only go up to 3. Incrementing count from 3 to 4 causes a range overflow error.
📝 Syntax
advancedSyntax error in prescaler process
Which option contains the correct syntax for a prescaler process that toggles output clock every 5 input clock cycles?
Attempts:
2 left
💡 Hint
Remember VHDL uses '<=' for signal assignment and '=' for comparison.
✗ Incorrect
Option A uses correct comparison operator '=' and signal assignment '<=' with valid count value 4 for 5 cycles (0 to 4). Option A compares to 5 which is out of range if count declared 0 to 4. Option A uses ':=' which is for variables, not signals. Option A uses '==' which is invalid in VHDL.
🚀 Application
expertCalculate output frequency of a prescaler with variable division
Given a 50 MHz input clock and this prescaler code snippet:
What is the output clock frequency in MHz?
constant DIVIDE_BY : integer := 8;
signal count : integer range 0 to DIVIDE_BY := 0;
signal out_clk : std_logic := '0';
process(clk)
begin
if rising_edge(clk) then
if count = DIVIDE_BY then
count <= 0;
out_clk <= not out_clk;
else
count <= count + 1;
end if;
end if;
end process;What is the output clock frequency in MHz?
Attempts:
2 left
💡 Hint
Output toggles every DIVIDE_BY+1 input cycles, so full period is twice that.
✗ Incorrect
The counter counts from 0 to 8 (9 cycles). The output clock toggles every 9 input clock cycles, so one full output clock period is 18 input clock cycles. Frequency = 50 MHz / 18 ≈ 2.777 MHz.
