数字系统设计教学资料-第四章时序逻辑电路.ppt

上传人:牧羊曲112 文档编号:6050092 上传时间:2023-09-18 格式:PPT 页数:37 大小:524KB
返回 下载 相关 举报
数字系统设计教学资料-第四章时序逻辑电路.ppt_第1页
第1页 / 共37页
数字系统设计教学资料-第四章时序逻辑电路.ppt_第2页
第2页 / 共37页
数字系统设计教学资料-第四章时序逻辑电路.ppt_第3页
第3页 / 共37页
数字系统设计教学资料-第四章时序逻辑电路.ppt_第4页
第4页 / 共37页
数字系统设计教学资料-第四章时序逻辑电路.ppt_第5页
第5页 / 共37页
点击查看更多>>
资源描述

《数字系统设计教学资料-第四章时序逻辑电路.ppt》由会员分享,可在线阅读,更多相关《数字系统设计教学资料-第四章时序逻辑电路.ppt(37页珍藏版)》请在三一办公上搜索。

1、本章目录,不当的设计实例误用异步复位误用门控时钟误用派生时钟功耗考虑计数器二进制计数器格雷码计数器环形计数器线性反馈移位寄存器(LFSR)寄存器充当快速临时存储,同步设计在设计规模巨大、复杂的系统时是最重要的。在过去,一些非同步的设计实践被用来节约芯片和面积滥用异步复位滥用门控时钟滥用派生时钟,时序电路设计:实践,原则:在寄存器正常工作的时候,不要用复位信号来清空寄存器。这里有一个不太实用的10进制计数器例子,当计数值达到“1010”时,立刻清空计数器。,误用异步复位,误用异步复位,library ieee;use ieee.std_logic_1164.all;use;entity mod1

2、0_counter isport(clk,reset:in std_logic;q:out std_logic_vector(3 downto 0);end mod10_counter;architecture poor_async_arch of mod10_counter issignal r_reg:unsigned(3 downto 0);signal r_next:unsigned(3 downto 0);signal async_clr:std_logic;begin-registerprocess(clk,async_clr)beginif(async_clr=1)then r_

3、reg 0);elsif(clkevent and clk=1)then r_reg=r_next;end if;end process;-asynchronous clear async_clr=1 when(reset=1 or r_reg=1010)else 0;-next state and output logic r_next=r_reg+1;q=std_logic_vector(r_reg);end poor_async_arch;,问题所在:从“1001”到“0000”的跳转时,经过了“1010”状态(如时序图所示)。在驱动aync_clr信号的组合逻辑中,任意的毛刺都会复位计

4、数器不能应用时序分析来决定最大的时钟频率,误用异步复位,因此,异步复位信号只能在上电初始化的时候使用!,补救方法:同步载入“0000”。,误用异步复位,architecture two_seg_arch of mod10_counter issignal r_reg:unsigned(3 downto 0);signal r_next:unsigned(3 downto 0);begin-registerprocess(clk,reset)beginif(reset=1)then r_reg 0);elsif(clkevent and clk=1)then r_reg 0)when r_reg

5、=9 else r_reg+1;-output logic q=std_logic_vector(r_reg);end two_seg_arch;,原则:不能插入逻辑(例如与门)来阻止时钟更新寄存器的值时钟树是一种特殊的设计结构,不能被外部干涉。考虑一个带有使能信号的计数器,一种实现使能的方法是和clk信号相与,如下图所示。,误用门控时钟,使用门控时钟来禁用触发器,存在的问题:en不能改变clk,有可能仅仅是减少触发器时钟的时钟脉冲宽度。如果en易受毛刺影响,计数器可能会比预想的计数要多。由于时钟路径里面存在与门,会影响分布时钟树的构建和分析。,误用门控时钟,下面给出一种简单但不实用的解决方法

