41
Lecture 7 Chap 9: Registers Instructors: Fu-Chiung Cheng ( 鄭鄭鄭 ) Associate Professor Computer Science & Engineering Tatung University

Lecture 7 Chap 9: Registers

  • Upload
    sezja

  • View
    52

  • Download
    0

Embed Size (px)

DESCRIPTION

Lecture 7 Chap 9: Registers. Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University. Registers. registers: a flip-flop or a bank of flip-flops with comon control The register is contained within the process statement. - PowerPoint PPT Presentation

Citation preview

Page 1: Lecture 7 Chap 9: Registers

Lecture 7Chap 9: Registers

Instructors: Fu-Chiung Cheng

(鄭福炯 )Associate Professor

Computer Science & EngineeringTatung University

Page 2: Lecture 7 Chap 9: Registers

Registers

• registers: a flip-flop or a bank of flip-flops with comon control• The register is contained within the process statement.• Register: match the template wait until ck’event and ck = ‘1’;• Example:

Page 3: Lecture 7 Chap 9: Registers

library ieee;use ieee.std_logic_1164.all;

entity Dtype is port(d, ck: in std_logic;

q: out std_logic);end;architecture behavior of Dtype isbegin process begin

wait until ck’event and ck=‘1’;q <= d;

end process;end;

Page 4: Lecture 7 Chap 9: Registers

Registers: simulation model

• wait statement syntax: wait on sensitivity-list until condition;• Thus

wait until ck’event and ck=‘1’;= wait on ck until ck’event and ck=‘1’;• Operation: A. the wait statement is activated by an event. B. the until condition is tested

true: process executionfalse: wait statement is deactivated.

(process remain suspended)

Page 5: Lecture 7 Chap 9: Registers

Registers: redundancy?

• The following example:wait until ck’event and ck=‘1’;

= wait on ck until ck’event and ck=‘1’;• the process will be executed once when ck =‘1’ and ck has a transition = (the rising edge on ck )• Redundancy:

wait on ck until ck’event and ck=‘1’; “ck’event” and “ on ck” (ck is in the sensitivity list) means the same thing. However, synthesis tools need to match this pattern (register template) to recognize a register process.

Page 6: Lecture 7 Chap 9: Registers

Registers: synthesis model

• Hardware implementation: an edge-triggered register• register process = a block of combinational logic(CL) +

registers on every output of the CL• All signal assignments in a registered process result in in registers on those target signals. • Note that a latched process can have both latched and combinational outputs.

Page 7: Lecture 7 Chap 9: Registers

Registers

• register process:

process begin

wait until ck’event and ck=‘1’;z <= a and b;

end process;

D F/F

ab

ck

z

-- compare to this process begin

wait on a, b;z <= a and b;

end process;

Page 8: Lecture 7 Chap 9: Registers

Register Templates: basic

• Basic Template: A: implicit on clause process begin

wait until ck’event and ck=‘1’;q <= d;

end process; B. explicit on clause:

wait on ck until ck’event and ck=‘1’;

Page 9: Lecture 7 Chap 9: Registers

Register Templates: short

• Short Template: (the most compact form of registered process) process begin

wait until ck=‘1’;q <= d;

end process;• Note that the least likely to be recognized by all synthesisers.• Explicit on clause:

wait on ck until ck=‘1’;

Page 10: Lecture 7 Chap 9: Registers

Register Templates: if statement

• if statement Template: process begin

wait on ckif ck’event and ck=‘1’ then q <= d;end if;

end process;• ck’event may be removed.

if ck=‘1’ then …• asynchronous reset (see section 9.8).

Page 11: Lecture 7 Chap 9: Registers

Register Templates: sensitivity list

• sensitivity list Template: process (ck) begin

if ck’event and ck=‘1’ then q <= d;end if;

end process;• ck’event may be removed.

if ck=‘1’ then …

wait on ck;

Page 12: Lecture 7 Chap 9: Registers

Register: active edge

• falling-edge sensitivity register: process begin

wait until ck=‘0’; q <= d;

end process;• testing the rising or falling edge: rising edge: 0 --> 1 but how about x --> 1? • Rising-edge trigger process: wait until ck’event and ck=‘1’ and ck’last_value=‘0’;• Check synthesiser documentation.

Page 13: Lecture 7 Chap 9: Registers

Register: active edge

• All signals are initialized with the leftmost value of the type. Signal ck: std_logic; • The leftmost value of std_logic is ‘U’. This may cause false triggering of registers • Preventing false triggering by initialization:

Signal ck: std_logic:=‘0’; Signal ck: std_logic:=‘1’;

