我现在用VHDL编写五人表决器,但是num_agr计数总是不对,请高手指教,程序如下!

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity vote5 is
port(v_in:in std_logic_vector(4 downto 0);
lock,clr:in std_logic;
v_over:out std_logic_vector(2 downto 0);
num_agr,num_opp:out std_logic_vector(3 downto 0);
v_out:out std_logic_vector(4 downto 0);
led_agr,led_opp:out std_logic);
end entity vote5;
architecture one of vote5 is
begin
process(clr,v_in,lock)
variable agr,opp: std_logic_vector(3 downto 0);
begin
if(clr='1')then
led_agr<='0';
led_opp<='0';
agr:="0000";
opp:="0000";
if agr="0000" then

num_agr<="0000";
end if;
if opp="0000"then
num_opp<="0000";
end if;
v_out<="00000";
v_over<="000";
elsif(lock'event and lock='1')then
v_out<=v_in;
v_over<="111";
agr:="0000";
opp:="0000";
for i in 0 to 4 loop
if (v_in(i)<='0') then opp:=opp+1;
end if;
if(v_in(i)<='1')then agr:=agr+1;
end if;

end loop;
num_agr<=agr;
num_opp<=opp;
if(agr>opp)then
led_agr<='1';
led_opp<='0';
else
led_agr<='0';
led_opp<='1';
end if;
end if;

end process;

end architecture one;

第1个回答  2010-11-17
这个for循环错了:
for i in 0 to 4 loop
if (v_in(i)<='0') then opp:=opp+1;
end if;
if(v_in(i)<='1')then agr:=agr+1;
end if;
end loop;
应该为:
for i in 0 to 4 loop
if (v_in(i)='0') then opp:=opp+1;
elsif(v_in(i)='1')then agr:=agr+1;
end if;
end loop;

希望可以帮到你。
第2个回答  2010-11-10
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;

ENTITY FOUR_OUT_FIVE_IN IS
PORT(D0,D1,D2,: IN STD_LOGIC;
OUT1: OUT STD_LOGIC
);
END FOUR_OUT_FIVE_IN;

ARCHITECTURE ART1 OF FOUR_OUT_FIVE_IN IS
SIGNAL INDATA:STD_LOGIC_VECTOR(2 DOWNTO 0);
BEGIN
INDATA<=D2&D1&D0;
IF((INDATA) >= 2)THEN
OUT1='1';
ELSE
OUT1='0';
END ART1;
请参考本回答被网友采纳
相似回答