6、。,误用门控时钟,library ieee;use ieee.std_logic_1164.all;use;entity binary_counter isport(clk,reset:in std_logic;en:in std_logic;q:out std_logic_vector(3 downto 0);end binary_counter;architecture gated_clk_arch of binary_counter issignal r_reg:unsigned(3 downto 0);signal r_next:unsigned(3 downto 0);signal

7、gated_clk:std_logic;begin-registerprocess(gated_clk,reset)beginif(reset=1)then r_reg 0);elsif(gated_clkevent and gated_clk=1)then r_reg=r_next;end if;end process;-gated clock-poor design practice gated_clk=clk and en;-next-state and output logic r_next=r_reg+1;q=std_logic_vector(r_reg);end gated_clk

8、_arch;,误用门控时钟,architecture two_seg_arch of binary_counter issignal r_reg:unsigned(3 downto 0);signal r_next:unsigned(3 downto 0);begin-registerprocess(clk,reset)beginif(reset=1)then r_reg 0);elsif(clkevent and clk=1)then r_reg=r_next;end if;end process;-next-state logic r_next=r_reg+1 when en=1 else

9、 r_reg;-output logic q=std_logic_vector(r_reg);end two_seg_arch;,下面给出一种更好的解决方法。,存在的问题:子系统可能会运行在不同的时钟频率。,误用派生时钟,原则:不要为一个慢的子系统派生一个慢的时钟,左图的问题在于这个系统不再同步了。派生时钟会增加时序分析的复杂度,致使我们不能再用前面简单的方法来分析了,我们必须把它视为两个不同频率和相位的时钟系统。,考虑一个实现“秒和分的计数器”功能的设计,假设它的输入时钟为1MHz。,误用派生时钟,一个使用派生时钟的设计例子如下:,误用派生时钟,library ieee;use ieee.s

10、td_logic_1164.cb;use;entity timer isport(clk,reset:in std_logic;sec,min:out std_logic_vector(5 downto 0);end timer;architecture multi_clock_arch of timer issignal r_reg:unsigned(19 downto 0);signal r_next:unsigned(19 downto 0);signal s_reg,m_reg:unsigned(5 downto 0);signal s_next,m_next:unsigned(5 d

11、ownto 0);signal sclk,mclk:std_logic;begin-registerprocess(clk,reset)beginif(reset=1)then r_reg 0);elsif(clkevent and clk=1)then r_reg 0)when r_reg=999999 else r_reg+1;-output logic-clock has 50%duty cycle sclk=0 when r_reg 500000 else 1;,一个使用派生时钟的设计例子如下(续),误用派生时钟,-second dividerprocess(sclk,reset)be

12、ginif(reset=1)then s_reg 0);elsif(sclkevent and sclk=1)then s_reg 0)when s_reg=59 else s_reg+1;-output logic(50%duty cycle)mclk 0);elsif(mclkevent and mclk=1)then m_reg 0)when m_reg=59 else m_reg+1;-output logic min=std_logic_vector(m_reg);end multi_clock_arch;,一种更好的使用同步1个时钟脉冲的方法,误用派生时钟,architecture

13、 single_clock_arch of timer issignal r_reg:unsigned(19 downto 0);signal r_next:unsigned(19 downto 0);signal s_reg,m_reg:unsigned(5 downto 0);signal s_next,m_next:unsigned(5 downto 0);signal s_en,m_en:std_logic;begin-registerprocess(clk,reset)beginif(reset=1)then r_reg 0);s_reg 0);m_reg 0);elsif(clke

14、vent and clk=1)then r_reg 0)when r_reg=999999 else r_reg+1;s_en=1 when r_reg=500000 else 0;,一种更好的使用同步1个时钟脉冲的方法(续),误用派生时钟,-next state logic/output logic for second divider s_next 0)when(s_reg=59 and s_en=1)else s_reg+1 when s_en=1 else s_reg;m_en 0)when(m_reg=59 and m_en=1)else m_reg+1 when m_en=1 el

15、se m_reg;-output logic sec=std_logic_vector(s_reg);min=std_logic_vector(m_reg);end single_clock_arch;,功耗现在已经成为一个主要的设计准则在CMOS工艺中,高时钟频率隐含着高速的开关频率,高速的开关频率令动态功耗增加。对时钟进行操作会减少开关转换的频率,但这个不能在寄存器传输层实现。恰当的流程如下:设计、综合、验证常规的同步子系统。使用特殊的电路(例如锁相环)来获得派生时钟使用“功耗优化”的软件工具在一些寄存器上加上门控时钟,功耗考虑,计数器会按照一系列的模式不断重复其内部状态二进制计数器格雷码

