A watchdog timer helps a digital system check if it is working properly. If the system stops responding, the watchdog timer resets it to fix the problem.
Watchdog timer design in VHDL
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity watchdog_timer is port( clk : in std_logic; reset_n : in std_logic; kick : in std_logic; -- signal to reset the timer timeout : out std_logic -- signal goes high on timeout ); end watchdog_timer; architecture Behavioral of watchdog_timer is constant TIMEOUT_LIMIT : integer := 1000000; -- example count limit signal counter : integer := 0; begin process(clk, reset_n) begin if reset_n = '0' then counter <= 0; timeout <= '0'; elsif rising_edge(clk) then if kick = '1' then counter <= 0; -- reset counter when kicked timeout <= '0'; else if counter < TIMEOUT_LIMIT then counter <= counter + 1; timeout <= '0'; else timeout <= '1'; -- timeout reached end if; end if; end if; end process; end Behavioral;
The kick input resets the timer counter to prevent timeout.
The timeout output signals when the timer reaches the limit without being reset.
kick signal high.kick <= '1'; -- reset the watchdog timer counterif timeout = '1' then -- perform system reset or error handling end if;
This program defines a simple watchdog timer with a small timeout limit for demonstration. The testbench resets the system, kicks the watchdog once, then stops kicking to let the timeout signal go high.
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity watchdog_timer is port( clk : in std_logic; reset_n : in std_logic; kick : in std_logic; timeout : out std_logic ); end watchdog_timer; architecture Behavioral of watchdog_timer is constant TIMEOUT_LIMIT : integer := 10; -- small limit for demo signal counter : integer := 0; begin process(clk, reset_n) begin if reset_n = '0' then counter <= 0; timeout <= '0'; elsif rising_edge(clk) then if kick = '1' then counter <= 0; timeout <= '0'; else if counter < TIMEOUT_LIMIT then counter <= counter + 1; timeout <= '0'; else timeout <= '1'; end if; end if; end if; end process; end Behavioral; -- Testbench to simulate watchdog timer library ieee; use ieee.std_logic_1164.all; entity tb_watchdog is end tb_watchdog; architecture test of tb_watchdog is signal clk : std_logic := '0'; signal reset_n : std_logic := '0'; signal kick : std_logic := '0'; signal timeout : std_logic; component watchdog_timer port( clk : in std_logic; reset_n : in std_logic; kick : in std_logic; timeout : out std_logic ); end component; begin uut: watchdog_timer port map(clk, reset_n, kick, timeout); clk_process : process begin while true loop clk <= '0'; wait for 10 ns; clk <= '1'; wait for 10 ns; end loop; end process; stim_proc: process begin reset_n <= '0'; wait for 25 ns; reset_n <= '1'; -- Kick the watchdog at first kick <= '1'; wait for 20 ns; kick <= '0'; -- Do not kick, let timeout happen wait for 250 ns; wait; end process; end test;
Make sure the kick signal is sent regularly to prevent unwanted resets.
The timeout limit depends on your system clock speed and how long you want to wait before resetting.
A watchdog timer helps detect system freezes by counting time without a reset signal.
Use a kick signal to reset the timer counter regularly.
When the timer reaches its limit, it signals a timeout to trigger a system reset or error handling.
Practice
watchdog timer in a VHDL design?Solution
Step 1: Understand the watchdog timer role
A watchdog timer monitors system activity to detect failures.Step 2: Identify the correct function
It triggers a reset if the system stops responding to prevent lockup.Final Answer:
To detect system failures and trigger a reset if the system stops responding -> Option DQuick Check:
Watchdog timer = system failure detection [OK]
- Confusing watchdog timer with clock generator
- Thinking it stores data
- Assuming it generates random numbers
Solution
Step 1: Identify correct vector size and direction
A 16-bit vector uses indices 15 downto 0 for standard logic vectors.Step 2: Check each option
signal counter : std_logic_vector(15 downto 0); uses std_logic_vector(15 downto 0), which is correct for 16 bits.Final Answer:
signal counter : std_logic_vector(15 downto 0); -> Option AQuick Check:
16-bit vector = (15 downto 0) [OK]
- Using integer range 0 to 15 instead of vector
- Using ascending range (0 to 15) incorrectly
- Using bit_vector instead of std_logic_vector
process(clk)
begin
if rising_edge(clk) then
if kick = '1' then
counter <= (others => '0');
else
counter <= counter + 1;
end if;
end if;
end process;What happens to
counter when kick is '1'?Solution
Step 1: Analyze the condition when kick = '1'
The code sets counter to (others => '0'), which means all bits zero.Step 2: Understand the effect on counter
Counter resets to zero instead of incrementing.Final Answer:
Counter resets to zero -> Option AQuick Check:
kick '1' resets counter = zero [OK]
- Assuming counter increments on kick
- Thinking counter holds value on kick
- Confusing reset value with all ones
process(clk)
begin
if rising_edge(clk) then
if kick = '1' then
counter <= 0;
else
counter <= counter + 1;
end if;
end if;
end process;Solution
Step 1: Check signal type and assignment
Counter is usually std_logic_vector; assigning integer 0 directly is invalid.Step 2: Identify correct assignment method
Must assign (others => '0') or convert integer to vector properly.Final Answer:
Assigning integer 0 to a std_logic_vector signal -> Option BQuick Check:
std_logic_vector needs vector assignment, not integer [OK]
- Assigning integer directly to vector
- Ignoring reset conditions
- Misusing clock edge detection
timeout signal when the counter reaches 1000 without a kick. Which approach correctly implements this behavior?Solution
Step 1: Understand watchdog timer logic
Counter increments every clock cycle unless reset by kick signal.Step 2: Identify correct timeout condition
Timeout triggers when counter reaches 1000 without reset.Step 3: Evaluate options
Increment counter each clock cycle; reset to zero on kick; set timeout when counter = 1000 matches correct logic: increment, reset on kick, timeout at 1000.Final Answer:
Increment counter each clock cycle; reset to zero on kick; set timeout when counter = 1000 -> Option CQuick Check:
Watchdog counts up, resets on kick, timeout at limit [OK]
- Incrementing only on kick
- Setting timeout every cycle
- Resetting counter incorrectly
Ready to prove it?
Pass the test and this pattern moves unknown
