660 likes | 837 Views
Introduction to VHDL (A Basic Introduction). Mr. Scott, have you always multiplied your repair estimates by a factor of four?. Use and Distribution Notice. Possession of any of these files implies understanding and agreement to this policy.
E N D
Introduction to VHDL(A Basic Introduction) Mr. Scott, have you always multiplied your repair estimates by a factor of four?
Use and Distribution Notice • Possession of any of these files implies understanding and agreement to this policy. • The slides are provided for the use of students enrolled in Jeff Six's Computer Architecture class (CMSC 411) at the University of Maryland Baltimore County. They are the creation of Mr. Six and he reserves all rights as to the slides. These slides are not to be modified or redistributed in any way. All of these slides may only be used by students for the purpose of reviewing the material covered in lecture. Any other use, including but not limited to, the modification of any slides or the sale of any slides or material, in whole or in part, is expressly prohibited. • Some of the material in these slides, including the examples, is derived from VHDL for Programmable Logic and The Designer’s Guide to VHDL. Credit is hereby given to the authors of these textbooks for much of the content. This content is used here for the purpose of presenting this material in CMSC 411, which uses this textbook.
Modeling a Hardware System • A hardware system can be described using a model, consisting of an entity declaration and architecture bodies. Entity Declaration Architecture Bodies
Entity Declarations and Architecture Bodies Entity Declaration • The entity declaration specifies what the system being modeled looks like from the outside (black box view). • An architecture body is one possible implementation of that entity. Architecture Bodies
Example: An 8-bit Equality Comparator • Here is a schematic symbol for such a comparator (let’s call it eqcomp8). A(7:0) Equals B(7:0)
Example:The Entity Declaration • The entity declaration for this model is quite simple. In VHDL, entity eqcomp8 is port ( a: in bit_vector (7 downto 0) b: in bit_vector (7 downto 0) equals: out bit ); -- equals is active high end eqcomp8;
The Entity Declaration • A couple observations concerning the entity declaration… • entity, port, is – these are keywords/reserved words in VHDL • -- (2 hyphens) is the comment syntax – everything past the -- to the end of the line is a comment (like // in the C++ language) • a, b are input 8-bit bit vectors • equals is an output bit • The entity declaration describes the entity being modeled – it’s a black box view.
Example:The Architecture Body • The architecture body for this model is also quite simple. In VHDL, architecture dataflow of eqcomp8 is begin equals <= ‘1’ when (a = b) else ‘0’; end dataflow;
The Architecture Body • Observations about the architecture body… • The is the architecture known as “dataflow” of the entity known as “eqcomp8”. • The one line in the body can be interpreted as “if the value of bus A equals the value of bus B then equals is assigned the value of ‘1’, otherwise ‘0’. • In VHDL, the high subscript line on a bus is the most significant (i.e. A(7) is the most significant bit of the value carried on the bus known as A).
Entity Declarations Revisited • The entity declaration specifies the interfaces of the design (the input and output). • As another example, the entity declaration of a 4-bit adder could be written as… entity add4 is port( a, b: in std_logic_vector(3 downto 0); cin: in std_logic; sum: out std_logic_vector(3 downto 0); cout: out std_logic); end add4;
Port Maps and Modes • These port declarations describe the signals coming in and out of the entity. • The mode describes the direction in which data is transferred through a port… • in – data flows into the entity • out – data flows out of the entity • buffer – data flows out but is also available for internal feedback (can act as a driver within the architecture body) • data only flows out – cannot drive this signal externally • may not have multiple drivers • in/out – can do all of the above (really do not want to do this unless you need to)
Architecture Bodies • An architecture body can be written in one of three different forms/models… • behavioral – written as a set of sequential assignment statements and is used to model the behavior of the system • dataflow – written as a set of concurrent assignment statements and is used to model the paths by which data flows in the system • structural – written as a set of interconnected components and is used to model the internal structure of the system
Behavioral Modeling • The behavioral model is written as a set of sequential assignment statements. • This is known as a high-level description of the system being modeled and is very similar to a sequential algorithm programmed in a C-like language. • A behavioral description has one or more process statements (procedures), each with a sensitivity list. • When any of the input signals specified in the sensitivity list changes, the process statement will run and (possibly) change the output signals.
Behavioral Modeling Example library ieee; use ieee.std_logic_1164.all; entity eqcomp8 is port ( a,b: in std_logic_vector(7 downto 0); equals: out std_logic); end eqcomp8; architecture behavioral of eqcomp8 is ( begin comp: process (a,b) begin if a = b then equals <= ‘1’; else equals <= ‘0’; end if; end process comp; end behavioral;
Another Behavioral Modeling Example architecture behavioral of register2 isbegin storage : process isvariable internal_data0, internal_data1 : bit;beginif en = '1' and clk = '1' then internal_data0 := data0; internal_data1 := data1;end if; q0 <= internal_d0 after 5 ns; q1 <= internal_d1 after 5 ns; wait on data0, data1, en, clk;end process storage; end architecture behavioral;
More on Behavioral Models • This is a behavioral model of a 2 bit register. • We do a couple new things here… • The process has two internal variables (they will end up as flip/flops in hardware). • Some of the assignment statements are in a conditional statement – they only have an effect if the conditional is true when the process runs. • We added a wait keyword in our output assignments – this models the propagation delay inherit in that datapath. • The sensitivity list is implemented as a wait on statement at the end of the process (but it works the same way as putting these signals in parens at the beginning of the process statement).
Behavioral Descriptions • Is there any difference between these two behavioral descriptions? architecture behavioral of eqcomp8 is begin comp: process (a,b) begin equals <= ‘0’; if a = b then equals <= ‘1’; end if; end process comp; end behavioral; architecture behavioral of eqcomp8 is begin comp: process (a,b) begin if a = b then equals <= ‘1’; end if; equals <= ‘0’; end process comp; end behavioral; Yes! A process statement is sequential!
Dataflow Modeling • The dataflow model is written as a set of concurrent assignment statements. • It specifies how data is transferred through the system. • There are no process statements. Rather dataflow modeling using simple equations, when-else, with-select-when, and some other forms. • These statements are evaluated concurrently, not sequentially!
Dataflow Modeling Example library ieee; use ieee.std_logic_1164.all; entity eqcomp8 is port ( a,b: in std_logic_vector(7 downto 0); equals: out std_logic); end eqcomp8; architecture dataflow of eqcomp8 is ( begin equals <= ‘1’ when (a = b) else ‘0’; -- equals is active high end dataflow;
Another Dataflow Modeling Example • As another example, a dataflow model of a full adder could be written. • Here we add the after keyword which models propagation delay for that datapath. • Note that we do not use “dataflow” as the name of our architectural body – it’s just a name. architecture my_full_adder of full_adder is ( begin sum <= a xor b xor cin after 15ns; cout <= (a and b) or (b and cin) or (a and cin) after 10ns; end my_full_adder;
Structural Modeling • The structural model is a VHDL netlist (this is like a schematic netlist). • Individual components are instantiated. • This is a hierarchical type design… • Each component present in the structural model can be individually design and simulated – the model then tied them all together using a netlist (which port connects to which port). • The structure of the logic is completely specified.
Structural Modeling Example • Here is an example of a structural model…
Port Maps • In a structural model, the port map statement connects signals to input and output ports on components. • In the example, the first 2 input XOR gate (xor2) has its two inputs connected to a(0) and b(0) and its output connected to c(0). Similar connections exits for the other bits in the a, b, and c signals. • The c signals are then connected to the 4 input NOR (nor4) inputs and the output of that gate is connected to the aeqb signal. • All the port map statements do is connect ports and wires, defining the entity’s structure.
Back to the Basics • Now that we dove in and looked at the three ways of constructing models in VHDL and some simple examples, let’s take a step back and look at some basics of the VHDL language. • VHDL = Very High Speed Integrated Circuit Hardware Description Language. • Started life in the 1970s as part of the DoD’s VHSIC program • Now an IEEE standard (set of standards, actually)
Identifiers • Identifiers (names of things) in VHDL must follow certain rules… • The first character must be a letter. • The last character cannot be an underscore. • Two underscores in succession are not allowed. • Reserved words/keywords cannot be used as identifiers.
Signals and Variables • A signal is a wire. • A signal is not updated until the end. Although a sequential signal assignment causes a transaction to be scheduled, it is only the last transaction on that signal that has any effect. • A variable is not a wire. • A variable is used only in processes/subprograms. It does not represent a wire and is typically used for high-level modeling. It stores values. • A variable assignment happens immediately. • Declaring them is almost the same… signal count : bit_vector(3 downto 0) variable count : bit_vector(3 downto 0)
Enumeration Types • Enumeration types can be created in VHDL… • Some simple examples… • type color is (red, black, blue); • type suite is (hearts, spades, clubs, diamonds); • IEEE 1076 introduces a few… • type boolean is (false, true); • type bit is (‘0’, ‘1’);
Record Types • A record type can be created… type io_bundle is record data: bit_vector (7 downto 0); enable: bit; control: bit_vector (3 downto 0); end record; signal bus_a: io_bundle; signal bus_b: io_bundle;
Logic Types • The standard bit and bit_vector represent 0 or 1 (or a vector of 0/1). • The IEEE 1164 standard describes std_logic, which represents a physical wire/signal… type std_logic is ( ‘U’ -- undefined ‘X’ -- forcing unknown ‘0’ -- forcing 0 ‘1’ -- forcing 1 ‘Z’ -- high impedance ‘W’ -- weak unknown ‘L’ -- weak 0 ‘H’ -- weak 1 ‘-’ -- don’t care ); Notice that std_logic is an enumeration type, itself. It is used to represent physical wire states.
Attributes • VHDL supports attributes which allow the direct access to parts of a signal or data type… type count is integer range 0 to 127; type states is (idle, decision, read, write); type word is array (15 downto 0) of std_logic; Attributes and their return values
A More Complex Example • Let’s look at a 4-input multiplexer. • Here, we use concurrent assignment statements. • What style model is this?
The with-select-when Statement • Let’s introduce a selective signal assignment statement. This is used as a concurrent statement in VHDL (not in a sequential process). • Some rules must be followed… • The statement is a with-select-when. • All selection signals must be listed. • All selection signal values must be mutually exclusive. • Changes in any signal will cause the evaluation.
Rewriting the Multiplexer • We can rewrite our 4-bit multiplexer using the with-select-when statement to make it much simpler.
A Little More Robustness • We can make our design a little more robust by introducing an undefined output with an invalid input… • The ‘-’ value is defined in std_logic as “undefined”. So, if an invalid input is detected, the output will be undefined. • Note that here an invalid input is impossible, but this is still a good practice.
The when-else Statement • Let’s introduce a conditional signal assignment statement. This is used as a concurrent statement in VHDL (not in a sequential process). • Some rules must be followed… • The statement is a when-else. • The signal is assigned the first value when the condition is true. • The conditions do not have to be mutually exclusive.
Rewriting the Multiplexer • We can rewrite the multiplexer using when-else statements…
A Simple Hardware System? • Remember that when-else statements do not need to be mutually exclusive. • Let’s look at a simple statement and the (quite complex) synthesis result…
What Happened? • Since the conditions are not mutually exclusive, complex hardware is created to deal with priority (the first condition in the when-else takes precedence over the second, etc…). • If we use a mutually exclusive form, the design can become a lot simpler…
Sequential Statements • We have seen some concurrent statements, now let’s look at sequential statements using in a process. • The if statement is used here…
If Statement Example • Are these two process statements the same? Yes! Sequential execution of these two processes yields the same value being assigned to the step output.
Lack of a Default Value • Here is a different type of example…what will the hardware for this process statement yield? Why is this hardware synthesized? Since there is no value assigned if addr is <= “0F,” step will retain its value.
The else-if Statement • This is why the elsif part of the if statement is present in VHDL…
Rewriting the Multiplexer(again) • Rewriting the multiplexer using the if/elsif/else statement…
Another if/elsif/else Example • Let’s implement an address decoder that takes an address as input and then specifies which device controls the range of memory that address falls in.
The case-when Statement • For cases where there are multiple input combinations and the outputs should behave differently based on those input combinations, the case-when statement can be used.
Modeling Sequential Logic • Let’s build a D flip/flop. • Note that this is an edge-triggered flip/flop. We are using the event attribute on the clk signal – this is true is the clk signal is the signal that changed and caused the process to run.
Modeling a Register • Note that it is trivial to model an 8-bit register in place of the flip/flop…
Modeling a T Flip/Flop • We can model a T flip/flop easily as well…
The rising_edge Function • Realizing that the combination of the event attribute and a signal level comparison are a popular combination, VHDL has the rising_edge (and falling_edge) function…