


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



VHDL Syntax Review Matthew Murach Basic code layout Define data types (library declarations) o IEEE_std_logic_1163.all defines bit type (0,1,U,X,-,H,L) o IEEE_std_logic_unsigned.all defines arithmetic for unsigned numbers Define user packages o Custom packages Altera,Xilinx, or you come up with So… Library ieee; -- Use IEEE libraries note that the double Use ieee.std_logic_1163.all; -- hyphen is used for commenting Use ieee.std_logic_unsigned.all; Use work.p1_pack.all; -- Your custom package can define types for -- example as well as constants Define the black box (entity declaration) o What are the inputs and outputs o What should be the name of this component o Example 1-bit adder o Needs three inputs (one bit for operands a and b and the carry c) o Needs two outputs (sum and the carry bit) o Clock and enable (optional if you want to use synchronous design) So…. Entity one_bit_add is Port( A : in std_logic; B : in std_logic; Cin : in std_logic; S : out std_logic; Cout : out std_logic; Clk : in std_logic; En : in std_logic ); end one_bit_add; Well, what is in the box…(architecture section) o Recall from logic design that the output can be computed as follows S A B Cin Cout AB BCin ACin
Cin clk
Cout
o The two outputs can be solved independently (two different trees of logic) o So use two process directives o Declare the architecture section as follows: Archtecture struct of one_bit_add is -- start defining the black box --declare signals and sub-components here Begin --start processes Sum : process(clk,en) -- clk for sync operation or use process(a,b,cin) for async --declare variables for this process Begin If clk = ‘1’ and en = ‘1’ and clk’event then --capture clk on the rising edge S <=a xor b xor c; -- logic End if; End process; Begin --start processes Carry : process(clk,en) -- clk for sync operation or use process(a,b,cin) for async --declare variables for this process Begin If clk = ‘1’ and en = ‘1’ and clk’event then --capture clk on the rising edge Cout <=(a and b) or (b and c) or (a and c); -- logic End if; End process; End struct; -- Note that the sensitivity list tells the process when to trigger. In the synchronous case -- the operation only happens when the clk pulse is received. Likewise for the -- asynchronous case, the answer is only re-evaluated on a changing input signal. Differences between variables and signals Signals are global (wire-like). That is that a signal can be used between processes. Note that it takes one delay unit for an update to occur (or one clock cycle in synchronous circuits). One one process may drive a signal, however multiple processes can read that signal. Signal assignment is concurrent. The following will swap A and B’s values ; ;
is equal to
Variables are local (register-like). Updates are immediate and the variable can be read and written several times in a clock. Variable assignment is sequential.
Cout : out std_logic; Clk : in std_logic; En : in std_logic); end component; Begin -- assign defaults c(0) <= ‘0’; -- Clearly the first carry in is zero -- For generate loops GI : for i in 0 to 3 Generate G1 : if (i /= 3) Generate cell : one_bit_add port map (A(i), B(i), C(i), S(i), C(i+1), clk,en); End Generate G1; G2 : if (i = 3) Generate cell : one_bit_add port map (A(i), B(i), C(i), S(i), S(i+1), clk,en); End Generate G2; End Generate GI; End Struct;