key :
alwaysを用いた記述
一応あれでも動くのだけれど、最終的な出力を見る際には、信号を1つ1つ追ってみなければ分かり辛い所がある。
作っている最中はいいかもしれないけど、時間を置いてから見たり他人が見たりした際には動作を把握するまでにちょっくら時間がかかる。
そこで、先ほどの記述を更に簡単に
・簡単な記述
library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity cnt_10 is port( clock : in std_logic; reset : in std_logic; cnt_en : in std_logic; data_set : in std_logic; data : in std_logic_vector (3 downto 0); Q : out std_logic_vector (3 downto 0) ); end cnt_10; architecture RTL of cnt_10 is signal Q_reg : std_logic_vector (3 downto 0); begin Q <= q_reg; process (clock , reset) begin if (reset = '0') then Q_reg <= "0000" ; elsif (clock'event and clock = '1' ) then if (cnt_en = '1' and Q_reg = "1001") then Q_reg <= "0000" ; elsif (data_set = '1') then q_reg <= data ; elsif (cnt_en = '1') then Q_reg <= Q_reg + "0001" ; else Q_reg <= Q_reg ; end if; else q_reg <= q_reg ; end if; end process; end RTL; |
先ほどの記述より、どの信号が入ったさいにどのような動作を行うかがはっきりと分かる。 //else if ((Q[3] & Q[0] == 1) && (cnt_en == 1)) else if ((Q == 4'h9) && (cnt_en == 1)) はどちらも同じ動作だが、コメントアウトしてない下の記述の方がより分かりやすい。 今後、回路を記述する際、メインはこの記述方法になる。 |
次回はテストベンチ。