Presentation is loading. Please wait.

Presentation is loading. Please wait.

第一次上机安排 第六周 第七周 周一晚(提高1、2,通信001~012) 周二上(通信014~085) 周四上(通信086~154)

Similar presentations


Presentation on theme: "第一次上机安排 第六周 第七周 周一晚(提高1、2,通信001~012) 周二上(通信014~085) 周四上(通信086~154)"— Presentation transcript:

1 第一次上机安排 第六周 第七周 周一晚(提高1、2,通信001~012) 周二上(通信014~085) 周四上(通信086~154)
周四下(通信250~282,电信001~043) 周五晚(电信044~125) 第七周 周一下(电信125~216) 周二上(电信217~302) 周二下(电信302~385)

2 VHDL硬件描述语言基础 简介 基本结构 基本数据类型 设计组合电路 设计时序电路 设计状态机 大规模电路的层次化设计
Function and Procedure

3 简介--背景 传统数字电路设计方法不适合设计大规模的系统。工程师不容易理解原理图设计的功能。
众多软件公司开发研制了具有自己特色的电路硬件描述语言(Hardware Description Language,HDL),存在着很大的差异,工程师一旦选用某种硬件描述语言作为输入工具,就被束缚在这个硬件设计环境之中。因此,硬件设计工程师需要一种强大的、标准化的硬件描述语言,作为可相互交流的设计环境。

4 简介--背景 美国国防部在80年代初提出了VHSIC(Very High Speed Integrated Circuit)计划,其目标之一是为下一代集成电路的生产,实现阶段性的工艺极限以及完成10万门级以上的设计,建立一项新的描述方法。1981年提出了一种新的HDL,称之为VHSIC Hardware Description Language,简称为VHDL,这种语言的成就有两个方面: 描述复杂的数字电路系统 成为国际的硬件描述语言标准

5 VHDL的优点 用于设计复杂的、多层次的设计。支持设计库和设计的重复使用
与硬件独立,一个设计可用于不同的硬件结构,而且设计时不必了解过多的硬件细节。 有丰富的软件支持VHDL的综合和仿真,从而能在设计阶段就能发现设计中的Bug,缩短设计时间,降低成本。 更方便地向ASIC过渡 VHDL有良好的可读性,容易理解。

6 VHDL与计算机语言的区别 运行的基础 执行方式 验证方式 计算机语言是在CPU+RAM构建的平台上运行
计算机语言基本上以串行的方式执行 VHDL在总体上是以并行方式工作 验证方式 计算机语言主要关注于变量值的变化 VHDL要实现严格的时序逻辑关系

7 VHDL 大小写不敏感 eqcomp4.vhd 库 包 实体 构造体 文件名和实体名一致 Library IEEE;
--eqcomp4 is a four bit equality comparator Library IEEE; use IEEE.std_logic_1164.all; entity eqcomp4 is port(a, b:in std_logic_vector(3 downto 0); equal :out std_logic); end eqcomp4; architecture dataflow of eqcomp4 is begin equal <= ‘1’ when a=b else ‘0’; End dataflow; 实体 每行;结尾 关键字end后跟实体名 构造体 关键字begin 关键字end后跟构造体名

8 实体(Entity) 描述此设计功能输入输出端口(Port) 在层次化设计时,Port为模块之间的接口 在芯片级,则代表具体芯片的管脚
Entity eqcomp4 is port(a, b: in std_logic_vector(3 downto 0); equal:out std_logic ); end eqcomp4; A[3..0] equal B[3..0]

9 实体--端口的模式 输入(Input) 输出(Output)
双向(Inout):可代替所有其他模式,但降低了程序的可读性,一般用于与CPU的数据总线接口 缓冲(Buffer):与Output类似,但允许该管脚名作为一些逻辑的输入信号

10 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 <= not(a); c <= b; end a;

11 结构体(Architecture) 描述实体的行为 结构体有三种描述方式 行为描述(behavioral) 数据流描述(dataflow)
结构化描述(structural)

12 结构体--行为描述 Architecture behavioral of eqcomp4 is begin
comp: process (a,b) if a=b then equal <= ‘1’; else equal <=‘0’; end if; end process comp; end behavioral ; 高层次的功能描述,不必考虑在电路中到底是怎样实现的。