16、计数器环形计数器线性反馈移位寄存器(LFSR)BCD码计数器,计数器,状态会根据二进制计数序列来改变使用一个自增器来实现下一个状态,二进制计数器,每一次状态的变换,仅仅改变其中的一位使用一个格雷码自增器,格雷码计数器,library ieee;use ieee.std_logic_1164.all;use;entity gray_counter4 isport(clk,reset:in std_logic;q:out std_logic_vector(3 downto 0);end gray_counter4;architecture arch of gray_counter4 isconst

17、ant WIDTH:natural:=4;signal g_reg:unsigned(WIDTH-1 downto 0);signal g_next,b,b1:unsigned(WIDTH-1 downto 0);begin-registerprocess(clk,reset)beginif(reset=1)then g_reg 0);elsif(clkevent and clk=1)cb g_reg=g_next;end if;end process;-next-state logic-gray to binary b=g_reg xor(0,格雷码计数器,循环移动单个1,例如4位的环形计数

18、器:“1000”“0100”“0010”“0001”,环形计数器,N位的寄存器就有N个模式,输出也是N个相位的信号。在自我错误修复的设计中,“0001”在初始化的时候被插入,library ieee;use ieee.std_logic_1164.all;entity ring_counter isport(clk,reset:in std_logic;q:out std_logic_vector(3 downto 0);end ring_counter;architecture reset_arch of ring_counter isconstant WIDTH:natural:=4;si

19、gnal r_reg:std_logic_vector(WIDTH-1 downto 0);signal r_next:std_logic_vector(WIDTH-1 downto 0);begin-registerprocess(clk,reset)beginif(reset=1)then r_reg 1,others=0);elsif(clkevent and clk=1)then r_reg=r_next;end if;end process;-next-state logic r_next=r_reg(0),环形计数器,在自我错误修复的设计中,必须保证一个“1”总是在环形中循环。可以

20、这样实现:检测高3位,如果高3位为“000”,则利用组合逻辑在它的最低位插入一个“1”。,环形计数器,architecture self_correct_arch of ring_counter isconstant WIDTH:natural:=4;signal r_reg,r_next:std_logic_vector(WIDTH-1 downto 0);signal s_in:std_logic;begin-registerprocess(clk,reset)beginif(reset=1)then-no special input pattern is needed in this v

21、ersion-since the 1 is not circulated-its generated r_reg 0);elsif(clkevent and clk=1)then r_reg=r_next;end if;end process;-next-state logics_in=1 when r_reg(WIDTH-1 downto 1)=000 else 0;r_next=s_in,LFSR是一个带有决定下一系列输入值的异或(XOR)反馈网络移位寄存器仅有一部分的寄存器的位被用来进行异或操作,如果位的选择恰当,N位的寄存器组成的LFSR可以设计为2n-1个状态循环。下面是一个4位的L

22、FSR。,线性反馈移位寄存器(LFSR),“1000”“0100”“0010”“1001”“1100”“0110”“1011”“0101”“1010”“1101”“1110”“1111”“0111”“0011”“0001”,需要注意的是“0000”并没有包含其中,如果出现了,则LFSR会被阻塞,LFSR的特性来源于有限域的理论因为反馈表达式用AND和XOR操作来表示,所以使用线性项定义一个线性代数系统。除了“2n-1个状态”的性质之外,LFSR还具有以下性质:对于任意n,反馈网络都会生成最大的状态数目。输出的序列是伪随机的,存在一定的统计特性和随机特性,线性反馈移位寄存器(LFSR),LFSR

23、的应用伪随机序列:用于测试数据的编码和解码简单的“next-state logic”计数器例如,一个128位的LFSR使用3个XOR门可以产生2128-1种模式,对于一个100GHz的系统,需要1012年的时间,线性反馈移位寄存器(LFSR),library ieee;use ieee.std_logic_1164.all;entity lfsr4 isport(clk,reset:in std_logic;q:out std_logic_vector(3 downto 0);end lfsr4;architecture no_zero_arch of lfsr4 issignal r_reg

24、,r_next:std_logic_vector(3 downto 0);signal fb:std_logic;constant SEED:std_logic_vector(3 downto 0):=0001;begin-registerprocess(clk,reset)beginif(reset=1)then r_reg=SEED;elsif(clkevent and clk=1)then r_reg=r_next;end if;end process;-next-state logic fb=r_reg(1)xor r_reg(0);r_next=fb,线性反馈移位寄存器(LFSR),

25、下面将利用二进制计数器来实现PWM调制。脉宽调试(PWM)占空比:信号有效所占的时间百分比,计数器应用例子,PWM使用一个信号w来表示占空比:当w不为“0000”时,占空比为w/16当w为“0000”时,占空比为16/16,计数器应用例子,library ieee;use ieee.std_logic_1164.all;use;entity pwm isport(clk,reset:in std_logic;w:in std_logic_vector(3 downto 0);pwm_pulse:out std_logic);end pwm;architecture two_seg_arch o

26、f pwm issignal r_reg:unsigned(3 downto 0);signal r_next:unsigned(3 downto 0);signal buf_reg:std_logic;signal buf_next:std_logic;begin-register,寄存器由于体积太大而不能作为大存储空间。而RAM因为其体积较小,更适合用来作为较大的存储空间。寄存器在数字系统中,通常用来构建小而快速的临时存储空间,例如:寄存器文件,寄存器充当快速临时存储,寄存器文件寄存器以一维排列每个寄存器以地址作为标识通常有一个写入端口(带有使能信号)和两个或者更多的读取端口,寄存器文件,

27、作为例子,下图为一个带有1个写入端口,两个读取端口的4字大小的寄存器文件,寄存器文件,译码器decoder用来分配使能信号,选择器Mux用来选择输出的数据。,寄存器文件,译码器电路的工作方式如下:当wr_en=0时,输出“0000”当wr_en=1时,根据w_addr的值使某一位有效,library ieee;use ieee.std_logic_1164.all;entity reg_file isport(clk,reset:in std_logic;wr_en:in std_logic;w_addr:in std_logic_vector(1 downto 0);w_data:in st

28、d_logic_vector(15 downto 0);r_addr0,r_addr1:in std_logic_vector(1 downto 0);r_data0,r_data1:out std_logic_vector(15 downto 0);end reg_file;architecture no_loop_arch of reg_file isconstant W:natural:=2;-#of bits in addressconstant B:natural:=16;-#of bits in datatype reg_file_type is array(2*W-1 downt

29、o 0)of std_logic_vector(B-1 downto 0);signal array_reg:reg_file_type;signal array_next:reg_file_type;signal en:std_logic_vector(2*W-1 downto 0);,寄存器文件(一),begin-registerprocess(clk,reset)beginif(reset=1)then array_reg(3)0);array_reg(2)0);array_reg(1)0);array_reg(0)0);elsif(clkevent and clk=1)then arr

30、ay_reg(3)=array_next(3);array_reg(2)=array_next(2);array_reg(1)=array_next(1);array_reg(0)=array_next(0);end if;end process;-enable logic for registerprocess(array_reg,en,w_data)begin array_next(3)=array_reg(3);array_next(2)=array_reg(2);array_next(1)=array_reg(1);array_next(0)=array_reg(0);if(en(3)

31、=1)then array_next(3)=w_data;end if;if(en(2)=1)then array_next(2)=w_data;end if;if(en(1)=1)then array_next(1)=w_data;end if;if(en(0)=1)then array_next(0)=w_data;end if;end process;,寄存器文件(二),-decoding for write addressprocess(wr_en,w_addr)beginif(wr_en=0)then en 0);elsecase w_addr iswhen 00=en en en

32、en=1000;end case;end if;end process;-read multiplexingwith r_addr0 select r_data0=array_reg(0)when 00,array_reg(1)when 01,array_reg(2)when 10,array_reg(3)when others;with r_addr1 select r_data1=array_reg(0)when 00,array_reg(1)when 01,array_reg(2)when 10,array_reg(3)when others;end no_loop_arch;,寄存器文件(三),

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号