Basic concept of Sequential Design 7102007 DSD USIT
Basic concept of Sequential Design 7/10/2007 DSD, USIT, GGSIPU 1
Sequential code • Code written within the following statements execute sequentially. • Process • Functions • Procedures 7/10/2007 DSD, USIT, GGSIPU 2
Process • A process is a sequential section of VHDL code. • It is characterized by the presence of following statements: • • If Statements Case Statements Null Statements Loop Statements – Exit Statements – Next Statements – While loops – For loops 7/10/2007 DSD, USIT, GGSIPU 3
Process (cont. . ) • A Process must be installed in the main code, and is executed every time a signal in the sensitivity list changes (or the condition related to WAIT is fulfilled). • Syntax: [label: ] Process (sensitivity list) [variable name type [range] [: =initial value; ]] Begin (sequential code) End Process [label]; 7/10/2007 DSD, USIT, GGSIPU 4
Process Statements Label: process (sensitivity_signal_list) -- constant_declaration -- variable_declaration --Subprogram declaration -- signal declaration are not permitted here Begin --Sequential statements End process LABEL; 7/10/2007 DSD, USIT, GGSIPU 5
• Used in architectures • Every process statement within an architecture is executed once at the beginning of simulation, and thereafter, only when a signal in its sensitivity list changes value (I. e. , when there is an event on one or more of the signal in the sensitivity list). • The statements within processes must be sequential statements. 7/10/2007 DSD, USIT, GGSIPU 6
• Variables declared within processes are static. They are initialized only once at the beginning of simulation and retain their values between process activations. • The other form of process statements as no sensitivity list. 7/10/2007 DSD, USIT, GGSIPU 7
If Statements If_statement <= [if_label: ] if Boolean_expression then {sequential statement} else {sequential statement} end if [if_label]; 7/10/2007 DSD, USIT, GGSIPU 8
Caution for using if…. . else statement • Avoid using more than three levels of if…else……end if statements. • If more than three levels are required, encapsulate the inner nested levels with procedure calls. • Indent each level of if statement. • When defining the condition, use parentheses levels of operations on the condition. Group the operations in a logical and readable order. 7/10/2007 DSD, USIT, GGSIPU 9
Single bit comparator gr: a(1) >a(0) A(1) sm: a(1) <a(0) A(0) Single bit comparator eq: a(1)=a(0) 7/10/2007 DSD, USIT, GGSIPU 10
Truth table 7/10/2007 A(1) A(0) Gr Sm Eq 0 0 1 0 1 0 1 0 0 1 DSD, USIT, GGSIPU 11
Boolean equation • Gr <= a(1) and (not a(0)) • Le <= a 7/10/2007 DSD, USIT, GGSIPU 12
VHDL Code • • entity singlebitcomparator is Port ( a : in std_logic_vector(1 downto 0); en: in std_logic; • • gt : out std_logic; sm : out std_logic; eq : out std_logic); end singlebitcomparator; • • • • architecture Behavioral of singlebitcomparator is begin process (en, a) begin if (a(1)>a(0)) then gt <= '1'; sm <= '0'; eq <= '0'; elsif (a(1) < a(0)) then gt <= '0'; sm <= '1'; eq <= '0'; else gt <= '0'; sm <= '0'; eq <= '1'; end if; end process; end Behavioral; 7/10/2007 DSD, USIT, GGSIPU 13
Waveform of single bit comparator 7/10/2007 DSD, USIT, GGSIPU 14
4 -bit comparator 1 -bit comp A 1 -bit comp B 1 -bit comp 7/10/2007 DSD, USIT, GGSIPU 15
Boolean equation for 4 -bit comparator • • • Let A=a 3 a 2 a 1 a 0 Let B=b 3 b 2 b 1 b 0 Intermediate signal : i 3, i 2, i 1 and i 0 Aeq. B= i 3 i 2 i 1 i 0 Agt. B = a 3(b 3 bar)+i 3 a 2(b 2 bar)+i 3 i 2 a 1(b 1 bar)+i 3 i 2 i 1 a 0(b 0 bar) Alt. B = Not(Aeq. B+Agt. B) 7/10/2007 DSD, USIT, GGSIPU 16
VHDL code of 4 -bit comp • • entity comp 4 bit is Port ( x : in std_logic_vector(3 downto 0); y : in std_logic_vector(3 downto 0); en: in std_logic; greater : out std_logic; smaller : out std_logic; equal : out std_logic); end comp 4 bit; • • • architecture Behavioral of comp 4 bit is component singlebitcomparator is Port ( a : in std_logic_vector(1 downto 0); en: in std_logic; gt : out std_logic; sm : out std_logic; eq : out std_logic); end component singlebitcomparator; signal temp : std_logic_vector(10 downto 0); 7/10/2007 DSD, USIT, GGSIPU 17
• • • begin u 1: singlebitcomparator port map(a(1)=>x(3), a(0)=>y(3), en=>en, gt=>temp(0), sm=>temp(1), eq=>temp(2)); u 2: singlebitcomparator port map(a(1)=>x(2), a(0)=>y(2), en=>temp(2), gt=>temp(3), sm=>temp(4), eq=>temp(5)); u 3: singlebitcomparator port map(a(1)=>x(1), a(0)=>y(1), en=>temp(5), gt=>temp(6), sm=>temp(7), eq=>temp(8)); u 4: singlebitcomparator port map(a(1)=>x(0), a(0)=>y(0), en=>temp(8), gt=>temp(9), sm=>temp(10), eq=>equal); • • • greater <= temp(0) or temp(3) or temp(6) or temp(9); smaller <= temp(1) or temp(4) or temp(7) or temp(10); end Behavioral; 7/10/2007 DSD, USIT, GGSIPU 18
Waveform of 4 -bit comparator 7/10/2007 DSD, USIT, GGSIPU 19
4 x 1 Multiplexer library ieee; use ieee. std_logic_1164. all; entity mux 4_1_if is port (a: in std_logic_vector(3 downto 0); s: in std_logic_vector(1 downto 0); y: out std_logic ); end mux 4_1_if; architecture mux_behave of mux 4_1_if is begin process (s) begin if s = "00" then y <= a(0); elsif s = "01" then y <= a(1); elsif s = "10" then y <= a(2); else y <= a(3); end if; end process; end mux_behave; 7/10/2007 DSD, USIT, GGSIPU 20
Case statements A case statement selects for execution one of a number of alternative sequences of statements. The syntax for a case statement is as follows : case expression is when value => assignments; end case; 7/10/2007 DSD, USIT, GGSIPU 21
Rule for the Case statement • The case expression must be discrete type. • Every possible value of the case expression must be covered in one and only one when clause (I. e cannot duplicate a value in another “when” clause). • If the when others clause is used, it must appear as a single choice at the end of the case statement. • NULL may be used, when no action is required to take place. e. g. When OTHERS => NULL; 7/10/2007 DSD, USIT, GGSIPU 22
Rule for the Case statement…. • Case choice must be a locally static expression. • Array case expression must have a static subtype. Thus, the type of the case expression must not be based on generics. 7/10/2007 DSD, USIT, GGSIPU 23
Tips for programming using CASE • Choices in a case statement should be separated by one blank line and should be indented. • The sequence of statements should be immediately follow the case alternative specification and be indented by at least two spaces. • Keep the expression for the case statement SIMPLE. 7/10/2007 DSD, USIT, GGSIPU 24
Example 4: 1 Mux using Case statement library ieee; use ieee. std_logic_1164. all; entity mux 4_1_case is port (a: in std_logic_vector(3 downto 0); s: in std_logic_vector(1 downto 0); y: out std_logic ); end mux 4_1_case; architecture mux_behave of mux 4_1_case is begin process (s) begin case s is when "00" => y<=a(0); when "01" => y <= a(1); when "10" => y <= a(2); when others => y <= a(3); end case; end process; end mux_behave; 7/10/2007 DSD, USIT, GGSIPU 25
Comparing “if” and “case” statements • “if” statement produces priority-encoded logic • “case” statement produces parallel logic • Corresponds to “with---select” in concurrent statements. • “case” statement does not result in prioritized logic structure unlike the if statement. 7/10/2007 DSD, USIT, GGSIPU 26
Loop • Loop statement are used to execute a sequence of statements zero or more times. • Loop is intended exclusively for sequential code. • For/loop : The loop is repeated a fixed number of times. [label: ] FOR identifier IN range LOOP (sequential statements) END LOOP [label]; 7/10/2007 DSD, USIT, GGSIPU 27
Loop Statement • Three forms of loop statements: – The simple loop – The while loop – The for loop Loop_statement: : = [loop_label: ][iteration_scheme] loop sequence_of_statements End loop [loop_label]; 7/10/2007 DSD, USIT, GGSIPU 28
The Simple Loop • The simple loop does not have an explicit iteration scheme. • The implicit iteration scheme is while true, thus looping forever. • The usual way to exit an infinite loop is to use the exit statement. • The simple loop is not synthesizable. 7/10/2007 DSD, USIT, GGSIPU 29
The while loop • The while loop iterates as long as the condition expressed in the while statement is true. • This is often used to execute a set of sequential statements while a signal or a variable meets a certain criteria. • The while loop is not synthesizable. 7/10/2007 DSD, USIT, GGSIPU 30
The for loop • The loop parameter type for the for iteration loop scheme is the base type of the discrete range, and is not explicitly defined as a type. The type is implicitly defined from the range. • Syntax: [label: ] FOR identifier IN range LOOP (sequential statements) END LOOP [label]; 7/10/2007 DSD, USIT, GGSIPU 31
1. The loop parameter is not explicitly defined, but implicitly defined. 2. The loop parameter’s range is tested at the beginning of the loop, not at the end. 3. The loop parameter is an object whose type is the base type of the discrete range. 4. Inside the loop, the loop parameter is a constant. Thus, it may be used but not altered. 7/10/2007 DSD, USIT, GGSIPU 32
Rules of for loop(cont. . ) 5. The loop parameter’s discrete range may be dynamic. 6. The discrete range of the loop is evaluated before the loop is first executed. 7. The loop counter only exists within the loop 7/10/2007 DSD, USIT, GGSIPU 33
Example of For/loop FOR I in 0 to 5 loop x (i) <= enable AND w(i+2); y(0, i) <= w(i); End LOOP; NOTE: Range must be static. 7/10/2007 DSD, USIT, GGSIPU 34
Loop (cont. ) • WHILE/LOOP : The loop is repeated until a condition no longer holds. [label: ] WHILE condition LOOP (sequential statements); end LOOP [label]; 7/10/2007 DSD, USIT, GGSIPU 35
• Example WHILE/Loop While (I <10) Loop wait until clk’event and clk=‘ 1’; (other statement) End loop; 7/10/2007 DSD, USIT, GGSIPU 36
Exit Statement Exit statement: is a sequential statement that can be used only inside a loop Syntax: exit [loop-label] [when condition]; Example: SUM: = 1; J : = 0; L 3: loop J: = J + 21; SUM : = SUM * 10; if SUM > 100 then exit L 3; --only exit is also possible exited --if no loop label is specified, the innermost loop is end if; end loop L 3; 7/10/2007 DSD, USIT, GGSIPU 37
Next Statement: skipping the remaining statements in the current iteration of the specified loop; - execution resumes with the first statement in the next iteration of this loop, if one exists - can be used only inside a loop - sequential statement - if no loop label is specified, the innermost loop is assumed Syntax next [loop-label] [When condition]; 7/10/2007 DSD, USIT, GGSIPU 38
Next Statement (Example-1) Next statement can also cause an inner loop to be exited example: L 4: for K in 10 downto 1 loop ……. L 5: loop ………. next L 4 when WR_Done : = ‘ 1’; ………… end loop L 5; ……. . 7/10/2007 DSD, USIT, GGSIPU end loop L 4; 39
Example (exit and Next) For I in data’range loop case data(I) is when ‘ 0’ => count: = count +1; when others => exit; end case; End loop; 7/10/2007 DSD, USIT, GGSIPU 40
Example (next) For I in 0 to 15 loop next when I= skip; -- jump to next iteration 7/10/2007 DSD, USIT, GGSIPU 41
- Slides: 41