2017-07-18 4 views
0

整数信号を追加して、それをセグメント上でデコードしようとするときに問題があります。ところで、私たちのプロジェクトは、1つのスイッチがクリックされたときにインクリメントされた値を表示しようとしています。 3つのスイッチ(swA、swB、swC)があります。 switchAをクリックすると最初は3つのセグメントすべてが0,0,0 です。表示されるのは= 1,0,0 です。 switchCをクリックすると、1,0,2,と表示されます。 あなたがスイッチBをクリックすると、それが表示されます= 1,3,2 その後、..あなたはswitchCをクリックした場合、それが表示されます =VHDLでの整数問題の追加Spartan 3

1,3,4ので、アルゴリズムは、そのようになります。私の問題は追加部分です。私のデコーダコードは正常ですが、クリック、ジャンプ+4、+2、+8のシーケンスです。私の問題は私の追加アルゴリズムにあると思います。あるいは、おそらく私の周波数区分上にあるかもしれません。

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_ARITH.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 



entity SwitchCounterModule is 
    port(SegmentIndicator: inout STD_LOGIC_VECTOR(6 downto 0); 
      SegmentA : inout STD_LOGIC_VECTOR(6 downto 0); 
      SegmentB : inout STD_LOGIC_VECTOR(6 downto 0); 
      SegmentC : inout STD_LOGIC_VECTOR(6 downto 0); 
      SwitchA : in STD_LOGIC; 
      SwitchB : in STD_LOGIC; 
      SwitchC : in STD_LOGIC); 
end SwitchCounterModule; 

architecture Behavioral of SwitchCounterModule is 
signal counter :std_logic_vector(3 downto 0); 

signal sumOut1: integer; 





begin 
process(sumOut1) 
begin 

     sumOut1<=5; 
     if SwitchA = '1' then 
     SegmentIndicator <= "0001000"; --A 

      sumOut1 <= sumOut1 +1; 


      if(sumOut1>9)then 
      sumOut1<= 0; 


      case sumOut1 is 
      when 0 => SegmentA <="1000000"; -- '0' 
      when 1 => SegmentA <="1111001"; -- '1' 
      when 2 => SegmentA <="0100100"; -- '2' 
      when 3 => SegmentA <="0110000"; -- '3' 
      when 4 => SegmentA <="0011001"; -- '4' 
      when 5 => SegmentA <="0010010"; -- '5' 
      when 6 => SegmentA <="0000010"; -- '6' 
      when 7 => SegmentA <="1111000"; -- '7' 
      when 8 => SegmentA <="0000000"; -- '8' 
      when others => SegmentA <="0010000"; -- '9' 
      end case; 

      else       
      case sumOut1 is 
      when 0 => SegmentA <="1000000"; -- '0' 
      when 1 => SegmentA <="1111001"; -- '1' 
      when 2 => SegmentA <="0100100"; -- '2' 
      when 3 => SegmentA <="0110000"; -- '3' 
      when 4 => SegmentA <="0011001"; -- '4' 
      when 5 => SegmentA <="0010010"; -- '5' 
      when 6 => SegmentA <="0000010"; -- '6' 
      when 7 => SegmentA <="1111000"; -- '7' 
      when 8 => SegmentA <="0000000"; -- '8' 
      when others => SegmentA <="0010000"; -- '9' 
      end case; 
      end if; 



     elsif SwitchB = '1' then 
      SegmentIndicator <= "0000011"; --B 

      sumOut1 <= sumOut1 +1; 


      if(sumOut1=10)then 
      sumOut1<= 0; 
      case sumOut1 is 
      when 0 => SegmentB <="1000000"; -- '0' 
      when 1 => SegmentB <="1111001"; -- '1' 
      when 2 => SegmentB <="0100100"; -- '2' 
      when 3 => SegmentB <="0110000"; -- '3' 
      when 4 => SegmentB <="0011001"; -- '4' 
      when 5 => SegmentB <="0010010"; -- '5' 
      when 6 => SegmentB <="0000010"; -- '6' 
      when 7 => SegmentB <="1111000"; -- '7' 
      when 8 => SegmentB <="0000000"; -- '8' 
      when others => SegmentB <="0010000"; -- '9' 
      end case; 

      else  
      case sumOut1 is 
      when 0 => SegmentB <="1000000"; -- '0' 
      when 1 => SegmentB <="1111001"; -- '1' 
      when 2 => SegmentB <="0100100"; -- '2' 
      when 3 => SegmentB <="0110000"; -- '3' 
      when 4 => SegmentB <="0011001"; -- '4' 
      when 5 => SegmentB <="0010010"; -- '5' 
      when 6 => SegmentB <="0000010"; -- '6' 
      when 7 => SegmentB <="1111000"; -- '7' 
      when 8 => SegmentB <="0000000"; -- '8' 
      when others => SegmentB <="0010000"; -- '9' 
      end case; 
      end if; 



     elsif SwitchC = '1' then 

      SegmentIndicator <= "1000110"; --C 

      sumOut1 <= sumOut1 +1; 


      if(sumOut1=10)then 
      sumOut1<= 0; 
      case sumOut1 is 
      when 0 => SegmentC <="1000000"; -- '0' 
      when 1 => SegmentC <="1111001"; -- '1' 
      when 2 => SegmentC <="0100100"; -- '2' 
      when 3 => SegmentC <="0110000"; -- '3' 
      when 4 => SegmentC <="0011001"; -- '4' 
      when 5 => SegmentC <="0010010"; -- '5' 
      when 6 => SegmentC <="0000010"; -- '6' 
      when 7 => SegmentC <="1111000"; -- '7' 
      when 8 => SegmentC <="0000000"; -- '8' 
      when others => SegmentC <="0010000"; -- '9' 
      end case; 

      else 

      case sumOut1 is 
      when 0 => SegmentC <="1000000"; -- '0' 
      when 1 => SegmentC <="1111001"; -- '1' 
      when 2 => SegmentC <="0100100"; -- '2' 
      when 3 => SegmentC <="0110000"; -- '3' 
      when 4 => SegmentC <="0011001"; -- '4' 
      when 5 => SegmentC <="0010010"; -- '5' 
      when 6 => SegmentC <="0000010"; -- '6' 
      when 7 => SegmentC <="1111000"; -- '7' 
      when 8 => SegmentC <="0000000"; -- '8' 
      when others => SegmentC <="0010000"; -- '9' 
      end case; 
      end if; 

     else 
      sumOut1<=sumOut1; 
      SegmentA<=SegmentA; 
      SegmentB<=SegmentB; 
      SegmentC<=SegmentC; 

     end if; 

     end process; 
