在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 3098|回复: 9

[求助] 请教大侠们关于VHDL语言编写的数组问题!!

[复制链接]
发表于 2010-6-29 20:05:47 | 显示全部楼层 |阅读模式
50资产
本帖最后由 kscc0202121 于 2010-7-1 10:15 编辑


下面编写的数组不知道有什么错误,请大侠们赐教。
如果不对应该怎么编呢??

TYPE table1 IS ARRAY (0 TO 3) OF STD_LOGIC;
SIGNAL t1: table1;
t1(0)<="1111111"; table(1)<="1001111";
t1(2)<="0010111"; table(3)<="1000011";

另外,假如上面程序是正确的,是不是t1(1)(0)='1',能像C语言一样这样用不?

最佳答案

查看完整内容

仿真与综合通过,,
发表于 2010-6-29 20:05:48 | 显示全部楼层
仿真与综合通过,,
发表于 2010-6-29 20:50:18 | 显示全部楼层
TYPE table1 IS ARRAY (0 TO 3) OF STD_LOGIC;
应改成 std_logic_vector(6 downto 0),这样才能用,
如果要调用的话,也许是你说的这样吧?不过最好这样用:
signal t_tmp : std_logic_vector(6 downto 0);
t_tmp <= t1(1);
if t_tmp(0) = '1'
这样更清晰点。
 楼主| 发表于 2010-7-1 07:55:47 | 显示全部楼层
哥们,你说的我有点晕。
倒数第二行为什么用到了if?

麻烦你把修改结果完整的呈现一下好吧?

谢谢!!
发表于 2010-7-1 09:51:46 | 显示全部楼层
TYPE table1 IS ARRAY (0 TO 3) OF  std_logic_vector(6 downto 0);
SIGNAL t1: table1;
t1(0)<="1111111"; table(1)<="1001111";
t1(2)<="0010111"; table(3)<="1000011";



另外,假如上面程序是正确的,是不是t1(1)(0)='1',能像C语言一样这样用不?
是不是t1(1)(0)='1',改写成如下
如果要调用的话,也许是你说的这样吧?不过最好这样用:
signal t_tmp : std_logic_vector(6 downto 0);
t_tmp <= t1(1);
if t_tmp(0) = '1'
这样更清晰点。
 楼主| 发表于 2010-7-1 10:11:53 | 显示全部楼层
我的源程序是下面这个,好像是数组出现问题导致编译通不过。用的Quartus。请帮忙纠错!!谢谢!!!
(红色字体定义的数组部分用最下面的红色字体替换后还是不行,不知道为什么,真郁闷死了!!)
LIBRARY IEEE;
USE IEEE.std_logic_1164.ALL;
USE IEEE.std_logic_arith.ALL;
USE IEEE.std_logic_unsigned.ALL;

ENTITY Ctrl_dec IS

PORT( U1:
IN std_logic;


a1,b1,c1,d1,e1,f1,g1 : OUT std_logic);

END Ctrl_dec;

ARCHITECTURE
Ctrl_dec_arc of Ctrl_dec IS


TYPE table2 IS ARRAY (0 TO 3) OF std_logic;


SIGNAL t2 : table2 <=
("0111110","1011110","1101110","1110110");
BEGIN

PROCESS (U1)


BEGIN


IF (U1 = '1')
THEN


a1<= t2(1)(0); b1<= t2(1)(1); c1<= t2(1)(2); d1<= t2(1)(3);


e1<= t2(1)(4); f1<= t2(1)(5); g1<= t2(1)(6);


ELSE
a1<='1'; b1<='1'; c1<='1'; d1<='1'; e1<='1'; f1<='1'; g1<='1';


END IF;

END PROCESS;
END Ctrl_dec_arc;



TYPE table2 IS ARRAY (0 TO 3, 0 TO 6) OF std_logic;


SIGNAL t2 : table2 <= (


('0','1','1','1','1','1','0' ),


('1','0','1','1','1','1','0' ),


('1','1','0','1','1','1','0' ),


('1','1','1','0','1','1','0' )


);
 楼主| 发表于 2010-7-1 10:14:09 | 显示全部楼层
