Download
basic concept of sequential design n.
Skip this Video
Loading SlideShow in 5 Seconds..
Basic concept of Sequential Design PowerPoint Presentation
Download Presentation
Basic concept of Sequential Design

Basic concept of Sequential Design

137 Views Download Presentation
Download Presentation

Basic concept of Sequential Design

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Basic concept of Sequential Design DSD,USIT,GGSIPU

  2. Sequential code • Code written within the following statements execute sequentially. • Process • Functions • Procedures DSD,USIT,GGSIPU

  3. 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 DSD,USIT,GGSIPU

  4. 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]; DSD,USIT,GGSIPU

  5. 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; DSD,USIT,GGSIPU

  6. 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. DSD,USIT,GGSIPU

  7. 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. DSD,USIT,GGSIPU

  8. If Statements If_statement <= [if_label:] if Boolean_expressionthen {sequential statement} elsifBoolean_expressionthen {sequential statement} else {sequential statement} end if [if_label]; DSD,USIT,GGSIPU

  9. 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. DSD,USIT,GGSIPU

  10. Single bit comparator Single bit comparator gr: a(1) >a(0) A(1) sm: a(1) <a(0) A(0) eq: a(1)=a(0) DSD,USIT,GGSIPU

  11. Truth table DSD,USIT,GGSIPU

  12. Boolean equation • Gr <= a(1) and (not a(0)) • Le <= a DSD,USIT,GGSIPU

  13. 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; DSD,USIT,GGSIPU

  14. Waveform of single bit comparator DSD,USIT,GGSIPU

  15. 4-bit comparator 4-bit comparator 1-bit comp A 1-bit comp B 1-bit comp 1-bit comp DSD,USIT,GGSIPU

  16. Boolean equation for 4-bit comparator • Let A=a3a2a1a0 • Let B=b3b2b1b0 • Intermediate signal : i3,i2,i1 and i0 • AeqB= i3i2i1i0 • AgtB = a3(b3bar)+i3a2(b2bar)+i3i2a1(b1bar)+i3i2i1a0(b0bar) • AltB = Not(AeqB+AgtB) DSD,USIT,GGSIPU

  17. VHDL code of 4-bit comp • entity comp4bit 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 comp4bit; • architecture Behavioral of comp4bit 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); DSD,USIT,GGSIPU

  18. begin • u1: singlebitcomparator port map(a(1)=>x(3),a(0)=>y(3),en=>en,gt=>temp(0),sm=>temp(1),eq=>temp(2)); • u2: singlebitcomparator port map(a(1)=>x(2),a(0)=>y(2),en=>temp(2),gt=>temp(3),sm=>temp(4),eq=>temp(5)); • u3: singlebitcomparator port map(a(1)=>x(1),a(0)=>y(1),en=>temp(5),gt=>temp(6),sm=>temp(7),eq=>temp(8)); • u4: 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; DSD,USIT,GGSIPU

  19. Waveform of 4-bit comparator DSD,USIT,GGSIPU

  20. 4x1 Multiplexer library ieee; use ieee.std_logic_1164.all; entity mux4_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 mux4_1_if; architecture mux_behave of mux4_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; DSD,USIT,GGSIPU

  21. 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; when value => assignments; end case; DSD,USIT,GGSIPU

  22. 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; DSD,USIT,GGSIPU

  23. 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. DSD,USIT,GGSIPU

  24. 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. DSD,USIT,GGSIPU

  25. Example 4:1 Mux using Case statement library ieee; use ieee.std_logic_1164.all; entity mux4_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 mux4_1_case; architecture mux_behave of mux4_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; DSD,USIT,GGSIPU

  26. 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. DSD,USIT,GGSIPU

  27. 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]; DSD,USIT,GGSIPU

  28. 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]; DSD,USIT,GGSIPU

  29. 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. DSD,USIT,GGSIPU

  30. 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. DSD,USIT,GGSIPU

  31. 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]; DSD,USIT,GGSIPU

  32. The loop parameter is not explicitly defined, but implicitly defined. • The loop parameter’s range is tested at the beginning of the loop, not at the end. • The loop parameter is an object whose type is the base type of the discrete range. • Inside the loop, the loop parameter is a constant. Thus, it may be used but not altered. DSD,USIT,GGSIPU

  33. 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 DSD,USIT,GGSIPU

  34. 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. DSD,USIT,GGSIPU

  35. Loop (cont.) • WHILE/LOOP : The loop is repeated until a condition no longer holds. [label:] WHILE condition LOOP (sequential statements); end LOOP [label]; DSD,USIT,GGSIPU

  36. Example WHILE/Loop While (I <10) Loop wait until clk’event and clk=‘1’; (other statement) End loop; DSD,USIT,GGSIPU

  37. 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; L3: loop J:= J + 21; SUM := SUM * 10; if SUM > 100 then exit L3; --only exit is also possible --if no loop label is specified, the innermost loop is exited end if; end loop L3; DSD,USIT,GGSIPU

  38. Next Statement 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]; DSD,USIT,GGSIPU

  39. Next Statement (Example-1) Next statement can also cause an inner loop to be exited example: L4: for K in10 downto1 loop ……. L5:loop ………. next L4 when WR_Done := ‘1’; ………… end loop L5; …….. end loop L4; DSD,USIT,GGSIPU

  40. 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; DSD,USIT,GGSIPU

  41. Example (next) For I in 0 to 15 loop next when I= skip; -- jump to next iteration DSD,USIT,GGSIPU