Docsity

VHDL Code for Combinational Logic Design with Process Statements - Prof. David Hwang, Study notes of Digital Systems Design

Partial preview of the text

Download VHDL Code for Combinational Logic Design with Process Statements - Prof. David Hwang and more Study notes Digital Systems Design in PDF only on Docsity!

ECE 545—Digital System Design with VHDL

Lecture 8

Combinational Logic with Process Statements

VHDL Simulation: Signals vs. Variables

Midterm Review

Outline

  • Behavioral VHDL Coding for Synthesis
    • Coding for Combinational Logic using Process

Statements

  • Majority Function
  • Mux with don't cares
  • Priority Encoder
  • VHDL Timing: Signals vs. Variables

Resources

  • Volnei A. Pedroni, Circuit Design with VHDL
    • Chapter 6, Sequential Code
    • Chapter 7, Signals and Variables

VHDL Design Styles (Architecture)

STRUCTURAL

components and interconnects

VHDL Design Styles

DATAFLOW

“concurrent” statements (^) • Sequential Logic

(registers,
counters)
  • State machines
(FSMs, ASMs)
  • Complex Comb.
Logic

“sequential” statements

NON-

SYNTHESIZABLESYNTHESIZABLE

BEHAVIORAL

  • Test Benches
  • Gates^ •^ Modeling IP
  • Simple Comb.
Logic

Majority Gate

3-input majority function

A B C F

  • Logical expression form

F = A B + B C + A C

Majority Gate—Dataflow

library IEEE; use IEEE.STD_LOGIC_1164.all;

entity majority1 is port( a : in STD_LOGIC; b : in STD_LOGIC; c : in STD_LOGIC; f : out STD_LOGIC ); end majority1;

architecture dataflow of majority1 is begin f <= (a and b) or (a and c) or (b and c); end dataflow;

Testbench

library ieee; use ieee.std_logic_1164.all;

entity majority1_tb is end majority1_tb;

architecture TB_ARCHITECTURE of majority1_tb is

component majority port( a : in std_logic; b : in std_logic; c : in std_logic; f : out std_logic ); end component;

signal a : std_logic := '0'; signal b : std_logic := '0'; signal c : std_logic := '0'; signal f : std_logic;

Testbench cont'd

begin

UUT : majority1 port map (a => a, b => b, c => c, f => f);

process begin for i in 0 to 1 loop for j in 0 to 1 loop for k in 0 to 1 loop wait for 10 ns; c <= not c; end loop; b <= not b; end loop; a <= not a; end loop; wait; end process;

end TB_ARCHITECTURE;

Testbench—Another Method cont'd

begin UUT : majority1 port map (a => a, b => b, c => c, f => f);

a <= inputvec(2); -- assign ports b <= inputvec(1); c <= inputvec(0); process begin inputvec <= "000"; -- initialize for i in 0 to 7 loop wait for 10 ns; inputvec <= inputvec + 1; end loop; wait; end process;

end TB_ARCHITECTURE;

Combinational Logic Using Process Statements

  • Combinational logic blocks can be designed using

behavioral code

  • When behavioral code mentioned, this means PROCESS statements
  • Three important things to remember to prevent

mistakes modeling combinational logic using process

statements

1. Make sure all inputs (all things on right-hand side of an equation) are listed in process sensitivity list  **MISTAKE # 1

  1. Make sure all signal outputs have a default assignment (or** else may get a latch). Outputs should always get assigned some value for any input  **MISTAKE #
  2. Remember that the statements in a process statement are** sequential, so orders matters!  MISTAKE #

Examples illustrate mistakes

  • The following examples will illustrate some common

mistakes

  • All examples use signals only, not variables
  • Show correct example followed by mistakes
    • Majority function  mistake #1, mistake #
    • Mux with don't cares  mistake #
    • Priority Encoder  mistake #

Majority Function with Process Statements

Waveform – Error # 1

Error: should be '1'

  • Sometimes synthesis tool will find these
  • Synplicity gives WARNINGS (in blue) to let us know it may have done something we did not intend it to do:
@W: CG296 … Incomplete sensitivity list - assuming completeness
@W: CG290 … Referenced variable c is not in sensitivity list

Pre-Synthesis Simulation

Mistake # 2 – Not all outputs assigned value

library IEEE; use IEEE.STD_LOGIC_1164.all; entity majority1 is port( a : in STD_LOGIC; b : in STD_LOGIC; c : in STD_LOGIC; f : out STD_LOGIC ); end majority1; architecture behavioral of majority1 is begin process (a,b,c) begin if (((a = '1') and (b = '1')) or ((a = '1') and (c = '1')) or ((b = '1') and (c = '1')) ) then f <= '1'; -- no default value assigning f <= '0' end if; end process; end behavioral;