哥们,我按照你的方法改了,也不行。
发表于 2010-7-1 15:33:49 | 显示全部楼层
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.numeric_std.all;

entity Ctrl_dec is
    port (
        -- global
        U1                            : in    std_logic;
        a1,b1,c1,d1,e1,f1,g1          : out   std_logic
         );

end Ctrl_dec ;

architecture rtl of Ctrl_dec is

TYPE table2 IS ARRAY (0 TO 3) OF std_logic_vector(6 downto 0);
constant t2 : table2 := ("0111110","1011110","1101110","1110110");

begin

PROCESS (U1)

BEGIN
IF (U1 = '1')THEN
a1<= t2(1)(0); b1<= t2(1)(1); c1<= t2(1)(2); d1<= t2(1)(3);

e1<= t2(1)(4); f1<= t2(1)(5); g1<= t2(1)(6);
else
a1<='1'; b1<='1'; c1<='1'; d1<='1'; e1<='1'; f1<='1'; g1<='1';
END IF;
END PROCESS;

end rtl;
发表于 2010-7-1 16:20:05 | 显示全部楼层
楼主先看看书再来提问 先自己思考 这种问题就不要拿出来问了。
发表于 2010-7-1 22:08:21 | 显示全部楼层
给个参考的吧,不想删了,直接全部拷给你们。
--FILENAME                        :                DDR2_LOCAL_INTERFACE
--DESCRITPION                :       
--CURRICULUM VITAE        :               
--first vision                        :                2010-03-22;designed for ddr2 controller use;
--改进需求:在识别用户端口上有写请求时,在此时钟周期开始的BL个时钟周期内不响应用户端口上的读写请求,以完整接收数据;
--改进需求:在识别用户端口上有写请求时,在此时钟周期开始的BL个时钟周期内,主动从用户数据端口上汲取数据,防止用户没有按
--照BL的方式发送数据;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity ddr2_local_interface is
        generic(
                local_address_bus_width                        :                integer range 0 to 50                        :=32;
                local_data_bus_width                                :                integer range 0 to 128                        :=64;
                bank_address_bus_width                        :                integer range 0 to 8                        :=3;
                rows_address_bus_width                        :                integer range 0 to 20                        :=10;
                colm_address_bus_width                        :                integer range 0 to 20                        :=10;                               
                bl                                                                :                integer range 0 to 8                        :=8;
                command_stack_depth                                :                integer range 0 to 256                        :=64               
        );
        port(
                clk                                                                :                in        std_logic;
                block_reset                                                :                in        std_logic;
                local_read_request                                        :                in        std_logic;
                local_write_request                                        :                in        std_logic;
                local_address                                                :                in        std_logic_vector(local_address_bus_width-1 downto 0);
                lcoal_data_write_requset                        :                in        std_logic;
                local_data                                                :                in        std_logic_vector(local_data_bus_width-1 downto 0);
                command_execute_response                        :                in        std_logic;
                command_bus                                                :                out        std_logic_vector(1 downto 0);
                address_bus                                                :                out        std_logic_vector(local_address_bus_width-1 downto 0);
                data_written_response                                :                in        std_logic;
                data_bus                                                        :                out        std_logic_vector(local_data_bus_width-1 downto 0)
        );
end entity ddr2_local_interface;

architecture archi of ddr2_local_interface is
type        array_local_comand is array (integer range 0 to command_stack_depth-1) of std_logic_vector(1 downto 0);
        ----定义一个宽度为2,深度为command_stack_depth-1的命令堆栈。堆栈里面存储"01"或者"10";
        ----其中"01"表示存储了一个读命令;"10"表示存储了一个写命令;
        ----'0'表示存储了一个写命令。最多可以存储command_stack_depth个命令;
type        array_local_data is array (integer range 0 to bl*command_stack_depth-1) of std_logic_vector(local_data_bus_width-1 downto 0);
        ----定义一个宽度为local_data_bus_width,深度为bl*command_stack_depth的数据堆栈。堆栈里面存储将被写入DDR2 SDRAM
        ----的数据。由于每个写地址最多可以定义burst length个数据,因此堆栈深度要在command_stack_depth基础上乘以bl参数;