• Note that std_logic_1164 defines two functions wait on rising_edge(ck); wait on falling_edge(ck);• Not all tool support these functions.

Page 14: Lecture 7 Chap 9: Registers

Registers of other types

• signal being registered can be: A. 1-bit signal B. integer (Ex. Counter) C. enumeration (Ex. State machines) D. array type (Ex. Buses) E. record type (Ex buses split into fields.)• Example:

Page 15: Lecture 7 Chap 9: Registers

library ieee;use ieee.std_logic_1164.all, ieee.numeric_std.all;entity Dtype is port(d: in signed(7 downto 0);

ck: in std_logic; q: out signed(7 downto 0));

end;architecture behavior of Dtype is begin process begin

wait on ck until ck=‘1’;q <= d; -- 8-bit register

end process;end;

Page 16: Lecture 7 Chap 9: Registers

Registers of other types

• any number of signals can be registered in the same registered process. Example:

process begin

wait on ck until ck=‘1’;q0 <= d0;q1 <= d1;q2 <= d2;

end process;

Page 17: Lecture 7 Chap 9: Registers

Clock types

• So far all the examples have used a clock which is of type std_logic. • Other logic types are OK for clock signal: A. bit B. boolean

Page 18: Lecture 7 Chap 9: Registers

Gated Registers

• So far all the registers have been ungated.• In practice, it is very rare for a register to be ungated. A. clock gating -- in general not OK, rare B. data gating

Page 19: Lecture 7 Chap 9: Registers

Clock Gating

• In clock gating the clock signal is switched on or off by some other control signals. -- save power• Clock gating is sometimes used in hand-crafted design.• It is rarely used and considered bad practice to use clock gating in synthesisable design.• Two reasons: A. Testing: (synchronous design) scan paths with built-in test patten generation to give a complete test. Scan techniques require directly control the clocks. B. Glitches: logic synthesis for logic minimization can not guarantee glitch-free logic. Glitches in the control signals would be disastrous.

Page 20: Lecture 7 Chap 9: Registers

Glitches (Hazards)

• Static hazards:

• Dynamic hazards

O

1

O

1 1

O

Static 0 hazard Static 1 hazard

Page 21: Lecture 7 Chap 9: Registers

Glitches (Hazards)

Page 22: Lecture 7 Chap 9: Registers

Clock gating

• Clock gating is often used in low-power circuits.• Clock gating is used to effectively disable a register or a register bank.• If clock gating is used, User has to check that synthesized clock circuits are safe.• Example:

Page 23: Lecture 7 Chap 9: Registers

library ieee;use ieee.std_logic_1164.all;entity GDtype is port(d, en, ck: in std_logic; q: out std_logic);end;architecture behavior of GDtype is signal cken: std_logic;begin cken <= ck when en = ‘1’ else ‘1’; -- clock gating process begin

wait until cken’event and cken=‘1’;q <= d;

end process;end;

D F/Fen

ck

d

q

Page 24: Lecture 7 Chap 9: Registers

Data gating

• Data gating controls the data input of the register.• Hardware implementation: multiplexer• Example:

Page 25: Lecture 7 Chap 9: Registers

library ieee;use ieee.std_logic_1164.all;entity DGDtype is port(d, en, ck: in std_logic; q: out std_logic);end;architecture behavior of DGDtype is begin process begin

wait until ck’event and ck=‘1’;if en = ‘1’ then -- data q <= d; -- gatingend if;

end process;end;

D F/F

d

ck

q

MU

X

en

Page 26: Lecture 7 Chap 9: Registers

Data gating

• common pitfall: don’t combine if statements if ck’event and ck=‘1’ then;

if en = ‘1’ then -- data gating q <= d; end if;

endif ;• Not OK: (register template ??)

if ck’event and ck=‘1’ and en = ‘1’ then q <= d;

endif ;

Page 27: Lecture 7 Chap 9: Registers

Resettable Registers

• Register reset: Asynchronous and synchronous• Asynchronous resets: A. override the clock and act immediately to change the value of the register. B. global system-level resets enforced from off-chip C. sensitive to glitches (asynchronous reset controls are in effect always.)• Synchronous resets: A. take effect on the active edge of the clock B. insensitive to glitches

Page 28: Lecture 7 Chap 9: Registers

Asynchronous Reset

• Asynchronous resets require special register template• Many different ways to write models that act like asynchronous resets during simulation • Only those that conform to the templates will be synthesisable.• The templates vary from synthesizer to synthesizer.• Example

Page 29: Lecture 7 Chap 9: Registers

Asynchronous Reset

• An asynchronous reset example: process(ck,rst) begin if rst = ‘1’ then

