本帖最后由 izefei 于 2011-5-23 11:32 编辑
我的代码目的是:data数组用来存储常数数据;sgn数组用来存储data数组中数据的符号,正数的话为1,负数的话为-1。可是仿真输出的sgn波形老是不对(我个人怀疑问题应该出在数组的使用上,可又找不到到底是哪儿的错),求各位过路大侠指点迷津。代码如下:entity decode is
port (
rst:in std_logic;
clk:in std_logic;
data_port: out std_logic_vector(3 downto 0);
sgn_port: out std_logic_vector(2 downto 0)
);
end decode;
architecture Behavioral of decode is
type Data_type is array (0 to 5) of integer range -10 to 10;
type sgn_type is array (0 to 5) of integer range -1 to 1;
constant Data: Data_type:=(5,-5,4,3,-2,-4);
signal sgn:sgn_type;
signal count:integer range 0 to 6;
begin
--------------------------------------------------------------------------
process(rst,clk)
begin
if(rst='0')then
count<=0;
elsif(rising_edge(clk))then
case count is
when 0 to 4 =>count<=count+1;
when others=>null;
end case;
end if;
end process;
--------------------------------------------------------------------------
process(clk)
begin
if(rising_edge(clk))then
case count is
when 0 to 5 =>
data_port<=conv_std_logic_vector(data(count),4);
if data(count)>0 then
sgn(count)<=1;
else
sgn(count)<=-1;
end if;
when others=>null;
end case;
end if;
end process;
sgn_port<=conv_std_logic_Vector(sgn(count),3);
end Behavioral;
仿真波形见图: |