1、第一次上机安排,第六周 周一晚(提高1、2,通信001012)周二上(通信014085)周四上(通信086154)周四下(通信250282,电信001043)周五晚(电信044125)第七周 周一下(电信125216)周二上(电信217302)周二下(电信302385),VHDL硬件描述语言基础,简介基本结构基本数据类型设计组合电路设计时序电路设计状态机大规模电路的层次化设计Function and Procedure,简介背景,传统数字电路设计方法不适合设计大规模的系统。工程师不容易理解原理图设计的功能。众多软件公司开发研制了具有自己特色的电路硬件描述语言(Hardware Descript
2、ion Language,HDL),存在着很大的差异,工程师一旦选用某种硬件描述语言作为输入工具,就被束缚在这个硬件设计环境之中。因此,硬件设计工程师需要一种强大的、标准化的硬件描述语言,作为可相互交流的设计环境。,简介背景,美国国防部在80年代初提出了VHSIC(Very High Speed Integrated Circuit)计划,其目标之一是为下一代集成电路的生产,实现阶段性的工艺极限以及完成10万门级以上的设计,建立一项新的描述方法。1981年提出了一种新的HDL,称之为VHSIC Hardware Description Language,简称为VHDL,这种语言的成就有两个方面
3、:描述复杂的数字电路系统成为国际的硬件描述语言标准,VHDL的优点,用于设计复杂的、多层次的设计。支持设计库和设计的重复使用与硬件独立,一个设计可用于不同的硬件结构,而且设计时不必了解过多的硬件细节。有丰富的软件支持VHDL的综合和仿真,从而能在设计阶段就能发现设计中的Bug,缩短设计时间,降低成本。更方便地向ASIC过渡VHDL有良好的可读性,容易理解。,VHDL与计算机语言的区别,运行的基础计算机语言是在CPURAM构建的平台上运行VHDL设计的结果是由具体的逻辑、触发器组成的数字电路执行方式计算机语言基本上以串行的方式执行VHDL在总体上是以并行方式工作验证方式计算机语言主要关注于变量值
4、的变化VHDL要实现严格的时序逻辑关系,-eqcomp4 is a four bit equality comparatorLibrary IEEE;use IEEE.std_logic_1164.all;entity eqcomp4 isport(a,b:in std_logic_vector(3 downto 0);equal:out std_logic);end eqcomp4;architecture dataflow of eqcomp4 isbegin equal=1 when a=b else 0;End dataflow;,VHDL 大小写不敏感,eqcomp4.vhd,包,实
5、体,构造体,文件名和实体名一致,每行;结尾,关键字begin,关键字end后跟实体名,关键字end后跟构造体名,库,实体(Entity),描述此设计功能输入输出端口(Port)在层次化设计时,Port为模块之间的接口在芯片级,则代表具体芯片的管脚,A3.0,B3.0,equal,Entity eqcomp4 isport(a,b:in std_logic_vector(3 downto 0);equal:out std_logic);end eqcomp4;,实体端口的模式,输入(Input)输出(Output)双向(Inout):可代替所有其他模式,但降低了程序的可读性,一般用于与CPU的数
6、据总线接口缓冲(Buffer):与Output类似,但允许该管脚名作为一些逻辑的输入信号,Out与Buffer的区别,Entity test1 is port(a:in std_logic;b,c:out std_logic);end test1;architecture a of test1 is begin b=not(a);c=b;-Error end a;,Entity test2 is port(a:in std_logic;b:buffer std_logic;c:out std_logic);end test2;architecture a of test2 is begin b
7、=not(a);c=b;end a;,结构体(Architecture),描述实体的行为结构体有三种描述方式行为描述(behavioral)数据流描述(dataflow)结构化描述(structural),结构体行为描述,Architecture behavioral of eqcomp4 is begincomp:process(a,b)beginif a=b then equal=1;else equal=0;end if;end process comp;end behavioral;,高层次的功能描述,不必考虑在电路中到底是怎样实现的。,结构体数据流描述描述输入信号经过怎样的变换得到输
8、出信号,Architecture dataflow1 of eqcomp4 is begin equal=1 when a=b else 0;end dataflow1;,Architecture dataflow2 of eqcomp4 is beginequal=not(a(0)xor b(0)and not(a(1)xor b(1)and not(a(2)xor b(2)and not(a(3)xor b(3);end dataflow2;,当a和b的宽度发生变化时,需要修改设计,当宽度过大时,设计非常繁琐,结构体结构化描述,architecture struct of eqcomp4
9、isbegin U0:xnor2 port map(a(0),b(0),x(0);U1:xnor2 port map(a(1),b(1),x(1);U2:xnor2 port map(a(2),b(2),x(2);U3:xnor2 port map(a(3),b(3),x(3);U4:and4 port map(x(0),x(1),x(2),x(3),equal);end struct;,类似于电路的网络表,将各个器件通过语言的形式进行连接,与电路有一一对应的关系。一般用于大规模电路的层次化设计时。,三种描述方式的比较,VHDL标识符(Identifiers),基本标识符由字母、数字和下划线组
10、成第一个字符必须是字母最后一个字符不能是下划线不允许连续2个下划线保留字(关键字)不能用于标识符大小写是等效的,VHDL数据对象(Data Objects),常数(Constant)固定值,不能在程序中被改变增强程序的可读性,便于修改程序在综合后,连接到电源和地可在Library、Entity、Architecture、Process中进行定义,其有效范围也相应限定Constant data_bus_width:integer:=8;,VHDL数据对象(Data Objects),信号(Signals)代表连线,Port也是一种信号没有方向性,可给它赋值,也可当作输入在Entity中和Arch
11、itecture中定义设定的初始值在综合时没有用,只是在仿真时在开始设定一个起始值。在MaxPlusII中被忽略。用=进行赋值signal count:bit_vector(3 downto 0):=“0011”;,VHDL数据对象(Data Objects),变量(Variable)临时数据,没有物理意义只能在Process和Function中定义,并只在其内部有效要使其全局有效,先转换为Signal。用:=进行赋值 variable result:std_logic:=0;,信号与变量的区别,architecture rtl of start is signal count:integer
12、 range 0 to 7;begin process(clk)begin if(clkevent and clk=1)then count=count+1;if(count=0)then carryout=1;else carryout=0;end if;end if;end process;end rtl;,architecture rtl of start is begin process(clk)variable count:integer range 0 to 7;begin if(clkevent and clk=1)then count:=count+1;if(count=0)t
13、hen carryout=1;else carryout=0;end if;end if;end process;end rtl;,信号与变量的区别,architecture a of start is signal tmp:std_logic;begin process(a_bus)begin tmp=1;for i in 3 downto 0 loop tmp=a_bus(i)and tmp;end loop;carryout=tmp;end process;end a;,architecture a of start is begin process(a_bus)variable tmp
14、:std_logic;begin tmp:=1;for i in 3 downto 0 loop tmp:=a_bus(i)and tmp;end loop;carryout=tmp;end process;end a;,VHDL数据类型,标量类型(Scalar)枚举(Enumeration)整数(Integer)浮点数(Float)物理(Physical)复合类型(Composite),VHDL数据类型枚举,列举数据对象可能存在的值,一般用于定义状态机的状态Type states is(idle,start,running,pause,stop)Signal current_state:st
15、ates;IEEE1076标准中预定义了两个枚举类型Type boolean is(False,True)Type bit is(0,1)Signal a:bit;,VHDL数据类型枚举,IEEE1164标准中预定义了一个枚举类型Type std_logic is(U,X,0,1,Z,W,L,H,-);该类型能比较全面地包括数字电路中信号会出现的几种状态,因此一般情况把这种类型代替bitSignal a:std_logic;注意:这里的大小写是敏感的,VHDL数据类型,整数、浮点数方便用于数值方面的运算:加减乘除整数范围:-231 231 1,经常用于计数器实数范围:-1.0E38+1.0E3
16、8,不被MaxPLusII支持Variable a:integer range 255 to+255;物理类型主要用于调试,VHDL数据类型复合类型,Array Types多个相同类型成员组成的队列,一般用于定义数据总线、地址总线等。Signal a:std_logic_vector(7 downto 0);a=B“00111010”;a=X“3A”;可自定义复合类型Type word is array(15 downto 0)of bit;Signal b:word;Type table8x4 is array(0 to 7,0 to 3)of bit;,VHDL数据类型复合类型,Recor
17、d Types相同或不同类型的元素组成,类似C中的结构具有模型抽象能力,用于描述一个功能模块Type iocell is record Enable:bit;DataBus:bit_vector(7 downto 0);end record;singal bus:iocell;bus.Enable=1;bus.DataBus=“00110110”;,VHDL数据类型及子类型Types And Subtypes,VHDL是强类型语言,必须用类型转换函数才能进行不同类型之间的转换type byte_size is integer range 0 to 255;signal a:byte_size;
18、signal b:integer range 0 to 255;if a=b then 采用以下方式 subtype byte_size is integer range 0 to 255;,属性(Attributes),提供Entity、Architecture、Type和Signals的信息。有许多预定义的值、信号和范围的属性一个最常用的属性是eventif clkevent and clk=1 thenleft,right,high,low,lengthtype count is integer range 0 to 127countleft=0;countright=127;count
19、high=127;countlow=0;countlength=128;,VHDL运算符,逻辑运算符AND、OR、NAND、NOR、XOR、NOT关系运算符=、/=、=算术运算符+、-、*、/并置(连接)运算符&,组合电路并行语句(Concurrent),并行语句位于Process外面,同时执行,不分位置的先后顺序并行语句包括:布尔等式:=With-select-whenWhen-else布尔等式 A=s(0)and s(1);B=not(y);,组合电路并行语句,With-select-when语句 With Sel_signal select Signal_name=a when Sel_
20、signal_1,b when Sel_signal_2,c when Sel_signal_3,x when Sel_signal_x;,Signal s:std_logic_vector(1 downto 0);Signal a,b,c,d,x:std_logic;With s select x=a when“00”,b when“01”,c when“10”,d when others;,组合电路并行语句,When-else语句 Signal_name=a when condition1 else b when condition2 else c when condition3 else
21、 x;,x=a when s=“00”else b when s=“01”else c when s=“10”else d;,Signal a,b,c,d:std_logic;Signal w,x,y,z:std_logic;x=w when a=1 else x when b=1 else y when c=1 else z when d=1 else 0;,组合电路并行语句,实现优先级编码器 encode=“111”when D(7)=1 else“110”when D(6)=1 else“101”when D(5)=1 else“100”when D(4)=1 else“011”when
22、 D(3)=1 else“010”when D(2)=1 else“001”when D(1)=1 else“000”when D(0)=1 else“000”;,组合电路并行语句,When-else语句条件语句可以是一个简单的表达式With-select-when则不能采用表达式作为条件 a=“0000”when state=idle and state=1 else“0001”when state=idle and state=0 else b when state=running and state=1 else a;,组合电路顺序语句(Sequential),Process,Funct
23、ion,Procedure中的语句都是顺序执行,以Process为例Process与Process之间,与其他并行语句之间都是并行的关系If-then-elseCase-when,组合电路顺序语句,If-then-elseIf(condition1)then do something;elsif(condition2)then else do something different;end if;,组合电路顺序语句,Process(addr)Begin step=0;if(addr=X“F”)then step=1;end if;End process;,Process(addr)Begin
24、if(addr=X“F”)then step=1;else step=0;end if;End process;,Process(addr)Begin if(addr=X“F”)then step=1;end if;End process;,Step=addr(3)*addr(2)*Addr(1)*addr(0)+step,组合电路顺序语句,用于作地址译码InRam=X“0000”and addr=X“4000”and addr=X“4008”and addr=X“8000”and addr=X“C000”then EEPRom=1;end if;,组合电路顺序语句,Case-when cas
25、e sel_signal is when value_1=(do sth)when value_2=(do sth)when value_last=(do sth)end case;,组合电路顺序语句,实现数码管译码器Process(address)begin case address is when“0000”=decode decode decode decode decode=X“00”;end case;end process;,几种语句的比较,同步时序逻辑电路,Process(clk)begin if(clkevent and clk=1)then q=d;end if;end process;,Process(clk)begin if(clk=1)then q=d;end if;end process;,D触发器,缓冲器,实现T触发器,Process(clk)begin if(clkevent and clk=1)then if(t=1)then q=not(q);else q=q;end if;end if;end process;,
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2