Digital Design Using VHDL: Using Xilinx'S Tool For Synthesis and Modelsim For Verification Part (Iii)
Digital Design Using VHDL: Using Xilinx'S Tool For Synthesis and Modelsim For Verification Part (Iii)
Using Xilinxs Tool for Synthesis and ModelSim for Verification Part (III) Ahmed Abu-Hajar, Ph.D. [email protected] Digitavid, Inc San Jose, CA
Process In VHDL
Process executes statements sequentially Syntax Label_name: PROCESS (sensitivity list) ( if no wait statement is used) --constant declaration -- variable declaration --subprogram declaration begin sequential statement; -- wait statement ( if a sensitivity list is not specified) end process label_name;
Process M2 M3
M1
M4
Sequential Statements
Must be used within processes, functions or procedures They execute sequentially ( one statement after the other)
Wait statement If statement Case statement Loop statement Next statement Exit statement Null statement
IF Statement
Syntax: If condition1 then --Sequence of statements elsif codition2 then --sequence of statement elsif codition3 then --sequence of statement else -- last sequence of statements end if; Must be within a process, function or procedure
Example: D-Latch
Open Project Navigator and create an entity for the given D-latch
clk
D Latch
Example: D-Latch
architecture Behavioral of MY_D_Latch is begin proc_1: process(clk) begin if(clk'event and clk = '1') then Q <= D; else Q <= Q; -- not required Why? end if; end process; end Behavioral; Verify your code and view the synthesizer
D Latch
clk
Example: D-Latch
Verify your code and view the synthesizer Open a new source for simulation and call it TB_My_D_Latch Test the D-Latch by assigning vlaues to the inputs
D Latch
clk
CASE Statement
Syntax
Case expression is When case1 => sequence of sequential statements; When case2 => sequence of sequential statements; . . . when others => sequence of sequential statements; end case;
Must cover all possibilities
entity MY_DEC is Port ( a : in STD_LOGIC_vector (2 downto 0); F : out STD_LOGIC_VECTOR (7 downto 0)); end MY_DEC;
3:8 DEC
8:1 MUX f
RES S
3
Wait Statement
Three Types of wait statements Wait on -- waits on a list of variables or signals Wait until -- waits until a specific condition is true Wait for -- wait for some specified time
Examples:
Wait on A, B; -- wait until an event has occurred on A or B Wait until A = 1; -- wait until A = 1 is true Wait for 10 ns; -- process will pause for 10ns
Example: A <= B or C; -- concurrent signal assignment The concurrent signal statement is activated at the beginning of the simulation and every time there is a change in B or C.
RESET
Functions in VHDL
FUNCTION is a class of subprograms FUNCTIONs compute and return value when it is invoked FUNCTION may take parameters to compute its returned value FUNCTION may not modify or change its passed parameters FUNCTION may be declared in the declaration section of the architecture or in package body FUNCTIONS are called within the architecture body Three things we need to know about functions:
Function Heading: How to declare the function Function Body: How functions evaluate the returned value Function call: how to call function to evaluate a value
Functions in VHDL
Syntax: FUNCTION function_name ( passing_parameters) RETUTN return_data_type i -- constant declarations; -- variable declarations; BEGIN -- sequential statements; -- RETURN returned_value; END function_name;
Functions in VHDL
Example: Architecture behavioral of my_one_bit_comparator is FUNCTION compare ( A:std_logic, B:std_Logic) RETUTN std_logic is BEGIN -- sequential statements; if (A = 0 and B = 1) then RETURN B; else RETURN A; End if ; END function_name; Begin f <= compare (a,b); End behavior