Waveform – Error # 2

  • Synplicity gives WARNINGS (in blue) to let us know it may have done something we did not intend it to do:
@W: CL111 … All reachable assignments to f assign '1', register removed
by optimization
@W: CL207 … All reachable assignments to f assign 1, register removed by
optimization

Error: should be '0'

Pre-Synthesis Simulation

Mux with Don't Care with Process Statements

Mux with Don't Cares with Process Statements

(Correct) cont'd

architecture behavioral of muxdontcare is signal selint : integer range 0 to 3; begin selint <= conv_integer(unsigned(sel)); process (a,b,c,d,selint) begin if (selint = 0) then x <= a; y <= '0'; elsif (selint = 1) then x <= b; y <= '1'; elsif (selint = 2) then x <= c; y <= '-'; -- use '-' to indicate don't care else -- selint is 3 x <= d; y <= '-'; -- use '-' to indicate don't care end if; end process; end behavioral;

Testbench

library ieee; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; use ieee.std_logic_1164.all;

entity muxdontcare_tb is end muxdontcare_tb;

architecture TB_ARCHITECTURE of muxdontcare_tb is

component muxdontcare port( a : in std_logic; b : in std_logic; c : in std_logic; d : in std_logic; sel : in std_logic_vector(1 downto 0); x : out std_logic; y : out std_logic ); end component;

Testbench cont'd

signal a,b,c,d,x,y : std_logic; signal sel : std_logic_vector(1 downto 0); signal inputvec : std_logic_vector(3 downto 0); begin UUT : muxdontcare port map ( a => a, b => b, c => c, d => d, sel => sel, x => x, y => y ); a <= inputvec(3); b <= inputvec(2); c <= inputvec(1); d <= inputvec(0); process begin inputvec <= "0000"; sel <= "00"; for i in 0 to 3 loop for j in 0 to 15 loop wait for 10 ns; inputvec <= inputvec + 1; end loop; sel <= sel + 1; end loop; wait; end process; end TB_ARCHITECTURE;

Waveform

Pre-Synthesis Simulation

don't care

Mistake # 2 – Not all outputs assigned value cont'd

architecture behavioral of muxdontcare is signal selint : integer range 0 to 3; begin selint <= conv_integer(unsigned(sel)); process (a,b,c,d,selint) begin if (selint = 0) then x <= a; y <= '0'; elsif (selint = 1) then x <= b; y <= '1'; elsif (selint = 2) then x <= c; -- don't assign y else -- selint is 3 x <= d; -- don't assign y end if; end process; end behavioral;

Waveform – Mistake #

Error: creates a latch, i.e. remembers the last value of y

  • Synplicity gives WARNINGS (in blue) to let us know it may have done something we did not intend it to do:
@W: CL117 … Latch generated from process for signal y, probably caused
by a missing assignment in an if or case stmt

Pre-Synthesis Simulation

Inferred Latch

This latch should not be here, but was inferred due to poor coding

Priority Encoder with Process Statements

Testbench

library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity priority_tb is end priority_tb; architecture TB_ARCHITECTURE of priority_tb is component priority port( y : in std_logic_vector(7 downto 1); pout : out std_logic_vector(2 downto 0) ); end component; signal y : std_logic_vector(7 downto 1); signal pout : std_logic_vector(2 downto 0); begin UUT : priority port map ( y => y, pout => pout );

Testbench cont'd

process begin y <= "0000000"; for i in 1 to 128 loop wait for 10 ns; y <= y + 1; end loop; wait; end process; end TB_ARCHITECTURE;

Waveform

Priority Encoder—Correct but be careful

library ieee; use ieee.std_logic_1164.all; entity priority is port ( y: in std_logic_vector(7 downto 1); pout: out std_logic_vector(2 downto 0) ); end priority; architecture behavioral of priority is begin process (y) begin pout <= "000"; if (y(1) = '1') then pout <= "001"; end if; if (y(2) = '1') then pout <= "010"; end if; if (y(3) = '1') then pout <= "011"; end if; if (y(4) = '1') then pout <= "100"; end if; if (y(5) = '1') then pout <= "101"; end if; if (y(6) = '1') then pout <= "110"; end if; if (y(7) = '1') then pout <= "111"; end if; end process; end behavioral;

NOTES:

-for any given input, "pout <=" statement

assigned many times— this is not

recommended, except in certain cases

-only the last "pout<=" assignment in the

process counts

-therefore the highest priority assignment

should be last!

highest priority last