Skip to content
Snippets Groups Projects
Commit 82fef94c authored by Eric Kooistra's avatar Eric Kooistra
Browse files

Register inputs locally at this input to ease timing closure in case there are...

Register inputs locally at this input to ease timing closure in case there are multiple common_led_controller all using the same central source
parent dfcf97ce
No related branches found
No related tags found
No related merge requests found
...@@ -29,9 +29,11 @@ USE common_lib.common_pkg.ALL; ...@@ -29,9 +29,11 @@ USE common_lib.common_pkg.ALL;
-- ctrl_on = '0' : then led = ctrl_input, so completely driven by external control -- ctrl_on = '0' : then led = ctrl_input, so completely driven by external control
-- ctrl_on = '1' : then led = '1' but pulses '0' for g_nof_ms each time that a ctrl_evt clk pulse occurs -- ctrl_on = '1' : then led = '1' but pulses '0' for g_nof_ms each time that a ctrl_evt clk pulse occurs
-- Remark: -- Remark:
-- The p_state machine ensures that after g_nof_ms off the led also stays on for at least g_nof_ms, to -- The p_state machine ensures that after g_nof_ms off the led also stays on
-- avoid that a too fast ctrl_evt rate would cause the led too stay off. Hence the led can only accurately -- for at least g_nof_ms, to avoid that a too fast ctrl_evt rate would cause
-- visualize a certain ctrl_evt rate, faster events will get lost. -- the led too stay off. Therefore the maximum event rate that can be
-- signalled is 1/(2*g_nof_ms). If events occur faster then these can not be
-- visualized exactly anymore and will get lost.
ENTITY common_led_controller IS ENTITY common_led_controller IS
GENERIC ( GENERIC (
...@@ -40,7 +42,7 @@ ENTITY common_led_controller IS ...@@ -40,7 +42,7 @@ ENTITY common_led_controller IS
PORT ( PORT (
rst : IN STD_LOGIC; rst : IN STD_LOGIC;
clk : IN STD_LOGIC; clk : IN STD_LOGIC;
pulse_ms : IN STD_LOGIC; -- pulses every ms pulse_ms : IN STD_LOGIC := '0'; -- pulses every ms, used to time the ctrl_evt effect on the led
-- led control -- led control
ctrl_on : IN STD_LOGIC := '0'; ctrl_on : IN STD_LOGIC := '0';
ctrl_evt : IN STD_LOGIC := '0'; -- when ctrl_on='1' then the led output is on and pulses off for g_nof_ms when a ctrl_evt='1' event pulse occurs ctrl_evt : IN STD_LOGIC := '0'; -- when ctrl_on='1' then the led output is on and pulses off for g_nof_ms when a ctrl_evt='1' event pulse occurs
...@@ -58,6 +60,10 @@ ARCHITECTURE rtl OF common_led_controller IS ...@@ -58,6 +60,10 @@ ARCHITECTURE rtl OF common_led_controller IS
SIGNAL state : t_state; SIGNAL state : t_state;
SIGNAL nxt_state : t_state; SIGNAL nxt_state : t_state;
-- Register inputs locally at this input to ease timing closure in case there are multiple common_led_controller all using the same central source
SIGNAL pulse_ms_reg : STD_LOGIC;
SIGNAL ctrl_input_reg : STD_LOGIC;
SIGNAL cnt : NATURAL RANGE 0 TO g_nof_ms; SIGNAL cnt : NATURAL RANGE 0 TO g_nof_ms;
SIGNAL nxt_cnt : NATURAL; SIGNAL nxt_cnt : NATURAL;
...@@ -68,23 +74,27 @@ BEGIN ...@@ -68,23 +74,27 @@ BEGIN
p_clk : PROCESS(rst, clk) p_clk : PROCESS(rst, clk)
BEGIN BEGIN
IF rst='1' THEN IF rst='1' THEN
pulse_ms_reg <= '0';
ctrl_input_reg <= '0';
cnt <= 0; cnt <= 0;
state <= s_idle; state <= s_idle;
led <= '0'; led <= '0';
ELSIF rising_edge(clk) THEN ELSIF rising_edge(clk) THEN
pulse_ms_reg <= pulse_ms;
ctrl_input_reg <= ctrl_input;
cnt <= nxt_cnt; cnt <= nxt_cnt;
state <= nxt_state; state <= nxt_state;
led <= nxt_led; led <= nxt_led;
END IF; END IF;
END PROCESS; END PROCESS;
p_state : PROCESS(state, ctrl_on, ctrl_evt, ctrl_input, pulse_ms, cnt) p_state : PROCESS(state, ctrl_on, ctrl_evt, ctrl_input_reg, pulse_ms_reg, cnt)
BEGIN BEGIN
IF ctrl_on='0' THEN IF ctrl_on='0' THEN
-- Default behaviour when ctrl_on = '0' -- Default behaviour when ctrl_on = '0'
nxt_cnt <= 0; nxt_cnt <= 0;
nxt_state <= s_idle; nxt_state <= s_idle;
nxt_led <= ctrl_input; nxt_led <= ctrl_input_reg;
ELSE ELSE
-- Pulse led off briefly on event when ctrl_on = '1' -- Pulse led off briefly on event when ctrl_on = '1'
nxt_cnt <= cnt; nxt_cnt <= cnt;
...@@ -98,7 +108,7 @@ BEGIN ...@@ -98,7 +108,7 @@ BEGIN
END IF; END IF;
WHEN s_off => WHEN s_off =>
nxt_led <= '0'; nxt_led <= '0';
IF pulse_ms='1' THEN IF pulse_ms_reg='1' THEN
nxt_cnt <= cnt+1; nxt_cnt <= cnt+1;
IF cnt=g_nof_ms THEN IF cnt=g_nof_ms THEN
nxt_cnt <= 0; nxt_cnt <= 0;
...@@ -106,7 +116,7 @@ BEGIN ...@@ -106,7 +116,7 @@ BEGIN
END IF; END IF;
END IF; END IF;
WHEN OTHERS => -- s_on WHEN OTHERS => -- s_on
IF pulse_ms='1' THEN IF pulse_ms_reg='1' THEN
nxt_cnt <= cnt+1; nxt_cnt <= cnt+1;
IF cnt=g_nof_ms THEN IF cnt=g_nof_ms THEN
nxt_cnt <= 0; nxt_cnt <= 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment