设计中心
电子设计自动化技术
教师:李平教授(博导)
Email: pli@uestc.edu.cn
Tel: 83201794
设计中心
电子设计自动化技术
第七章
组合逻辑电路设计
时序逻辑电路设计
设计中心
内容提要
?组合逻辑电路设计
?时序逻辑电路设计
设计中心
Recall: Combinatorial Logic
? Combinatorial Logic if
– Outputs at a specified time are a function
only of the inputs at that time
? e.g. decoders, multiplexers and adders
Output change
instantly when
input change
设计中心
组合逻辑电路设计实例
?简单门电路(例7—1,2,3,4)
?加法器(作业……)
?编码译码器(例7—5,6)
?多路处理器(例7—7,8)
设计中心
简单门电路设计
?三输入与门
方法一:布尔表达式
方法二:逻辑真值描述
设计中心
方法一:布尔表达式
LIBRARY IEEE;
USE IEEE.STD_LOG1C_1164.ALL;
ENTITY and3 IS
PORT (a, b, c : IN STD_LOGIC;
y : OUT STD_LOGIC);
END and3;
ARCHITECTURE and3_1 OF and3 IS
BEGIN
y <= (a AND b AND c) ;
END and3_1;
设计中心
方法二:逻辑真值描述
LIBRARY IEEE;
USE IEEE STD_LOGIC_1164.ALL;
ENTITY and3 IS
PORT (a,b,c : IN STD_LOGIC;
y : OUT STD_LOGIC);
END and3;
ARCHITECTURE and3_2 OF and3 IS
BEGIN
t4: PROCESS (a,b,c)
VARIABLE comb:STD_LOGIC_VECTOR(2 DOWNTO 0);
BEGIN
comb := a & b & c;
设计中心
方法二:逻辑真值描述(续)
CASE comb IS
WHEN “000” => y <=‘0’;
WHEN “001” => y <=‘0’;
WHEN “010” => y <=‘0’;
WHEN “011” => y <=‘0’;
WHEN “100” => y <=‘0’;
WHEN “101” => y <=‘0’;
WHEN “110” => y <=‘0’;
WHEN “111” => y <=‘1’;
WHEN OTHERS=> y <=‘X’;
END CASE;
END PROCESS;
END and3_2;
设计中心
编码译码器设计
?三八译码器
?优先级编码器
设计中心
三八译码器(P.86)
?第一步:端口?实体设计……
y0
y1
y2
y3
y4
y5
y6
y7
a
b
c
三
八
译
码
器
y0
y1
y2
y3
y4
y5
y6
y7
a
b
c
gl
g2a
g2b
74LS138
100选通
设计中心
三八译码器
的实体设计
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY decoder_3_to_8 IS
PORT (a, b, c, g1, g2a, g2b : IN STD_LOGIC;
y : OUT STD_LOGIC_VECTOR(7 DOWNTO 0));
END decoder_3_to_8;
y0
y1
y2
y3
y4
y5
y6
y7
a
b
c
gl
g2a
g2b
74LS138
设计中心
?第二步:算法?构造体设计……
选通输入输入端译码输入端
g1 g2a g2b c b a y0 y1 y2 y3 y4 y5 y6 y7
x
x
0
1
1
1
1
1
1
1
1
1
x
x
0
0
0
0
0
0
0
0
x
1
x
0
0
0
0
0
0
0
0
x
x
x
0
0
0
0
1
1
1
1
x
x
x
0
0
1
1
0
0
1
1
x
x
x
0
1
0
1
0
1
0
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
设计中心
译码功能描述
CASE indata IS
WHEN “000”=> y <= “11111110”;
WHEN “001”=> y <= “11111101”;
WHEN “010”=> y <= “11111011”;
WHEN “011”=> y <= “11110111”;
WHEN “100”=> y <= “11101111”;
WHEN “101”=> y <= “11011111”;
WHEN “110”=> y <= “10111111”;
WHEN “111”=> y <= “01111111”;
WHEN OTHERS=> y <= “XXXXXXXX”;
END CASE;
设计中心
三八译码器构造体
ARCHITECTURE rtl OF decoder_3_to_8 IS
SIGHAL indata : STD_LOGIC_VECTOR(2 DOWNTO 0);
BEGIN
indata <= c & b & a;
PROCESS(indata,g1,g2a,g2b)
BEGIN
IF (g1=’1’ AND g2a=’0’ AND g2b=’0’) THEN
CASE……
ELSE
y <= ”11111111”;
END IF;
END PROCESS;
END rt1;
设计中心
优先级编码器(P.88)
?第一步:端口?实体设计……
input0
input1
input2
input3
input4
input5
input6
input7
y0
y2
y1
74LS148
设计中心
优先级编码器
的实体设计
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY priorityencoder IS
PORT (input : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
y : OUT STD_LOGIC_VECTOR (2 DOWNTO 0));
END priorityencoder;
input0
input1
input2
input3
input4
input5
input6
input7
y0
y2
y1
74LS148
设计中心
?第二步:算法?构造体设计…… (优先级)
输入编码输出
Input
(7)
Input
(6)
Input
(5)
Input
(4)
Input
(3)
Input
(2)
Input
(1)
Input
(0)
y2 y1 y0
xxxxxxx0 111
xxxxxx0 1 110
xxxxx0 11101
xxxx0 111100
xxx0 1111011
xx0 11111010
x 0 111111001
x1111111000
设计中心
编码功能描述
PROCESS (input)
BEGIN
IF (input(0)=‘0’) THEN y <=“111”;
ELSIF (input(1)=‘0’) THEN y <=“110”;
ELSIF (input(2)=‘0’) THEN y <=“101”;
ELSIF (input(3)=‘0’) THEN y <=“100”;
ELSIF (input(4)=‘0’) THEN y <=“011”;
ELSIF (input(5)=‘0’) THEN y <=“010”;
ELSIF (input(6)=‘0’) THEN y <=“001”;
ELSE y <=“000”;
END IF;
END PROCESS;
设计中心
Recall: Case Statement
Example:
PROCESS(sel, a, b, c, d)
BEGIN
CASE sel IS
WHEN “00” =>
q <= a;
WHEN “01” =>
q <= b;
WHEN “10” =>
q <= c;
WHEN OTHERS =>
q <= d;
END CASE;
END PROCESS;
sel
a
b
c
d
2
q
设计中心
Recall: Case Statement
? Conditions are evaluated at once
– No Prioritization
? All possible conditions must be
considered
? WHEN OTHERS clause evaluates all
other possible conditions that are not
specifically stated.
设计中心
Recall: If-Then Statements
Example:
PROCESS(sela, selb, a, b, c)
BEGIN
IF sela=‘1’ THEN
q <= a;
ELSIF selb=‘1’ THEN
q <= b;
ELSE
q <= c;
END IF;
END PROCESS;
sela
c
b
a
selb
q
设计中心
Recall: If-Then Statements
? Conditions are evaluated in order from top to
bottom
– Prioritization
? The first condition, that is true, causes the
corresponding sequence of statements to be
executed.
? If all conditions are false, then the sequence of
statements associated with the “ELSE” clause
is evaluated.
设计中心
多路处理器设计
?四选一选择器
?交通灯状态监测器
设计中心
交通灯信号原理图
RY G
停车
注意
通行
red
yellow
green
error
设计中心
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY rgy IS
PORT (red, green, yellow : IN STD_LOGIC;
error : OUT STD_LOGIC);
END rgy;
red
yellow
green
error
设计中心
ARCHITECTURE rtl OF rgy IS
BEGIN
PROCESS (red, green, yellow)
VARIABLE internal : STD_LOGIC_VECTOR(2 DOWNTO 0);
BEGIN
internal := red & green & yellow;
CASE internal IS
WHEN "001"=> error<='0';
WHEN "010"=> error<='0';
WHEN "100"=> error<='0';
WHEN OTHERS=> error<='1';
END CASE;
END PROCESS;
END rtl;
设计中心
内容提要
?组合逻辑电路设计
?时序逻辑电路设计
设计中心
Recall: Sequential Logic
? Sequential Logic if
– Outputs at a specified time are a function of the inputs at
that time and at all preceding times
– All sequential circuits must include one or more registers
? e.g. State Machine, Counters, Shift Register and Controllers
Outputs depends
on inputs and
previous output
Register is used to hold the previous value
设计中心
时序逻辑电路设计实例
?基本概念(例7—9,10,11,12,13)
?触发器(例7—14,15,16,17,18)
?寄存器(例7—19)
?存储器(例7—20,21)
设计中心
基本概念
?时钟信号、复位控制信号
?进程的敏感信号与wait语句的关系
?时钟边沿描述
?触发器的同步和非同步复位
?组合逻辑进程、时序逻辑进程
设计中心
进程的等效描述
?敏感信号(sensitive signals)与WAIT ON
process (a, b, cin) process
begin begin
sum <= a XOR b XOR cin; sum <= a XOR b XOR cin;
end process; wait on a, b, cin;
end process;
NOTE:
如果使用了sensitivity_list,在process中就不能使用WAIT语句
如果使用了WAIT语句,在process中就不能使用sensitivity_list
设计中心
How Many Registers?
ENTITY reg1 IS
PORT ( d, clk : in BIT; q : out BIT);
END reg1;
ARCHITECTURE reg1 OF reg1 IS
SIGNAL a, b : BIT;
BEGIN
PROCESS (clk)
BEGIN
IF rising_edge(clk) THEN
a <= d;
b <= a;
q <= b;
END IF;
END PROCESS;
END reg1;
rising_edge
– IEEE function that is
defined in the
std_logic_1164 package
– specifies that the signal
value must be 0 to 1
– X, Z to 1 transition is
not allowed
设计中心
? clk’event and clk=‘1’
– clk is the signal name (any name)
– ‘event is a VHDL attribute,
specifying that there needs to be a
change in signal value
– event is a change in value: from 0 to 1;
or from X to 1, etc
– clk=‘1’ means positive-edge triggered
RECALL
设计中心
复位信号
?同步复位
当复位信号有效且在给定的
时钟边沿到来时,触发器才
被复位
?非同步复位
一旦复位信号有效,触发器
就被复位
D Q
ENA
CLRN
设计中心
Two Types of Process Statements
? Combinatorial Process
– Sensitive to all inputs used in
the combinatorial logic
Example: PROCESS(a, b, sel)
? Sequential Process
– Sensitive to a clock or/and
control signals
Example: PROCESS(clr, clk)
sel
b
a
q
d
clk
clr
q
D Q
ENA
CLRN
设计中心
触发器设计
? D触发器示例
D Q
CLK
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY dff1 IS
PORT (clk,d : IN STD_LOGIC;
q : OUT STD_LOGIC);
END dff1;
设计中心
D触发器描述一
ARCHITECTURE rtl OF dff1 IS
BEGIN
PROCESS(clk)
BEGIN
IF (clk’EVENT AND clk=’1’) THEN
q <= d;
END IF;
END PROCESS;
END rtl;
设计中心
D触发器描述二
ARCHITECTURE rtl 0F dff1 IS
BEGIN
PROCESS
BEGIN
WAIT UNTIL clk’EVENT AND clk=’1’;
q<=d;
END PROCESS:
END rtl ;
设计中心
Compare IF-THEN-ELSE vs WATI UNTIL
LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
ENTITY tdff IS
PORT(clk, d: in std_logic;
q : out std_logic);
END tdff;
architecture behaviour OF tdff IS
BEGIN
PROCESS
BEGIN
wait until clk = '1';
q <= d;
END PROCESS;
END behaviour;
Entity test1 is
port (clk, d : in bit;
q : out bit);
end test1;
architecture test1_b of test1 is
begin
process (clk)
begin
if (clk = ‘1’) then
q <= d;
end if;
end process;
end test1_b;
Entity test1 is
port (clk, d : in bit;
q : out bit);
end test1;
architecture test1_b of test1 is
begin
process (clk,d)
begin
if (clk = ‘1’ and clk’event) then
q <= d;
end if;
end process;
end test1_b;
设计中心
非同步复位D触发器
PROCESS(clk, clr)
BEGIN
IF(clr=’0’)THEN
q <= '0';
ELSIF (clk'EVENT AND clk=’1’) THEN
q <= d;
END IF;
END PROCESS;
D Q
CLK
CLR
设计中心
同步复位D触发器
PROCESS(clk)
BEGIN
IF (clk’EVENT AND clk=’1’)THEN
IF (clr=’1’)THEN
q<=’0’;
ELSE
q<=d;
END IF;
END IF;
END PROCESS;
D Q
CLK
CLR
设计中心
寄存器的设计
?例7-19(P.102)
COMPONENT
GENERATE
? recall
设计中心
How Many Registers?
ENTITY reg1 IS
PORT ( d, clk : in BIT; q : out BIT);
END reg1;
ARCHITECTURE reg1 OF reg1 IS
SIGNAL a, b : BIT;
BEGIN
PROCESS (clk)
BEGIN
IF rising_edge(clk) THEN
a <= d;
b <= a;
q <= b;
END IF;
END PROCESS;
END reg1;
设计中心
How Many Registers?
? Signal Assignments inside the IF-THEN
statement that checks the clock condition
infer registers.
D Q
ENA
CLRN
D Q
ENA
CLRN
D Q
ENA
CLRN
d
ba
q
clk clk
clk
设计中心
存储器的设计
? ROM 例7-20
? RAM 例7-21
设计中心
256×4
ROM
adr(0)
adr(1)
adr(2)
adr(3)
adr(4)
adr(5)
adr(6)
adr(7)
g2
g1
dout(0)
dout(1)
dout(2)
dout(3)
adr
7 DOWNTO 0
dout
3 DOWNTO 0
设计中心
ROM的实体
LIBRARY IEEE;
USE IEEE .STD_LOGIC_1164.ALL;
ENTITY rom24s10 IS
PORT (g1, g2 : IN STD_LOGIC;
adr : IN STD_LOGIC_VECTOR (7 DOWNTO 0);
dout : OUT STD_LOGIC_VECTOR (3 DOWNTO 0));
END rom24s10;
设计中心
256×4
ROM
dout(3)
adr(0)
adr(1)
adr(2)
adr(3)
adr(4)
adr(5)
adr(6)
adr(7)
g2
g1
dout(0)
dout(1)
dout(2)
dout(0)
dout(1)
dout(2)
dout(3)
01100010101…
…
256×1
256×1
256×1
256×1
word(3 DOWNTO 0)
memory(0 TO 255)
adr_in : INTEGER
设计中心
ARCHITECTURE behav OF rom24s10 IS
SUBTYPE word IS STD_LOGC_VECTOR(3 DOWNTO 0);
TYPE memory IS ARRAY(0 TO 255)OF word;
SIGNAL adr_in : INTEGER RANGE 0 TO 255;
FILE romin : TEXT IS IN “rom24s10.in”;
BEGIN
PROCESS(g1,g2,adr)
VARIBLE rom : memory;
VARIBLE startup : BOOLEAN := TRUE;
VARIBLE l : LINE;
VARIBLE j : INTEGER;
设计中心
BEGIN
IF startup THEN ――初始化开始
FOR j IN rom’RANGE LOOP
READLINE(romin, l); ――读一行
READ(l,rom(j)); ――读行中具体数据
END LOOP;
Startup :=FALSE;
END IF;――初始化完毕
设计中心
adr_in<=CONV_INTEGER(adr);
IF (g1='1' AND g2='1') THEN
dout<=rom(adr_in);
ELSE
dout<="ZZZZ";
END IF;
END PROCESS;
END behav;
设计中心
作业