13 结构体--数据流描述 描述输入信号经过怎样的变换得到输出信号
Architecture dataflow1 of eqcomp4 is begin equal <= ‘1’ when a=b else ‘0’; end dataflow1; Architecture dataflow2 of eqcomp4 is begin equal <= 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的宽度发生变化时,需要修改设计,当宽度过大时,设计非常繁琐

14 结构体--结构化描述 architecture struct of eqcomp4 is begin
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; 类似于电路的网络表,将各个器件通过语言的形式进行连接,与电路有一一对应的关系。 一般用于大规模电路的层次化设计时。

15 三种描述方式的比较 描述方式 优点 缺点 适用场合 结构化描述 连接关系清晰,电路模块化清晰 电路不易理解、繁琐、复杂 电路层次化设计
数据流描述 布尔函数定义明白 不易描述复杂电路,修改不易 小门数设计 行为描述 电路特性清楚明了 进行综合效率相对较低 大型复杂的电路模块设计

16 VHDL标识符(Identifiers)
基本标识符由字母、数字和下划线组成 第一个字符必须是字母 最后一个字符不能是下划线 不允许连续2个下划线 保留字(关键字)不能用于标识符 大小写是等效的

17 VHDL数据对象(Data Objects)
常数(Constant) 固定值,不能在程序中被改变 增强程序的可读性,便于修改程序 在综合后,连接到电源和地 可在Library、Entity、Architecture、Process中进行定义,其有效范围也相应限定 Constant data_bus_width: integer := 8;

18 VHDL数据对象(Data Objects)
信号(Signals) 代表连线,Port也是一种信号 没有方向性,可给它赋值,也可当作输入 在Entity中和Architecture中定义 设定的初始值在综合时没有用,只是在仿真时在开始设定一个起始值。在Max+PlusII中被忽略。 用 <= 进行赋值 signal count:bit_vector(3 downto 0):=“0011”;

19 VHDL数据对象(Data Objects)
变量(Variable) 临时数据,没有物理意义 只能在Process和Function中定义,并只在其内部有效 要使其全局有效,先转换为Signal。 用 := 进行赋值 variable result : std_logic := ‘0’;

20 信号与变量的区别 architecture rtl of start is
signal count : integer range 0 to 7; begin process(clk) if (clk'event and clk='1') then count <= count + 1; if(count=0) then carryout <= '1'; else carryout <= '0'; end if; end process; end rtl; architecture rtl of start is begin process(clk) variable count : integer range 0 to 7; if (clk'event and clk='1') then count := count + 1; if(count=0) then carryout <= '1'; else carryout <= '0'; end if; end process; end rtl;

21 信号与变量的区别 architecture a of start is signal tmp : std_logic; begin
process(a_bus) 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:std_logic; tmp := '1'; for i in 3 downto 0 loop tmp := a_bus(i) and tmp; end loop; carryout <= tmp; end process; end a;

22 VHDL数据类型 标量类型(Scalar) 复合类型(Composite) 枚举(Enumeration) 整数(Integer)
浮点数(Float) 物理(Physical) 复合类型(Composite)

23 VHDL数据类型--枚举 列举数据对象可能存在的值,一般用于定义状态机的状态 IEEE1076标准中预定义了两个枚举类型
Type states is (idle, start, running, pause, stop) Signal current_state : states; IEEE1076标准中预定义了两个枚举类型 Type boolean is (False, True) Type bit is (‘0’, ‘1’) Signal a : bit;

24 VHDL数据类型--枚举 IEEE1164标准中预定义了一个枚举类型Type std_logic is(‘U’, ‘X’,‘0’, ‘1’, ‘Z’, ‘W’, ‘L’, ‘H’, ‘-’); 该类型能比较全面地包括数字电路中信号会出现的几种状态,因此一般情况把这种类型代替bit Signal a : std_logic; 注意:这里的大小写是敏感的

25 VHDL数据类型 整数、浮点数 物理类型 方便用于数值方面的运算:加减乘除 整数范围:-231 ~231 –1,经常用于计数器
实数范围:-1.0E38~+1.0E38,不被 Max+PLusII支持 Variable a : integer range –255 to +255; 物理类型 主要用于调试

26 VHDL数据类型--复合类型 Array Types 多个相同类型成员组成的队列,一般用于定义数据总线、地址总线等。
Signal a: std_logic_vector(7 downto 0); a <= B“ ”; 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;

