1 / 61

CSET 4650 Field Programmable Logic Devices

VHDL Additional Details & Examples. CSET 4650 Field Programmable Logic Devices. Dan Solarek. VHDL: Modeling Styles. Dataflow Most are like assigning expressions to signals Structural Define explicit components and the connections between them. Behavioral

crwys
Download Presentation

CSET 4650 Field Programmable Logic Devices

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VHDL Additional Details & Examples CSET 4650 Field Programmable Logic Devices Dan Solarek

  2. VHDL: Modeling Styles • Dataflow • Most are like assigning expressions to signals • Structural • Define explicit components and the connections between them. • Behavioral • Write an algorithm that describes the circuit’s output

  3. VHDL: Dataflow Style • Dataflow description • The detail is less when compared with the structural description • “Concurrent” statements include assignment and select statements • Concurrency is needed to model the behavior of parallel, interconnected hardware elements • Data dependencies are described, not the components and connections • Includes “when-else” and “with-select” statements

  4. VHDL: Structural Style • A structural description is just like the schematic • Includes concurrent statements • A component statement is a concurrent statement • All interconnections are precisely described 2-to4 DCD V2to4dec Y0 I0 Y1 I1 Y2 EN Y3

  5. VHDL: Behavioral Style • Behavioral description • May not be synthesizable and may lead to a very large circuit • Primarily used for simulation • Normally uses VHDL “processes” • Each VHDL process executes in parallel with other VHDL processes and concurrent statements • But “sequential” statements can be used within a process

  6. What is a PROCESS? • A process is a sequence of instructions, referred to as sequential statements. the keyword process • A process can be given a unique name using an optional LABEL • This is followed by the keyword process • The keyword BEGIN is used to indicate the start of the process • All statements within the process are executed SEQUENTIALLY. Hence, order of statements is important. • A process must end with the keywords end process. TESTING: process begin TEST_VECTOR<=“00”; wait for 10 ns; TEST_VECTOR<=“01”; wait for 10 ns; TEST_VECTOR<=“10”; wait for 10 ns; TEST_VECTOR<=“11”; wait for 10 ns; end process;

  7. List of signals to which the process is sensitive. Whenever there is an event on any of the signals in the sensitivity list, the process starts. Every time the process starts, it will run in its entirety. WAIT statements not allowed in a processes with a sensitivity list. label: process(sensitivity list) declaration part begin statement part end process; Process Sensitivity List

  8. VHDL Processes • Processes Describe Sequential Behavior • Processes in VHDL Are Very Powerful Statements • Allow to define an arbitrary behavior that may be difficult to represent by a real circuit • Not every process can be synthesized • Use Processes with Caution in the Code to Be Synthesized • Use Processes Freely in Testbenches

  9. dataflow VHDL Design Styles VHDL Design Styles structural behavioral Components and interconnects Concurrent statements Sequential statements • Registers • State machines • Test benches Subset most suitable for synthesis

  10. VHDL Details: Design Flow • VHDL compiler analyzes code for syntax errors and checks for compatibility with other modules • Synthesizer converts VHDL program to a circuit with components • Place and route fits the circuit to a device

  11. Elements of VHDL

  12. Logic Operators • VHDL provides the following predefined basic logic operators: Definition conjunction inclusive or exclusive or complement exclusive or complement conjunction complement inclusive or complement Keyword and or xor xnor* nand nor not * only predefined in VHDL-93

  13. Logic Operators (cont.) • Predefined operators are all binary except for ‘not’ • Multi-input operators formed from series of binary operators • NAND-3: A nand B nand C • Expression evaluation differs from switching algebra • and, or, nand, nor are ‘short-circuit’ operators • right operand not evaluated if left operand determines result

  14. Operator Precedence • Unary ‘not’ has a higher precedence than any binary operator • ALL binary operators have the SAME precedence • Operators with the same precedence are evaluated left-to-right • Operators in parentheses are evaluated first; innermost to outermost order • Must be used for proper AND - OR evaluation

  15. Concurrency • Software source code statements execute in page/line order (i.e., sequential order) • VHDL concurrent signal assignments execute only when associated signal change value (i.e., concurrent order) • page/line sequence has nothing to do with execution • assignments are on a nonprocedural stimulus/ response basis (event driven) • signal assignments may trigger other concurrent assignments

  16. assignments are dependent upon each other Concurrent Operation Example entity XOR2_OP is port (A, B : in std_logic; Z : out std_logic); end XOR2_OP; architecture AND_OR_CONC of XOR2_OP is signal INT1, INT2: std_logic; begin Z <= INT1 or INT2; INT2 <= not A and B; INT1 <= A and not B; end AND_OR_CONC ;

  17. Libraries Design Units Statements Expressions Objects Types Design Units and Libraries • VHDL is defined such that more complex pieces are built from simpler pieces

  18. Design Units and Libraries (cont.) • Part of a VHDL model that can be independently analyzed (error checked) is a design unit • Primary Design Units • Entity Declaration • Package Declaration • Configuration Declaration • Secondary Design Units • Architectural Body • Package Body • Primary units analyzed before secondary units

  19. Design Units and Libraries (cont.) • Two predefined libraries in VHDL • STD - contains predefined VHDL constructs such as types, objects, etc. • WORK - the working library • Many other libraries may exist as part of development environment • IEEE library - standard types and operators needed for simulation and implementation • User-defined libraries - designs for reuse • Implementation specific libraries - logic families

  20. Modeling Latches and Flip-Flops

  21. NAND LatchRSQt+10 0 U0 1 11 0 01 1 Qt R Q Q S SR Latch: Structural ENTITYlatchISPORT( R, S: IN std_logic; Q, Qbar: OUT std_logic);END ENTITY latch; ARCHITECTURE latch_archOFlatch ISBEGIN Q <= R NAND Qbar;Qbar <= S NAND Q;END ARCHITECTURE;

  22. NANDRSQt+10 0 U0 1 11 0 01 1 Qt Sensitivity list of signals:Every time a change of state or event occurs on these signals this process will be called R Q SequentialStatements Q S SR Latch: Asynchronous ARCHITECTURE latch2_arch OF latch ISBEGINPROCESS (R, S) BEGINIF R = ‘0’ THEN Q <= ‘1’; Qbar <= ‘0’;ELSIF S =‘0’ THEN Q <= ‘0’; Qbar <= ‘1’;END IF; END PROCESS;END ARCHITECTURE;

  23. S Q LE Q R ARCHITECTURE Latch_arch OF GC_Latch IS BEGINPROCESS (R, S, LE) BEGIN IF LE =‘1’ THENIF R = ‘0’ THEN Q <= ‘1’; Qbar <= ‘0’;ELSIF S =‘0’ THEN Q <= ‘0’; Qbar <= ‘1’;END IF; END IF; END PROCESS;END ARCHITECTURE; SR Flip-Flop: Gated-Clock

  24. Notice the Process does not contain D:PROCESS(Clock, D) Sensitivity lists contain signals used in conditionals (i.e., IF) Clock’EVENT is what distinguishes a D-FlipFlip from a Latch Data-Flip Flops: Synchronous ARCHITECTURE Dff_arch OF Dff ISBEGIN PROCESS (Clock)BEGIN IF Clock’EVENT AND Clock=‘1’ THEN Q <= D; END IF; END PROCESS; END ARCHITECTURE;

  25. Alternate andmore readable way is to use the rising_edge function D-Flip Flops: rising_edge ARCHITECTURE Dff_arch OF Dff IS BEGINPROCESS (Clock)BEGIN IF Clock’EVENT AND Clock=‘1’ THEN Q <= D; END IF; END PROCESS;END ARCHITECTURE; ARCHITECTURE dff_arch OF dff IS BEGINPROCESS (Clock)BEGIN IF rising_edge(Clock) THEN Q <= D; END IF; END PROCESS;END ARCHITECTURE;

  26. D-Flip Flop: Asynchronous Reset ARCHITECTURE dff_reset_arch OF dff_reset IS BEGINPROCESS (Clock, Reset)BEGIN IF Reset= ‘1’ THEN -- Asynchronous ResetQ <= ‘0’ ELSIF rising_edge(Clock) THEN--Synchronous Q <= D; END IF; END PROCESS; END ARCHITECTURE;

  27. PROCESS (Clock, Reset)BEGIN IF Reset=‘1’ THENQ <= ‘0’ ELSIF rising_edge(Clock) THEN Q <= D; END IF;END PROCESS; Asynchronous Reset Synchronous FF D-Flip Flops: Synchronous Reset PROCESS (Clock, Reset)BEGIN IF rising_edge(Clock) THEN IF Reset=‘1’ THENQ <= ‘0’ ELSE Q <= D; END IF; END IF;END PROCESS; Synchronous Reset Synchronous FF

  28. D-Flip Flop: Async. Reset & Preset PROCESS (Clock, Reset, Preset)BEGIN IF Reset=‘1’ THEN --highest priorityQ <= ‘0’; ELSIF Preset=‘1’ THENQ <= ‘0’;ELSIF rising_edge(Clock) THEN Q <= D; END IF; END PROCESS;

  29. Vector operations and conditional concurrent signal assignments

  30. Bit Vectors • Signals can be more than one bit (a vector) • Represent P address and data, function selection, etc. • Declaration is similar to single bit signals • type is bit_vector or std_logic_vector • We also must specify vector index range and direction • big endian: (low to high) • little endian: (high downto low)

  31. Vector Declarations port ( A, B: in std_logic_vector(7 downto 0); Z: out std_logic_vector(1 to 16) ); A and B: Z: 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Note! The first bit and last bit index numbers define the number of bits in the vector (i.e., max - min + 1)

  32. Vector Literals • Single bit binary literals are ‘0’ and ‘1’ • Vector binary literals are “0101”, “10_01” • literal values may have an underscore embedded to improve readability

  33. Vector Logical Operations • Single bit logical operations also apply to vectors • Operands MUST be the same size (generally applies to all vector operations) • Assignment target must also have the same number of bits as the result • Operations are applied bitwise to operands to produce the vector result

  34. Vector Operations Given: Signal A, B, Z: std_logic_vector(7 downto 0); Then the following logical operation and assignment Z <= A and B; Is equivalent to: for i = 0 to 7 Zi = Ai and Bi;

  35. Vector Arithmetic Operations • Vector arithmetic operations are basically the same as vector logical operations • Operands MUST be the same size • Assignment target must also have the same number of bits as the result • Operations are applied bitwise to operands to produce the vector result • The only difference is the carry or borrow • Carry in/out must be specially handled • Result can be 1 bit larger than operands (CO)

  36. 4-bit Adder (Dataflow VHDL) entity add4 is port (a, b: in std_logic_vector (3 downto 0); cin: in std_logic; cout: out std_logic; s: out std_logic_vector(3 downto 0) ); end add4; architecture df of add4 is signal tmpsum std_logic_vector(4 downto 0); begin tmpsum <= (‘0’ & a) + (‘0’ & b) + (“0000” & cin); s <= tmpsum(3 downto 0); cout <= tmpsum(4); end df;

  37. Add4 Example • In the previous example note: • The “&” symbol is the concatenation operator • joins operands together so that result length is sum of lengths of operands. • In order to be able to access the MSB carry out we had to add 5-bit values (used & operator to add leading zeros to operands) • To assign result to S, we had to access only the least significant 4 bits of S; this is a SLICE • The carry out is a single bit assignment of the LSB of the result

  38. Vectors and Concatenation signal A: std_logic_vector(3 downto 0); signal B: std_logic_vector(3 downto 0); signal C, D, E: std_logic_vector(7 downto 0); A <= ”0000”; B <= ”1111”; C <= A & B; -- C = ”00001111” D <= ‘0’ & ”0001111”; -- D <= ”00001111” E <= ‘0’ & ‘0’ & ‘0’ & ‘0’ & ‘1’ & ‘1’ & ‘1’ & ‘1’; -- E <= ”00001111”

  39. Slice Reference & Assignment • A slice is a part of a vector • accessed by a range clause • (hi downto lo) or (lo to hi) • indexes cannot go out of bounds of original declaration • range direction must be the same as the original vector • a single index is use to access a single bit • e.g., tmpsum(4); • assignee must be the same size as the slice • cout <= tmpsum(4);

  40. Conditional Concurrent Assignment • Up to now, signal assignment has been only based on evaluation of operand changes • expressions are boolean algebra only • hard to understand what is being implemented e.g., a 4-to-1 MUX: Z <= (a and not s(1) and not s(0)) or (b and not s(1) and s(0)) or (c and s(1) and not s(0)) or (d and s(1) or s(0));

  41. Conditional Concurrent Assignment General Form: target_signal <= value1 when cond1 else value2 when cond2 else * valuem when condm else valuen; Note that the condition clauses must evaluate to a logical expression.

  42. 4-to-1 Mux (Cond. Concurrent Form) Z <= A when s = “00” else B when s = “01” else C when s = “10” else D; Note that in the last case, we did not specify a condition; this is the “when no other condition is met” case. Note also that we can conditionalize the last case by if so, we must ensure that all possible condition combinations are addressed.

  43. Relational Operators • In the previous example we introduced a new operator, the relational “equals” • The relational operators are = (equals) /= (not equals) > (greater than) < (less than) >= (greater or equal) <= (less or equal) • Note that <= (less or equal) is same operator as <= (signal assignment); i.e., context dependent • Precedence of relational operators is between “not” and the other logical operators.

  44. Selected Signal Assignment • Another form of concurrent signal assignment is the Select assignment • Similar to a software CASE statement • we first identify the “discriminator” signal or expression we will test • values and associated conditions are then identified • Like conditional signal assignment we must ensure that all cases of discriminator are covered • “others” condition makes this easy

  45. Selected Signal Assignment General Form: WITH discriminator SELECT target_signal <= value1 WHEN choices1, value2 WHEN choices2, * valuem WHEN choicesm, valuen WHEN others; The “choices” are values of the discriminator; either single, multiple or a range.

  46. OR Selected Signal Assignment • All possible values of the discriminator must be covered • single value: when “0001”, • multiple values: when “0100” | “0110” | “1000”, • value range: when“1010” to “1111”, • everything else: when others; • The last case “when others” must be the last clause if used • Comma separates clauses, semicolon ends the statement

  47. Selected Signal Assignment WITH digit SELECT segs <= “1110111” when “0000”, “0010010” when “0001”, “1011101” when “0010”, “1011011” when “0011”, “0111010” when “0100”, “1101011” when “0101”, “0101111” when “0110”, “1010010” when “0111”, “1111111” when “1000”, “1111010” when “1001”, “1101101” when others;

  48. Vector Attributes • Attributes allow access to signal definition information • useful when designing generic VHDL • tells use range, index, length of a signal • General form is signal_name’attr_name • Some attributes are pre-defined

  49. Pre-defined Attributes Definition index value on left of range index value on right of range greatest index value of range least index value of range range expression if signal reversed signal range expression number of bits in range Name ‘left ‘right ‘high ‘low ‘range ‘reverse_range ‘length

  50. Pre-Defined Attributes signal ex std_logic_vector(11 downto 8); Attribute ex‘left ex‘right ex‘high ex‘low ex‘range ex‘reverse_range ex‘length Value 11 8 11 8 (11 downto 8) (8 to 11) 4

More Related