Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is probably a very large number of ways to solve this, but without changing your code, much, here is one (note, not fully tested).</p> <ul> <li>Give each state a count output that depends on the clock rate.</li> <li>Establish a counter register big enough to hold the largest count.</li> <li>Decrement the count on each clock, reload it when it's zero.</li> <li>The reload value comes from the new state.</li> <li>Switch states on the last count before zero.</li> </ul> <h2> </h2> <pre><code>library IEEE; use IEEE.STD_LOGIC_1164.ALL; ENTITY programa IS PORT ( interrup : in Std_Logic_Vector (7 downto 0); clk, rst: in Std_Logic; led : out Std_Logic_Vector (2 downto 0) ); END programa; ARCHITECTURE arch_programa OF programa IS type state is (zero, one, two, three, four, five, six); signal pr_state, nx_state : state; signal A : Std_Logic_Vector (3 downto 0); signal count,pr_count:integer; --NOTE: Synthisizing integers is very unpredictable, should use unsigned BEGIN assign_counts:process(pr_state) begin --no idea what states need what delay, this is just an example case pr_state is when zero | one | two =&gt; pr_count&lt;=10; when four =&gt; pr_count&lt;=20; when others =&gt; pr_count&lt;=50; end case; end process; process(interrup, pr_state) begin case pr_state is when zero =&gt; led &lt;= "100"; A(0) &lt;= interrup(7); nx_state &lt;= one; when one =&gt; led &lt;= "100"; A(1) &lt;= interrup(6); nx_state &lt;= two; when two =&gt; led &lt;= "100"; A(2) &lt;= interrup(5); nx_state &lt;= three; when three =&gt; led &lt;= "100"; A(3) &lt;= interrup(3); nx_state &lt;= four; when four =&gt; led &lt;= "100"; if(A = "1111") then nx_state &lt;= five; else nx_state &lt;= six; end if; when five =&gt; led &lt;= "010"; nx_state &lt;=zero; when six =&gt; led &lt;= "001"; nx_state &lt;=zero; end case; end process; process(rst,clk) begin if(rst='1') then pr_state &lt;= zero; count&lt;=pr_count; elsif (clk'event and clk = '1') then if count=0 then count&lt;=pr_count; elsif count=1 then pr_state &lt;= nx_state; count&lt;=count-1; else count&lt;=count-1; end if; end if; end process; end architecture; --Test bench library IEEE; use IEEE.STD_LOGIC_1164.all; entity bench is end bench; architecture bench of bench is component programa IS PORT ( interrup : in Std_Logic_Vector (7 downto 0); clk, rst: in Std_Logic; led : out Std_Logic_Vector (2 downto 0)); END component; signal clk:std_logic:='1'; signal interrup:std_logic_vector (7 downto 0); signal rst:std_logic; constant freq:real:=1.0e6; begin do_reset:process begin rst&lt;='1'; wait for 10 us; rst&lt;='0'; wait; end process; clk&lt;=not clk after 0.5 sec / freq; UUT:programa port map ( interrup =&gt; interrup, clk =&gt; clk, rst =&gt; rst); end architecture; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload