打印

VHDL小程序求解

[复制链接]
1393|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
damoyeren|  楼主 | 2013-6-28 10:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 damoyeren 于 2013-6-28 10:54 编辑

各位大牛,小弟才学VHDL,望指导。程序的本意是设计一个多输入与门。
1.设计一个两输入与门(这个简单能看懂)
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity myand1 is
port(a,b:in std_logic;
           q:out std_logic);
end myand1;
architecture rtl of myand1 is
begin
        q<=a and b;
end rtl;
2.通过元件例化语句和generic语句修改输入变量数目,本程序设计为8个输入端口
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity myand is
generic (sreg_width:integer:=8);
port(indata:in std_logic_vector(sreg_width-1 downto 0);
                  q:out std_logic);
end myand;

architecture rtl of myand is
signal z:std_logic_vector(sreg_width-1 downto 0);
        component myand1
                port(a,b:in std_logic;
                           q:out std_logic);
        end component;
begin
z(sreg_width)<='1';--z是定义个的一个位矢量信号,怎么能给它赋1?最起码应该是“1111 1111”,还有z(sreg—width)这种书写格式没见过?
g1:for i in sreg_width-1 downto 0 generate--有for generate这个语句嘛,它的作用是?
u1:myand1 port map (z(i+1),indata(i),z(i));端口映射时的端口对应关系,还有z(i+1),indata(i),z(i));什么意思?
end generate;--generate都没见过
q<=z(0);
end rtl;

相关帖子

沙发
huangxz| | 2013-6-28 13:56 | 只看该作者
能综合过去么,
用verilog吧,vhdl实在是难看懂。

使用特权

评论回复
板凳
yghanwuji| | 2013-6-28 17:39 | 只看该作者
1、z(sreg_width)<='1';--z是定义个的一个位矢量信号,怎么能给它赋1?最起码应该是“1111 1111”,还有z(sreg—width)这种书写格式没见过?
请看上面的:generic (sreg_width:integer:=8);表明sreg_width是个常量,所以z(sreg_width)表示z的第sreg_width位;
2、g1:for i in sreg_width-1 downto 0 generate--有for generate这个语句嘛,它的作用是?、
有,类似于C语言中满足什么条件就调用哪个函数。
3、u1:myand1 port map (z(i+1),indata(i),z(i));端口映射时的端口对应关系,还有z(i+1),indata(i),z(i));什么意思?
z(i+1)表示z的第(i+1)位,下同理

使用特权

评论回复
地板
resxpl| | 2013-6-28 20:00 | 只看该作者
楼主有些基本语法没有掌握啊, for... generate, 书上一般都会讲到.
z()这种形式是引用矢量每一位的方法.
楼主代码有bug, z 少了1位. 改成这样应该就可以了.
signal z:std_logic_vector(sreg_width downto 0);

使用特权

评论回复
5
GoldSunMonkey| | 2013-6-28 21:32 | 只看该作者
这是书上的例子。这本书挺差的

使用特权

评论回复
6
GoldSunMonkey| | 2013-6-28 21:32 | 只看该作者
至少不要轻易用generate

使用特权

评论回复
7
yghanwuji| | 2013-6-28 22:10 | 只看该作者
GoldSunMonkey 发表于 2013-6-28 21:32
至少不要轻易用generate

为啥呢,最近看leon源码里经常用···

使用特权

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

本版积分规则

126

主题

393

帖子

2

粉丝