type        array_local_address is array (integer range 0 to command_stack_depth-1) of std_logic_vector(local_address_bus_width-1 downto 0);
        ----定义一个宽度为local_address_bus_width,深度为command_stack_depth的数据堆栈。堆栈里面存储与命令堆栈中的命令相同步的地址;
signal        local_command_stack                                :                array_local_comand;
signal        local_data_stack                                        :                array_local_data;
signal        local_address_stack                                :                array_local_address;

signal        com_add_stack_write_pointer                :                integer range 0 to command_stack_depth-1                        :=0;
signal        com_add_stack_read_pointer                        :                integer range 0 to command_stack_depth-1                        :=0;
signal        data_stack_write_pointer                        :                integer range 0 to bl*command_stack_depth-1                :=0;
signal        data_stack_read_pointer                                :                integer range 0 to bl*command_stack_depth-1                :=0;
begin
        process(block_reset,clk)
        begin
                if(block_reset='0')then
                        com_add_stack_write_pointer        <=0;
                elsif(rising_edge(clk))then
                        if((local_read_request xor local_write_request)='1')then
                                if(com_add_stack_write_pointer=(command_stack_depth-1))then
                                        com_add_stack_write_pointer        <=0;
                                else
                                        com_add_stack_write_pointer        <=com_add_stack_write_pointer+1;
                                end if;
                        end if;
                end if;
        end process;
       
        process(block_reset,clk)
        begin
                if(block_reset='0')then
                        data_stack_write_pointer<=0;
                elsif(rising_edge(clk))then
                        if(lcoal_data_write_requset='1')then
                                if(data_stack_write_pointer=bl*command_stack_depth-1)then
                                        data_stack_write_pointer<=0;
                                else
                                        data_stack_write_pointer<=data_stack_write_pointer+1;
                                end if;
                        end if;
                end if;
        end process;
       
        process(block_reset,clk)
        begin
                if(block_reset='0')then
                        com_add_stack_read_pointer<=0;
                elsif(rising_edge(clk))then
                        if(command_execute_response='1')then
                                if(com_add_stack_read_pointer=command_stack_depth-1)then
                                        com_add_stack_read_pointer<=0;
                                else
                                        com_add_stack_read_pointer<=com_add_stack_read_pointer+1;
                                end if;
                        end if;
                end if;
        end process;
       
        process(block_reset,clk)
        begin
                if(block_reset='0')then
                        data_stack_read_pointer<=0;
                elsif(rising_edge(clk))then
                        if(data_written_response='1')then
                                if(data_stack_read_pointer=bl*command_stack_depth-1)then
                                        data_stack_read_pointer<=0;
                                else
                                        data_stack_read_pointer<=data_stack_read_pointer+1;
                                end if;
                        end if;
                end if;
        end process;
       
        process(block_reset,clk)
        begin
                if(rising_edge(clk))then
                        if((local_read_request xor local_write_request)='1')then
                                local_command_stack(com_add_stack_write_pointer)<=(local_write_request & local_read_request);
                        end if;
                end if;
        end process;
       
        process(block_reset,clk)
        begin
                if(rising_edge(clk))then
                        if((local_read_request xor local_write_request)='1')then
                                local_address_stack(com_add_stack_write_pointer)<=local_address;
                        end if;
                end if;
        end process;
       
        process(block_reset,clk)
        begin
                if(rising_edge(clk))then
                        if(lcoal_data_write_requset='1')then
                                local_data_stack(data_stack_write_pointer)<=local_data;
                        end if;
                end if;
        end process;
       
        process(block_reset,clk)
        begin
                if(rising_edge(clk))then
                        command_bus        <=local_command_stack(com_add_stack_read_pointer);
                        address_bus        <=local_address_stack(com_add_stack_read_pointer);                       
                        data_bus                <=local_data_stack(data_stack_read_pointer);
                end if;
        end process;

end architecture archi;
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-3-29 16:00 , Processed in 0.031457 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表