27 VHDL数据类型--复合类型 Record Types 相同或不同类型的元素组成,类似C中的结构 具有模型抽象能力,用于描述一个功能模块
Type iocell is record Enable :bit; DataBus :bit_vector(7 downto 0); end record; singal bus : iocell; bus.Enable <= ‘1’; bus.DataBus <= “ ”;

28 VHDL数据类型及子类型 Types And Subtypes
type byte_size is integer range 0 to 255; signal a : byte_size; signal b : integer range 0 to 255; if a=b then …… 采用以下方式 subtype byte_size is integer range 0 to 255;

29 属性(Attributes) 提供Entity、Architecture、Type和Signals的信息。
有许多预定义的值、信号和范围的属性 一个最常用的属性是’event if clk’event and clk=‘1’ then ’left,’right, ’high, ’low,’length type count is integer range 0 to 127 count’left = 0; count’right = 127; count’high = 127; count’low = 0; count’length = 128;

30 VHDL运算符 逻辑运算符 关系运算符 算术运算符 并置(连接)运算符 AND、OR、NAND、NOR、XOR、NOT
=、/=、<、>、<=、>= 算术运算符 +、-、*、/ 并置(连接)运算符 &

31 组合电路--并行语句(Concurrent)
并行语句位于Process外面,同时执行,不分位置的先后顺序 并行语句包括: 布尔等式: <= With-select-when When-else 布尔等式 A <= s(0) and s(1); B <= not(y);

32 组合电路--并行语句 With-select-when语句 With Sel_signal select
Signal_name <= a when Sel_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;

33 组合电路--并行语句 When-else语句 Signal_name <= a when condition1 else
b when condition2 else c when condition3 else … x ; 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’; x <= a when s=“00” else b when s=“01” else c when s=“10” else d;

34 组合电路--并行语句 实现优先级编码器 encode <= “111” when D(7) = ‘1’ else
“000”;

35 组合电路--并行语句 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;

36 组合电路--顺序语句(Sequential)
Process,Function,Procedure中的语句都是顺序执行,以Process为例 Process与Process之间,与其他并行语句之间都是并行的关系 If-then-else Case-when

37 组合电路--顺序语句 If-then-else If(condition1) then do something;
elsif(condition2) then … else do something different; end if;

38 组合电路--顺序语句 Process(addr) Begin step <= ‘0’; if(addr = X “F”) then
end if; End process; Process(addr) Begin 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

39 组合电路--顺序语句 用于作地址译码 InRam <= ‘0’; Periph1 <= ‘0’; Periph2 <= ‘0’; OutRam<= ‘0’; EEPRom <= ‘1’; If addr >= X “0000” and addr <X “4000” then InRam <= ‘1’; elsif addr >= X “4000” and addr <X “4008” then Periph1 <= ‘1’; elsif addr >= X “4008” and addr <X “4010” then Periph2 <= ‘1’; elsif addr >= X “8000” and addr <X “C000” then OutRam <= ‘1’; elsif addr >= X “C000” then EEPRom <= ‘1’; end if;

40 组合电路--顺序语句 Case-when case sel_signal is when value_1 => (do sth)
when value_last => end case;

41 组合电路--顺序语句 实现数码管译码器 Process(address) begin case address is
when “0000” => decode <= X “3F” when “0001” => decode <= X “60” when “0010” => decode <= X “B5” when “0011” => decode <= X “F4” …… when others => decode <= X “00”; end case; end process;

42 几种语句的比较 语句 With-select-when When-else If-else Case-when 选择条件
一个信号的不同值,互斥 多个信号多种组合,不必互斥 语句属性 并行 顺序 用途 编码、译码、多路选择器 优先编码器,地址译码器 状态机

43 同步时序逻辑电路 Process(clk) begin if(clk’event and clk=‘1’) then q <= d;
end if; end process; Process(clk) begin if(clk=‘1’) then q <= d; end if; end process; D触发器 缓冲器

44 实现T触发器 Process(clk) begin if(clk’event and clk=‘1’) then
if(t = ‘1’) then q <= not(q); else q <= q; end if; end process;


Download ppt "第一次上机安排 第六周 第七周 周一晚(提高1、2,通信001~012) 周二上(通信014~085) 周四上(通信086~154)"

Similar presentations


Ads by Google