Lecture 3 Entity, Architecture, and Components Examples of Combinational Logic Hands-on in the Laboratory BTF4220 - Digital Electronics 2 Mar. 06, 2015 Bern University of Applied Sciences
Agenda Rev. ec317bd 3.2
The basic elements are AND, OR, NOT, EXOR, NAND, NOR Rev. ec317bd 3.3
The basic elements are AND, OR, NOT, EXOR, NAND, NOR Such components have a library declaration LIBRARY IEEE; Rev. ec317bd 3.3
The basic elements are AND, OR, NOT, EXOR, NAND, NOR Such components have a library declaration LIBRARY IEEE; To have them available include the corresponding package (STD_LOGIC_1164). for the standard package of the library IEEE is shown below: LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.all; Rev. ec317bd 3.3
The basic elements are AND, OR, NOT, EXOR, NAND, NOR Such components have a library declaration LIBRARY IEEE; To have them available include the corresponding package (STD_LOGIC_1164). for the standard package of the library IEEE is shown below: LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.all; of an AND File name : exand-entity.vhdl Example : AND (entity) 1 LIBRARY ieee; 2 USE ieee.std_logic_1164.all; 3 4 ENTITY ExAnd is 5 Port( 6 AxDI : IN std_logic; 7 BxDI : IN std_logic; 8 FxDO : OUT std_logic 9 ); 10 END ExAnd; Figure: Ex : Entity Block Rev. ec317bd 3.3
Some More Entity Examples Example : NOT (entity) 1 LIBRARY ieee; -- Library to include 2 USE ieee.std_logic_1164.all; -- Package of library 3 4 ENTITY ExNot is -- ENTITY block start 5 Port( -- PORT statement start 6 AxDI : IN std_logic; -- A input signal 7 FxDO : OUT std_logic -- A output signal 8 ); -- PORT end 9 END ExNot; -- ENTITY block end Rev. ec317bd 3.4
Some More Entity Examples Example : NOT (entity) 1 LIBRARY ieee; -- Library to include 2 USE ieee.std_logic_1164.all; -- Package of library 3 4 ENTITY ExNot is -- ENTITY block start 5 Port( -- PORT statement start 6 AxDI : IN std_logic; -- A input signal 7 FxDO : OUT std_logic -- A output signal 8 ); -- PORT end 9 END ExNot; -- ENTITY block end 1 type std_ulogic is ( 2 U, -- Uninitialized 3 X, -- Forcing Unknown 4 0, -- Forcing 0 5 1, -- Forcing 1 6 Z, -- High Impedance 7 W, -- Weak Unknown 8 L, -- Weak 0 9 H, -- Weak 1 10 - -- Don t 11 ); A nine-value resolved logic type std_logic is not a part of the VHDL standard. It is defined in IEEE Std 1164. Rev. ec317bd 3.4
Some More Entity Examples Example : NOT (entity) 1 LIBRARY ieee; -- Library to include 2 USE ieee.std_logic_1164.all; -- Package of library 3 4 ENTITY ExNot is -- ENTITY block start 5 Port( -- PORT statement start 6 AxDI : IN std_logic; -- A input signal 7 FxDO : OUT std_logic -- A output signal 8 ); -- PORT end 9 END ExNot; -- ENTITY block end 1 type std_ulogic is ( 2 U, -- Uninitialized 3 X, -- Forcing Unknown 4 0, -- Forcing 0 5 1, -- Forcing 1 6 Z, -- High Impedance 7 W, -- Weak Unknown 8 L, -- Weak 0 9 H, -- Weak 1 10 - -- Don t 11 ); A nine-value resolved logic type std_logic is not a part of the VHDL standard. It is defined in IEEE Std 1164. What circuit is it? What is its interface? Write the entity of the circuit on the left-hand side? Rev. ec317bd 3.4
Some More Entity Examples Example : NOT (entity) 1 LIBRARY ieee; -- Library to include 2 USE ieee.std_logic_1164.all; -- Package of library 3 4 ENTITY ExNot is -- ENTITY block start 5 Port( -- PORT statement start 6 AxDI : IN std_logic; -- A input signal 7 FxDO : OUT std_logic -- A output signal 8 ); -- PORT end 9 END ExNot; -- ENTITY block end 1 type std_ulogic is ( 2 U, -- Uninitialized 3 X, -- Forcing Unknown 4 0, -- Forcing 0 5 1, -- Forcing 1 6 Z, -- High Impedance 7 W, -- Weak Unknown 8 L, -- Weak 0 9 H, -- Weak 1 10 - -- Don t 11 ); A nine-value resolved logic type std_logic is not a part of the VHDL standard. It is defined in IEEE Std 1164. Example : Mux 2 to 1 1 library ieee; 2 use ieee.std_logic_1164.all; 3 4 entity ExMux_2_1 is 5 port ( 6 AxDI, BxDI : in std_logic; 7 SelxSI : in std_logic; 8 DxDO : out std_logic 9 ); 10 end ExMux_2_1; Rev. ec317bd 3.4
Some Vector Based Entities Example : AND 4 Bit (entity) 1 LIBRARY ieee; 2 USE ieee.std_logic_1164.all; 3 4 ENTITY ExAnd_4 is 5 Port( 6 AxDI : IN std_logic_vector(3 downto 0); 7 BxDI : IN std_logic_vector(3 downto 0); 8 FxDO : OUT std_logic_vector(3 downto 0) 9 ); 10 END ExAnd_4; Rev. ec317bd 3.5
Some Vector Based Entities Example : AND 4 Bit (entity) 1 LIBRARY ieee; 2 USE ieee.std_logic_1164.all; 3 4 ENTITY ExAnd_4 is 5 Port( 6 AxDI : IN std_logic_vector(3 downto 0); 7 BxDI : IN std_logic_vector(3 downto 0); 8 FxDO : OUT std_logic_vector(3 downto 0) 9 ); 10 END ExAnd_4; std_logic_vector(7 downto 0); --7th bit is MSB and 0th bit is LSB here std_logic_vector(0 to 7); --0th bit is MSB and 7th bit is LSB here Rev. ec317bd 3.5
Some Vector Based Entities Example : AND 4 Bit (entity) 1 LIBRARY ieee; 2 USE ieee.std_logic_1164.all; 3 4 ENTITY ExAnd_4 is 5 Port( 6 AxDI : IN std_logic_vector(3 downto 0); 7 BxDI : IN std_logic_vector(3 downto 0); 8 FxDO : OUT std_logic_vector(3 downto 0) 9 ); 10 END ExAnd_4; std_logic_vector(7 downto 0); --7th bit is MSB and 0th bit is LSB here std_logic_vector(0 to 7); --0th bit is MSB and 7th bit is LSB here What to do when we would like to create a more generic component Rev. ec317bd 3.5
Some Vector Based Entities Example : AND 4 Bit (entity) 1 LIBRARY ieee; 2 USE ieee.std_logic_1164.all; 3 4 ENTITY ExAnd_4 is 5 Port( 6 AxDI : IN std_logic_vector(3 downto 0); 7 BxDI : IN std_logic_vector(3 downto 0); 8 FxDO : OUT std_logic_vector(3 downto 0) 9 ); 10 END ExAnd_4; std_logic_vector(7 downto 0); --7th bit is MSB and 0th bit is LSB here std_logic_vector(0 to 7); --0th bit is MSB and 7th bit is LSB here What to do when we would like to create a more generic component There is the possibility of specifying generics that are used for making components more adaptable. The generic should have a default specification that can be overwritten when instantiating the component. Rev. ec317bd 3.5
Some Vector Based Entities What to do when we would like to create a more generic component There is the possibility of specifying generics that are used for making components more adaptable. The generic should have a default specification that can be overwritten when instantiating the component. Example : Mux 4 to 1 generic (entity) 1 LIBRARY ieee; 2 USE ieee.std_logic_1164.all; 3 4 ENTITY ExMux_4_G is 5 GENERIC( 6 VECTOR_WIDTH : INTEGER := 8 7 ); 8 Port( 9 AxDI, BxDI, CxDI, DxDI : IN std_logic_vector(vector_width-1 downto 0); 10 Sel1xSI, Sel2xSI : IN std_logic; 11 DxDO : OUT std_logic_vector(vector_width-1 downto 0) 12 ); 13 END ExMux_4_G; Rev. ec317bd 3.5
Mux Exercises Figure: Block Diagram 4 to 1 Mux Rev. ec317bd 3.6
Mux Exercises Figure: Block Diagram 4 to 1 Mux Figure: Logic Diagram 4 to 1 Mux Rev. ec317bd 3.6
Mux Exercises Figure: Block Diagram 4 to 1 Mux Exercise : Entity of 4 to 1 Mux Write the entity of a 4 to 1 multiplexer. Which libraries are required? What are the statements used? Use the syntax introduced. Figure: Logic Diagram 4 to 1 Mux Rev. ec317bd 3.6
Mux Exercises Figure: Block Diagram 4 to 1 Mux Solution : Mux 4 to 1 (entity) 1 LIBRARY ieee; 2 USE ieee.std_logic_1164.all; 3 4 ENTITY ExMux_4_1 is 5 Port( 6 AxDI, BxDI, CxDI, DxDI : IN std_logic; 7 Sel1xSI, Sel2xSI : IN std_logic; 8 DxDO : OUT std_logic 9 ); 10 END ExMux_4_1; Exercise : Entity of 4 to 1 Mux Write the entity of a 4 to 1 multiplexer. Which libraries are required? What are the statements used? Use the syntax introduced. Rev. ec317bd 3.6
Summary to the Interface We know the source code file block LIBRARIES: What libraries to use and which packages to include to have language definitions like standard logic types and basic logic functions available. Rev. ec317bd 3.7
Summary to the Interface We know the source code file block LIBRARIES: What libraries to use and which packages to include to have language definitions like standard logic types and basic logic functions available. We know the source code file part ENTITY: Describes the function unit, its interface (direction, type etc.) to the outside-world. Rev. ec317bd 3.7
Summary to the Interface We know the source code file block LIBRARIES: What libraries to use and which packages to include to have language definitions like standard logic types and basic logic functions available. We know the source code file part ENTITY: Describes the function unit, its interface (direction, type etc.) to the outside-world. How can we use this information in hardware description? To make designs more understandable and maintainable, a design is typically decomposed into several blocks. These blocks are then connected together to form a complete design. Each block in VHDL is analogous to an off-the-shelf part and is called an entity. The entity describes the interface to that block and a separate part associated with the entity describes how that block operates. description is like a pin description, specifying the inputs and outputs to the block. Rev. ec317bd 3.7
Summary to the Interface We know the source code file block LIBRARIES: What libraries to use and which packages to include to have language definitions like standard logic types and basic logic functions available. We know the source code file part ENTITY: Describes the function unit, its interface (direction, type etc.) to the outside-world. How can we use this information in hardware description? To make designs more understandable and maintainable, a design is typically decomposed into several blocks. These blocks are then connected together to form a complete design. Each block in VHDL is analogous to an off-the-shelf part and is called an entity. The entity describes the interface to that block and a separate part associated with the entity describes how that block operates. description is like a pin description, specifying the inputs and outputs to the block. Let s analyze an example of a latch entirely. Rev. ec317bd 3.7
The Latch Example Example : Latch Entity 1 library ieee; 2 use ieee.std_logic_1164.all; 3 4 entity Latch is 5 6 port ( 7 SetxDI, RstxDI : in std_logic; 8 QxDO, QxDLO : out std_logic 9 ); 10 11 end Latch; Example : Latch Architecture 1 architecture dataflow of Latch is 2 signal QxDN, QxDNL : std_logic; 3 begin -- architecture dataflow 4 5 QxDN <= RstxDI nor QxDNL; 6 QxDNL <= SetxDI nor QxDN; 7 8 QxDO <= QxDN; 9 QxDLO <= QxDNL; 10 11 end dataflow; The Library section includes the standard logic package of a Set/Reset Latch Ports of the same mode and object can be grouped together Rev. ec317bd 3.8
The Latch Example Example : Latch Entity 1 library ieee; 2 use ieee.std_logic_1164.all; 3 4 entity Latch is 5 6 port ( 7 SetxDI, RstxDI : in std_logic; 8 QxDO, QxDLO : out std_logic 9 ); 10 11 end Latch; Example : Latch Architecture 1 architecture dataflow of Latch is 2 signal QxDN, QxDNL : std_logic; 3 begin -- architecture dataflow 4 5 QxDN <= RstxDI nor QxDNL; 6 QxDNL <= SetxDI nor QxDN; 7 8 QxDO <= QxDN; 9 QxDLO <= QxDNL; 10 11 end dataflow; The Library section includes the standard logic package of a Set/Reset Latch Ports of the same mode and object can be grouped together The second part of the Latch is a description of how it works. The first line of the declaration indicates that this is the definition of a new architecture called dataflow and it belongs to the entity named Latch. This example uses the data flow approach which is discussed later. Rev. ec317bd 3.8
The internals of an element Example : VHDL Architecture 1 architecture <MODEL_NAME> of <ENTITY_NAME> is -- start of architecture statement 2 3 -- This part is called the declarative 4 -- section of an architecture 5 -- here goes signals and type defs 6 -- component declarations etc. 7 8 begin -- architecture behavior (start of descriptive section) 9 10 -- This part is called descriptive 11 -- section of an architecture. 12 -- hre goes your component model 13 -- it can be behavioral, data-flow, 14 -- or structural. 15 16 end <MODEL_NAME>; -- end of architecture statement Rev. ec317bd 3.9
Signals, Assignment, Concurrency Example : Concurrent Signal Assignment 1 architecture dataflow of <ENTITY_NAME> is 2 -- declaration of signal objects among others e.g. constants 3 -- <OBJECT_TYPE> <OBJECT_NAME> : <DATA_TYPE>; 4 signal MyTestSignalAxD : std_logic; 5 signal MyTestSignalBxD : std_logic; 6 7 begin -- architecture behavior 8 9 -- description of functional model 10 -- <TARGET> <= <EXPRESSION>; 11 MyTestSignalAxD <= MyInputAxDI and MyInputBxDI; 12 13 MyTestSignalBxD <= MyTestSignalAxD or MyInputBxDI; 14 15 -- the expression above is the same as 16 -- MyTestSignalBxD <= (MyInputAxDI and MyInputBxDI) or MyInputBxDI; 17 -- Signals are software representations of wires 18 -- The brackets are used to prioritize and nest sub-expressions 19 20 -- All statements are concurrent to each other 21 -- NO SEQUENTIAL execution -- think hardware whise 22 23 end dataflow; Rev. ec317bd 3.10
The dataflow paradigm In the data flow approach, circuits are described by indicating how the inputs and outputs of built-in primitive components (ex. an and gate) are connected together. In other words we describe how signals (data) flow through the circuit. Rev. ec317bd 3.11
The dataflow paradigm In the data flow approach, circuits are described by indicating how the inputs and outputs of built-in primitive components (ex. an and gate) are connected together. In other words we describe how signals (data) flow through the circuit. A signal assignment statement describes how data flows from the signals on the right side of the <= operator to the signal on the left side. The right side of the <= operator is called an expression. Rev. ec317bd 3.11
The dataflow paradigm In the data flow approach, circuits are described by indicating how the inputs and outputs of built-in primitive components (ex. an and gate) are connected together. In other words we describe how signals (data) flow through the circuit. A signal assignment statement describes how data flows from the signals on the right side of the <= operator to the signal on the left side. The right side of the <= operator is called an expression. The value of the expression is determined by evaluating the expression. Evaluating the expression is performed by substituting the values of the signals in the expression and computing the result of each operator in the expression. Rev. ec317bd 3.11
The dataflow paradigm In the data flow approach, circuits are described by indicating how the inputs and outputs of built-in primitive components (ex. an and gate) are connected together. In other words we describe how signals (data) flow through the circuit. A signal assignment statement describes how data flows from the signals on the right side of the <= operator to the signal on the left side. The right side of the <= operator is called an expression. The value of the expression is determined by evaluating the expression. Evaluating the expression is performed by substituting the values of the signals in the expression and computing the result of each operator in the expression. Exercise : S/R Latch Draw the gate diagram of the described S/R Latch Rev. ec317bd 3.11
The 4 to 1 Mux Architecture - Implicit Process Example : Mux 4 to 1 - pure logic Figure: Block Diagram 4 to 1 Mux 1 ARCHITECTURE purelogic OF ExMux_4_1 IS 2 BEGIN 3 DxDO <= ( AxDI AND (NOT Sel1xSI AND NOT Sel2xSI)) OR 4 ( BxDI AND (NOT Sel1xSI AND Sel2xSI)) OR 5 ( CxDI AND (Sel1xSI AND NOT Sel2xSI)) OR 6 ( DxDI AND (Sel1xSI AND Sel2xSI)); 7 END purelogic; Implicit process Dataflow method -> basic logic gates Fully concurrent implementation Rev. ec317bd 3.12
The 4 to 1 Mux Architecture - Implicit Process Figure: Block Diagram 4 to 1 Mux Example : Mux 4 to 1 - WHEN/ELSE 1 ARCHITECTURE whenexample OF ExMux_4_1 IS 2 BEGIN 3 DxDO <= AxDI WHEN (Sel1xSI & Sel2xSI) = 00 ELSE 4 BxDI WHEN (Sel1xSI & Sel2xSI) = 01 ELSE 5 CxDI WHEN (Sel1xSI & Sel2xSI) = 10 ELSE 6 DxDI WHEN (Sel1xSI & Sel2xSI) = 11 ELSE 7 X 8 END whenexample; Implicit process Priority based description Realizes nested gates Dataflow method Rev. ec317bd 3.12
The 4 to 1 Mux Architecture - Implicit Process Figure: Block Diagram 4 to 1 Mux Example : Mux 4 to 1 - WITH/SELECT/WHEN 1 ARCHITECTURE withexample OF ExMux_4_1 IS 2 SIGNAL SelxS : STD_LOGIC_VECTOR(1 DOWNTO 0); 3 BEGIN 4 SelxS <= Sel1xSI & Sel2xSI; -- concatenate the select bits 5 WITH SelxS SELECT 6 DxDO <= AxDI WHEN 00, 7 BxDI WHEN 01, 8 CxDI WHEN 10, 9 DxDI WHEN 11, 10 X WHEN OTHERS; 11 -- others condition is required 12 -- due to std_logic is not only 13 -- 0 and 1, also X, Z among others 14 END withexample; Implicit process Not priority based implementation An efficient method of implementation Do not forget the others condition Rev. ec317bd 3.12
ModelSim Do-Files ModelSim allows you to automate sequences of commands using DO files ModelSim DO-File reference manual : http://www.microsemi.com/document-portal/doc_view/ 134097-modelsim-command-reference-manual-v10-3a Rev. ec317bd 3.13
ModelSim Do-Files ModelSim allows you to automate sequences of commands using DO files To create a new DO file, navigate to the ModelSim main window and choose File New Source Do ModelSim DO-File reference manual : http://www.microsemi.com/document-portal/doc_view/ 134097-modelsim-command-reference-manual-v10-3a Rev. ec317bd 3.13
ModelSim Do-Files ModelSim allows you to automate sequences of commands using DO files To create a new DO file, navigate to the ModelSim main window and choose File New Source Do To run a Do-file type in ModelSim command-line <NAME>.do ModelSim DO-File reference manual : http://www.microsemi.com/document-portal/doc_view/ 134097-modelsim-command-reference-manual-v10-3a Rev. ec317bd 3.13
ModelSim Do-Files Example Do-file 1 # reset the simulation 2 restart -force -nowave 3 4 # add all input and output signals to the wave file 5 add wave -logic i0 6 add wave -logic i1 7 add wave -logic i2 8 add wave -logic i3 9 add wave -logic Sel 10 add wave -logic out 11 12 # force the input signals 13 force -freeze i0 0 0 14 force -freeze i1 1 0 15 force -freeze i2 1 0 16 force -freeze i3 0 0 17 18 force -freeze Sel 00 0 19 force -freeze Sel 01 50 20 force -freeze Sel 10 100 21 force -freeze Sel 11 150 22 23 # run the full simulation 24 run 200 25 26 # open the wave window 27 view wave ModelSim allows you to automate sequences of commands using DO files To create a new DO file, navigate to the ModelSim main window and choose File New Source Do To run a Do-file type in ModelSim command-line <NAME>.do The option -freeze is the default drive type and can be avoided. ModelSim DO-File reference manual : http://www.microsemi.com/document-portal/doc_view/ 134097-modelsim-command-reference-manual-v10-3a Rev. ec317bd 3.13
ModelSim Do-Files Example Do-file 1 # reset the simulation 2 restart -force -nowave 3 4 # add all input and output signals to the wave file 5 add wave -logic i0 6 add wave -logic i1 7 add wave -logic i2 8 add wave -logic i3 9 add wave -logic Sel 10 add wave -logic out 11 12 # force the input signals 13 force -freeze i0 0 0 14 force -freeze i1 1 0 15 force -freeze i2 1 0 16 force -freeze i3 0 0 17 18 force -freeze Sel 00 0 19 force -freeze Sel 01 50 20 force -freeze Sel 10 100 21 force -freeze Sel 11 150 22 23 # run the full simulation 24 run 200 25 26 # open the wave window 27 view wave ModelSim allows you to automate sequences of commands using DO files To create a new DO file, navigate to the ModelSim main window and choose File New Source Do To run a Do-file type in ModelSim command-line <NAME>.do The option -freeze is the default drive type and can be avoided. force [-freeze -drive -deposit] [-cancel <time>] [-repeat <time>] <item_name> <value> [<time>] [, <value> <time>...] ModelSim DO-File reference manual : http://www.microsemi.com/document-portal/doc_view/ 134097-modelsim-command-reference-manual-v10-3a Rev. ec317bd 3.13
The parallel carry-ripple adder Exercise : 4 Bit Full-Adder Specify the interface of a 4 Bit Full-Adder by using VHDL. Exercise : The model Write the functional model to the 4 Bit Full-Adder interface by using the VHDL methods shown above. Exercise : The test Write the functional test by using ModleSim Do-File syntax. Outlook In the upcoming session we are going to finish and test the adder in the lab. Make sure every thing is clear! Prepare questions if there are any!! We will not only do logical testing, but also a test run on real-world hardware. Rev. ec317bd 3.14