一个小小的程序问题(在线等),急!

[复制链接]
2040|4
 楼主| izefei 发表于 2011-5-23 11:25 | 显示全部楼层 |阅读模式
ST, ge, AN, TE, ic
本帖最后由 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;
仿真波形见图:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
AutoESL 发表于 2011-5-23 13:16 | 显示全部楼层
AutoESL 发表于 2011-5-23 14:21 | 显示全部楼层
问题应该count那里,和sgn数组没有对应上,错了一个时钟周期:
sgn寄存了一个周期:
          if data(count)>0 then
              sgn(count)<=1;
          else
              sgn(count)<=-1;
          end if;
但是在输出的时候:
sgn_port<=conv_std_logic_Vector(sgn(count),3);
sgn用的值实际上是上一周期的,count用的是本周期的.正好错开了一周期;
例如:本周期count为0时,sgn还没有任何值,在下一周期才有有效的值;本周期输出sgn(count)显然不是想要的值
 楼主| izefei 发表于 2011-5-24 08:36 | 显示全部楼层
精辟!感谢!通过这个错误,e又学到了很多东西。
再次感谢!!!!!!!!!!! 3# AutoESL
AutoESL 发表于 2011-5-24 09:53 | 显示全部楼层
共同学习,共同进步!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

80

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部