用vhdl语言写一个加减计数器
我想设计一个拔河游戏机,需要一个加减计数器。player1in和player2in,分别是控制加和减,但是在同一个process里不能对count分别赋值,请各位网友帮帮...
我想设计一个拔河游戏机,需要一个加减计数器。player1in和player2in,分别是控制加和减,但是在同一个process里不能对count分别赋值,请各位网友帮帮忙
展开
1个回答
展开全部
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY add_sub_counter IS
PORT ( clk,player1_in,player2_in : IN STD_LOGIC;
counter : OUT STD_LOGIC_VECTOR (7 DOWNTO 0));
END;
ARCHITECTURE behaviour OF add_sub_counter IS
SIGNAL q : STD_LOGIC_VECTOR (7 DOWNTO 0);
BEGIN
PROCESS(clk,player1_in,player2_in)
VARIABLE player : STD_LOGIC_VECTOR (1 DOWNTO 0);
BEGIN
player := player1_in&player2_in;
IF rising_edge(clk) THEN
CASE player IS
WHEN "10" => q <= q+1;
WHEN "01" => q <= q-1;
WHEN OTHERS => NULL;
END CASE;
END IF;
END PROCESS;
counter <= q ;
END;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY add_sub_counter IS
PORT ( clk,player1_in,player2_in : IN STD_LOGIC;
counter : OUT STD_LOGIC_VECTOR (7 DOWNTO 0));
END;
ARCHITECTURE behaviour OF add_sub_counter IS
SIGNAL q : STD_LOGIC_VECTOR (7 DOWNTO 0);
BEGIN
PROCESS(clk,player1_in,player2_in)
VARIABLE player : STD_LOGIC_VECTOR (1 DOWNTO 0);
BEGIN
player := player1_in&player2_in;
IF rising_edge(clk) THEN
CASE player IS
WHEN "10" => q <= q+1;
WHEN "01" => q <= q-1;
WHEN OTHERS => NULL;
END CASE;
END IF;
END PROCESS;
counter <= q ;
END;
更多追问追答
追问
你好,拔河的话应该不需要另外的clk输入了,只需要player1in 以及player2in 的脉冲输入就行了
追答
如果没有clk信号,VHDL是很难在一个进程中判断player1in和player2in的有效边沿的。
这时通常需要3个进程才能判断计数器该如何加减:用2个进程分别检测player1in和player2in的有效边沿,并分别输出各自的单脉冲信号,然后用另一个进程判断该如何对计数器进行加减操作。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询