end Behavioral; 
+3

あなたのプロセスは 'sumOut1'に敏感です。したがって、「sumOut1」は入力である。しかし、このプロセスは 'sumOut1'も変更します。これもまた出力です。コンビナトリアルループを作成しました。さらに、感度リストは不完全であり、スイッチも入力である。どんな種類のクロックもないので、レジスタはありません。あなたの回路は、スイッチ上の2つの動作の間に現在の値をどのように保存すると思いますか?おそらく、ソフトウェアエンジニアとしての考えを止め、必要なハードウェアをまず決定するべきです(VHDLはなく、紙と鉛筆だけです)。コーディングは次に来る。 –

+1

私は、合成ツールが実際にある種の実装を行ったことに感心しています。この記述はFPGAにマッピングするのが難しいためです。クロック同期ロジックを実装する必要があります。シンクロナイザーとデバウンスロジックを外部スイッチで使用することを忘れないでください。 – JHBonarius

+1

'ieee.std_logic_arith'と' ieee.std_logic_unsigned'の代わりに 'ieee.numeric_std'を使うべきです。後者は実際には標準ではありません。 – mkrieger1

答えて

1

デザインに間違いがあり、修正しました。私は個々の増分が一度にすべてであるようにあなたの正確な要件を理解していませんでした。どのように私はカウンタの問題を理解し、私はそれを修正した。あなたは、個々のテイクsumout1sumout2、各スイッチのsumout3をしたい場合 コードが

