Professional Documents
Culture Documents
VHDL Combinational Circuits
VHDL Combinational Circuits
If behavior is to depend on the value of a single expression, we can use case statement General form: CASE expression IS WHEN constant_value1=> statement1; WHEN constant_value2=> statement1; WHEN OTHERS=> statement3; END CASE;
CASE Statement
3-8 decoder
library ieee; use ieee.std_logic_1164.all; entity decoder2 is port(a: in integer range 0 to 7; y: out std_logic_vector(7 downto 0)); end decoder2; architecture dec3to8 of decoder2 is begin process(a) begin y<="00000000"; y(a)<='1'; end process; end dec3to8;
WAIT Statement
process cannot have sensititvity list when WAIT statement is employed 3 types: 1.syntax (WAIT UNTIL) WAIT UNTIL signal_condition ; E.g.: WAIT UNTIL A=B; WAIT UNTIL clkevent and clk=1; 2. syntax (WAIT ON) WAIT ON signal1,signal2,; E.g.: WAIT ON clk,rst; 3. syntax (WAIT FOR) WAIT FOR time_expression; E.g.: WAIT FOR 5ns;
Purpose
Used for a signal that is an input to an entity Used for a signal that is an output from an entity. The value of the signal cannot be used inside the entity. This means that in an assignment statement, the signal can appear only to the left of the <= operator Used for a signal that is both an input to an entity and an output from the entity Used for a signal that is an output from an entity. The value of the signal can be used inside the entity, which means that in an assignment statement, the signal can appear both on the left and right sides of the <= operator
INOUT
BUFFER
library ieee; use ieee.std_logic_1164.all; entity adder_n is generic(n: integer:=4); port(Cin: in std_logic; X, Y:in std_logic_vector(n-1 downto 0); S: out std_logic_vector(n-1 downto 0); Cout: out std_logic); end adder_n; architecture structure of adder_n is component fulladd port(Cin,x,y: in std_logic; Sum, Cout: out std_logic); end component; signal c: std_logic_vector(0 to n); begin c(0)<=Cin; Add: for i in 0 to n-1 generate Add_n: fulladd port map(C(i),X(i), Y(i), S(i), C(i+1)); end generate; Cout<=C(n); end structure;
Propagation Delay
E.g.: C<= A and B after 5ns; E<= C or D after 5ns; Concurrent: Statements evaluated any time a signal on the right side of assignment operator changes
Creating waveform
E.g.: CLK<= not CLK after 10ns; Generates a clock waveform with a period of 20ns
Constants: constant constant _name: type_name:= constant _value; Constants declared at the start of an architecture can be used anywhere within that architecture Constants declared within a process are local to that process
Signal updation using signal assignment statement: signal _name:= expression [after dealy]; Signal is scheduled to change after the delay If no delay specified then the signal is scheduled to be updated after a delta delay Variable updation using variable assignment statement: variable_name:= expression; Variable is instantaneously updated with no delay, not even a delta delay
If trigger changes at time t=10, var1,var2, var3 are updated instantly and sum computed with new variable values
Arrays
First declare an array type and then declare an array object type SHORT_WORD is array(15 downto 0) of bit Declares an array of type SHORT_WORD having an integer index with a range from 15 downto 0 with each element in the array of type bit signal data_word:SHORT_WORD; variable alt_word: SHORT_WORD:=0101010101010101; constant one_word: SHORT_WORD:= (others=>1); Can access each bit of the array E.g.: alt_word(0) Can specify a portion of the array E.g.: alt_word(5 downto 0) General form for array type and array object declaration:
type array_type_name is array index_range of element_type; signal array_name: array_type_name [:=initial_value];
1 2 3 4 5 6 7 8 9 10 11 12 matrixA(3,2) refers to the element in 3rd row and 2nd column Unconstrained array type: Dimension of the array may be undefined
type intvec is array(natural range <> ) of integer
matrixA initialised to
Two-dimensional array with unconstrained row and column index range type matrix is array( natural range <>, natural range <>) of integer;
0111|