0

Quartus II でプロジェクトを作成したいと考えています。その機能は、コードに応じて 3 つの異なる LED を有効にすることです。コードを入力すると、最初の LED がオンになります。入力したコードに応じて、2 番目または 3 番目がオンになります。私の問題は、コードが正しい場合、2 番目の LED を 3 秒間オンにし、正しくない場合は 3 番目の LED を 2 秒間オンにすることです。助けていただければ幸いです。

ありがとうございました!

注: LED は Logic Vector として宣言され、コードの番号は 0 から 7 までの割り込みとして宣言されます。

コード:

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);
BEGIN
    process(interrup, pr_state)
    begin
        case pr_state is
            when zero =>
                led <= "100";
                A(0) <= interrup(7);
                nx_state <= one;
            when one =>
                led <= "100";
                A(1) <= interrup(6);
                nx_state <= two;
            when two =>
                led <= "100";
                A(2) <= interrup(5);
                nx_state <= three;
            when three =>
                led <= "100";
                A(3) <= interrup(3);
                nx_state <= four;
            when four =>
                led <= "100";
                if(A = "1111") then nx_state <= five;
                else nx_state <= six;
                end if;
            when five =>
                led <= "010";
                nx_state <=zero;
            when six =>
                led <= "001";
                nx_state <=zero;
            end case;
    end process;

    process(rst,clk)
    begin
        if(rst='1') then
            pr_state <= zero;
        elsif (clk'event and clk = '1') then
            pr_state <= nx_state;
        end if;         
    end process;

end arch_programa;
4

2 に答える 2

1

最初の質問については、3 秒または 2 秒分のクロック パルスをカウントする必要があるため、クロック周波数を知る必要があります。たとえば、LED をオンにするとカウンターを開始し、正しいパルス数をカウントしたら LED とカウンターをオフにします。多くの場合、その値からカウントダウンし、カウンターがゼロに達したときに停止する方が簡単です。

2 つ目については、プロセスの 1 つへの入力として使用できる入力ポートを介してボタンを接続する必要があります。

于 2012-11-15T19:43:29.183 に答える
0

これを解決する方法はおそらく非常に多数ありますが、コードを変更せずに、ここにその 1 つを示します (完全にテストされていないことに注意してください)。

  • 各状態に、クロック レートに依存するカウント出力を与えます。
  • 最大カウントを保持するのに十分な大きさのカウンター レジスタを確立します。
  • クロックごとにカウントを減らし、ゼロになったらリロードします。
  • リロード値は、新しい状態から取得されます。
  • ゼロより前の最後のカウントで状態を切り替えます。

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 => 
                  pr_count<=10;
             when four =>
                  pr_count<=20;
             when others =>
                  pr_count<=50;
         end case;
    end process;

    process(interrup, pr_state)
    begin
        case pr_state is
            when zero =>
                led <= "100";
                A(0) <= interrup(7);
                nx_state <= one;
            when one =>
                led <= "100";
                A(1) <= interrup(6);
                nx_state <= two;
            when two =>
                led <= "100";
                A(2) <= interrup(5);
                nx_state <= three;
            when three =>
                led <= "100";
                A(3) <= interrup(3);
                nx_state <= four;
            when four =>
                led <= "100";
                if(A = "1111") then nx_state <= five;
                else nx_state <= six;
                end if;
            when five =>
                led <= "010";
                nx_state <=zero;
            when six =>
                led <= "001";
                nx_state <=zero;
            end case;
    end process;

    process(rst,clk)
    begin
        if(rst='1') then
            pr_state <= zero;
            count<=pr_count;
        elsif (clk'event and clk = '1') then
            if count=0 then
                count<=pr_count;
            elsif count=1 then
                pr_state <= nx_state;
                count<=count-1;
            else
                count<=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<='1';
        wait for 10 us;
        rst<='0';
        wait;
    end process;

    clk<=not clk after 0.5 sec / freq;

    UUT:programa port map (
      interrup => interrup,
      clk => clk,
      rst => rst);


end architecture;
于 2012-11-16T13:53:41.963 に答える