`library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_ARITH.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 



entity SwitchCounterModule is 
    port(SegmentIndicator: out STD_LOGIC_VECTOR(6 downto 0); 
      SegmentA : out STD_LOGIC_VECTOR(6 downto 0); 
      SegmentB : out STD_LOGIC_VECTOR(6 downto 0); 
      SegmentC : out STD_LOGIC_VECTOR(6 downto 0); 
      SwitchA : in STD_LOGIC; 
      SwitchB : in STD_LOGIC; 
      SwitchC : in STD_LOGIC; 
      clk : in STD_LOGIC; 
      rst : in STD_LOGIC); 
end SwitchCounterModule; 

architecture Behavioral of SwitchCounterModule is 
signal counter :std_logic_vector(3 downto 0); 

signal sumOut1: std_logic_vector(3 downto 0); 

begin 
process(SwitchA,SwitchB,sumOut1,SwitchC,clk,rst) 
begin 
if rst = '1' then 
     sumOut1 <= "0000"; 
     SegmentA <= "0000000"; 
     SegmentB <= "0000000"; 
     SegmentC <= "0000000"; 
     SegmentIndicator <= "1111111"; 

    elsif (clk='1' and clk'event) then 

     --sumOut1 <= "00000" ; --sumOut1 assigned with 5 
     if SwitchA = '1' then -- when pressing SwitchA 

       SegmentIndicator <= "0001000"; --A indicating a 
      sumOut1 <= sumOut1 +1; --integer increased to next value 

      if(sumOut1>9)then -- the integer value is greater than 9 then sumout1 =0 
        sumOut1<= "0000"; 

      else       
      case sumOut1 is 
      when "0000" => SegmentA <="1000000"; -- '0' 
      when "0001"=> SegmentA <="1111001"; -- '1' 
      when "0010" => SegmentA <="0100100"; -- '2' 
      when "0011"=> SegmentA <="0110000"; -- '3' 
      when "0100" => SegmentA <="0011001"; -- '4' 
      when "0101" => SegmentA <="0010010"; -- '5' 
      when "0110" => SegmentA <="0000010"; -- '6' 
      when "0111" => SegmentA <="1111000"; -- '7' 
      when "1000" => SegmentA <="0000000"; -- '8' 
      when "1001" => SegmentA <="0010000"; -- '9' 
       when others => SegmentA <="1111111"; -- '9' 
      end case; 
      end if; 



     elsif SwitchB = '1' then 
      SegmentIndicator <= "0000011"; --B 

      sumOut1 <= sumOut1 +1; 


      if(sumOut1=10)then 
      sumOut1<= "0000"; 


      else  
      case sumOut1 is 
      when "0000" => SegmentA <="1000000"; -- '0' 
      when "0001"=> SegmentA <="1111001"; -- '1' 
      when "0010" => SegmentA <="0100100"; -- '2' 
      when "0011"=> SegmentA <="0110000"; -- '3' 
      when "0100" => SegmentA <="0011001"; -- '4' 
      when "0101" => SegmentA <="0010010"; -- '5' 
      when "0110" => SegmentA <="0000010"; -- '6' 
      when "0111" => SegmentA <="1111000"; -- '7' 
      when "1000" => SegmentA <="0000000"; -- '8' 
      when "1001" => SegmentA <="0010000"; -- '9' 
       when others => SegmentA <="1111111"; -- '9' 
      end case; 
      end if; 



     elsif SwitchC = '1' then 

      SegmentIndicator <= "1000110"; --C 

      sumOut1 <= sumOut1 +1; 


      if(sumOut1=10)then 
      sumOut1<= "0000"; 


      else 

      case sumOut1 is 
      when "0000" => SegmentA <="1000000"; -- '0' 
      when "0001"=> SegmentA <="1111001"; -- '1' 
      when "0010" => SegmentA <="0100100"; -- '2' 
      when "0011"=> SegmentA <="0110000"; -- '3' 
      when "0100" => SegmentA <="0011001"; -- '4' 
      when "0101" => SegmentA <="0010010"; -- '5' 
      when "0110" => SegmentA <="0000010"; -- '6' 
      when "0111" => SegmentA <="1111000"; -- '7' 
      when "1000" => SegmentA <="0000000"; -- '8' 
      when "1001" => SegmentA <="0010000"; -- '9' 
       when others => SegmentA <="1111111"; -- '9' 
      end case; 
      end if; 

     else 
      sumOut1<=sumOut1; 


     end if; 
end if; 
     end process; 
end Behavioral; 
` 

です。