q <=0; elsif ck’event and ck=‘1’ then;

q <= d; end if; end;

D F/F

rst

ck

d

q

clear

Page 30: Lecture 7 Chap 9: Registers

Asynchronous Reset

• Some synthesizer requires attributed entity to declare an asynchronous reset example:library ieee;use ieee.std_logic_1164.all;library synthesis;use synthesis.attributes.all;entity RDtype is port(d, rst, ck: in std_logic; q: out std_logic); attribute signal_kind of ck: signal is clock; attribute signal_kind of rst: signal is set_reset;end;

Page 31: Lecture 7 Chap 9: Registers

Asynchronous Reset

• Reset value can be any constant value. process(ck,rst) begin if rst = ‘1’ then

q <= to_unsigned(10, q’length); elsif ck’event and ck=‘1’ then;

q <= d; end if; end;

D F/F

set

clear

D F/F

set

clear

D F/F

set

clear

D F/F

set

clear

rst

Page 32: Lecture 7 Chap 9: Registers

Asynchronous Set and Reset

• Asynchronous set and reset controls may not be synthesisable. process(ck,rst, set) begin if rst = ‘1’ then

q <= ‘0’; elsif set = ‘1’ then

q <= ‘1’; else ck’event and ck=‘1’ then;

q <= d; end if; end;

Page 33: Lecture 7 Chap 9: Registers

Resettable Counter

• module-16 counter signal ck, rst: std_logic; signal q: unsigned( 3 downto 0); …. process(ck,rst) begin if rst = ‘1’ then

count <= to_unsigned(0, count’length); elsif ck’event and ck=‘1’ then;

count <= count +1; end if; end;

Page 34: Lecture 7 Chap 9: Registers

Synchronous Reset

signal d, ck, rst: std_logic; signal q: std_logic; …. process begin wait until ck’event and ck=‘1’; if rst = ‘1’ then

q <= 0; else;

q <= d; end if;

end;

D F/F

0

ck

qM

UX

rst

d

Page 35: Lecture 7 Chap 9: Registers

signal d: unsigned(2 downto 0); signal ck, rst: in std_logic; signal q: out unsigned(2 downto 0); …. process begin wait until ck’event and ck=‘1’; if rst = ‘1’ then

q <= to_unsigned(5, q’length); else;

q <= d; end if;

end;

D F/F

1

ckq(2)

MU

X

d(2)

rst

D F/F

0

ck

MU

X

d(1)

rst

q(1)D F/F

1

ck

MU

X

d(0)

rst

q(0)

Page 36: Lecture 7 Chap 9: Registers

Synchronous Resettable Counter signal ck, rst: std_logic; signal q: unsigned(3 downto 0); …. process (ck) begin if ck’event and ck=‘1’ then; if rst = ‘1’ then

count <= to_unsigned(0, count’length); else

count <= count+1; endifend if;

end;

Page 37: Lecture 7 Chap 9: Registers

Simulation model of Asynchronous Reset

• Asynchronous reset behavior is more complex. process (ck, rst) begin if rst=‘1’ then; q <= ‘0’; elsif ck’event and ck=‘1’ then

q <= d; end if;

end; • two signals, ck (the clock signal) and rst (asynchronous reset signal) are in the sensitivity list.

Page 38: Lecture 7 Chap 9: Registers

Simulation model of Asynchronous Reset

• if rst goes high, q will be reset to zero.• If ck goes high, q will be set to d.• If both rst and ck go high then reset signal overrides the clock signal• Note that asynchronous reset acts as a level sensitive control signal. The reset is activated immediately and is not synchronized with the clock.• VHDL synthesizers recognize an asynchronous reset by matching an asynchronous reset template.

Page 39: Lecture 7 Chap 9: Registers

Asynchronous Reset Templates

• Asynchronous reset templates: A. sensitivity-list template process (ck, rst) begin if rst=‘1’ then; q <= ‘0’; elsif ck’event and ck=‘1’ then

q <= d; end if;

end;

Page 40: Lecture 7 Chap 9: Registers

Asynchronous Reset Templates

• Asynchronous reset templates: B. if-statement template process begin

wait on ck, rst; if rst=‘1’ then; q <= ‘0’; elsif ck’event and ck=‘1’ then

q <= d; end if;

end;

Page 41: Lecture 7 Chap 9: Registers

Registered Variables

process variable count : unsigned(7 downto 0); begin

wait until ck’event and ck=‘1’; if rst = ‘1’ then

count := to_unsigned(0, count’length); else

count := count+1; end if;result <= count; -- two registers are created

end;