很郁闷的问题
时间:10-02
整理:3721RD
点击:
VDHL写的一段代码:
type Reg is array(0 to 3) of std_logic_vector(7 downto 0);
...
Rd : in STD_LOGIC_VECTOR (1 downto 0); --端口声明里的
function decode(R_code : in std_logic_vector(1 downto 0)) --2-4译码器
return integer is
variable tmp : integer;
begin
case R_code is
when "00" => tmp:=0;
when "01" => tmp:=1;
when "10" => tmp:=2;
when "11" => tmp:=3;
when others => NULL;
end case;
return tmp;
end;
process (CLK)
variable R : Reg;
variable tmp: integer;
begin
...
tmp :=decode(Rd);
R_load(R(tmp)(2 downto 0),Rs);
...
R_load这个函数在这个问题里无关紧要。
让我很崩溃的是上面最后两行代码在板子上没效果,但下面这两行代码却没问题:
tmp :=2;
R_load(R(tmp)(2 downto 0),Rs);
decode(Rd)这个函数绝对没问题,我试过单独调用,Rd=“10”时tmp就是2.
既然tmp是2,为啥R(tmp)与R(2)不等价呢?
说白了我就是想让R的第一维下标依赖于板子上的开关Rd。
现在做不到这点,请问有什么别的好办法?
环境是ISE11,芯片是SPARTAN3
type Reg is array(0 to 3) of std_logic_vector(7 downto 0);
...
Rd : in STD_LOGIC_VECTOR (1 downto 0); --端口声明里的
function decode(R_code : in std_logic_vector(1 downto 0)) --2-4译码器
return integer is
variable tmp : integer;
begin
case R_code is
when "00" => tmp:=0;
when "01" => tmp:=1;
when "10" => tmp:=2;
when "11" => tmp:=3;
when others => NULL;
end case;
return tmp;
end;
process (CLK)
variable R : Reg;
variable tmp: integer;
begin
...
tmp :=decode(Rd);
R_load(R(tmp)(2 downto 0),Rs);
...
R_load这个函数在这个问题里无关紧要。
让我很崩溃的是上面最后两行代码在板子上没效果,但下面这两行代码却没问题:
tmp :=2;
R_load(R(tmp)(2 downto 0),Rs);
decode(Rd)这个函数绝对没问题,我试过单独调用,Rd=“10”时tmp就是2.
既然tmp是2,为啥R(tmp)与R(2)不等价呢?
说白了我就是想让R的第一维下标依赖于板子上的开关Rd。
现在做不到这点,请问有什么别的好办法?
环境是ISE11,芯片是SPARTAN3
没人知道怎么解决么。
和你一样糊涂着
可能是函数调用参数不要用端口,你改用信号,或用变量先传递。
回楼上,R_load这句中没有涉及到端口。如果你指的是decode这里面用了端口Rd的话,我单独调试过decode,这里面用端口还是用别的没关系。
decode 函数没有必要自己写,STD_LOGIC_UNSIGNED库里的CONV_INTEGER()函数就可实现这功能。
代码我也没看出什么问题,建议还是仿真一下,应该能发现问题在哪。
谢谢楼上的,我也试过conv_integer,问题依旧。仿真也没看出哪有问题,可是实际跑的时候这两种写法的结果就截然不同
