打印

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

[复制链接]
1269|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;
仿真波形见图:

截图00.jpg (13.69 KB )

截图00.jpg

相关帖子

沙发
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

使用特权

评论回复
5
AutoESL| | 2011-5-24 09:53 | 只看该作者
共同学习,共同进步!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

80

帖子

1

粉丝