Session eight
Upcoming SlideShare
Loading in...5
×
 

Session eight

on

  • 679 views

 

Statistics

Views

Total Views
679
Views on SlideShare
679
Embed Views
0

Actions

Likes
0
Downloads
38
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Session eight Session eight Presentation Transcript

  • http://www.bized.co.uk Session 8Prepared by Alaa Salah Shehata Mahmoud A. M. Abd El Latif Mohamed Mohamed Tala’t Mohamed Salah Mahmoud Version 02 – October 2011 Copyright 2006 – Biz/ed
  • http://www.bized.co.uk - Evaluation Test 8 - Arithmetic CircuitsContents - Tutorial [2] - IP Cores - ISIM Simulator - Language Templates - VHDL Coding TIPS 2 Copyright 2006 – Biz/ed
  • http://www.bized.co.uk Evaluation TestAnswer all questions in the following paperQuestions : 50 QuestionTime : 30 minuteFull Mark : 100 degree Copyright 2006 – Biz/ed
  • Evaluation Test http://www.bized.co.ukQuestion Choice1 A2 B3 --4 --5678 Answer all questions in the paper91011121314151617181920 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.uk Arithmetic Circuits 5 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukUnsigned and Signed Types Definition Behave exactly like STD_LOGIC_VECTOR They determine whether a given vector should be treated as a signed or unsigned number. Package ieee.numeric_std.all Unsigned 0 to 2N - 1 Signed - 2(N-1) to 2(N-1) – 1 2s Complement number Example signal A : unsigned(3 downto 0) ; signal B : signed(3 downto 0) ; A <= "1111" ; -- 15 B <= "1111" ; -- -1 6 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukAmbiguous Expressions Ambiguous Z_signed <= A_signed + "1010"; Error -6 or 10 Solution Z_signed <= A_signed + signed("1010“); 7 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukAdders with Carry In Result A(3:0) + B(3:0) + Carry-In Algorithm A(3:0) , ‘1’ 011 1 011 1 B(3:0) , Carry-In 001 1 001 0 -------------------- ------- cin =1 ------- cin =0 Result(4:1) 101 0 100 0 Code Signal A,B,Y : unsigned (3 downto 0); Signal Z : unsigned (4 downto 0); Signal cin : std_logic; Z <= (A & ’1’) + (B & cin); Y <= Z(4 downto 1 ); 8 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukAdders with Carry Out Result Result + Carry-Out Algorithm ‘0’ A(3:0) 0 111 ‘0’ B(3:0) 0 100 --------------------- ------- Cout Result(3:0) 1 011 Code Signal A,B,Y : unsigned (3 downto 0); Signal Z : unsigned (4 downto 0); Signal co : std_logic; Z <= (’0’ & A) + (’0’ & B); Y <= Z(3 downto 0 ); Co <= Y(4); 9 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukType Conversions Conversions Signed & Unsigned (elements)  Std_Logic Signed & Unsigned  Std_Logic_Vector Signed & Unsigned  Integer Std_Logic_vector  Integer Conversion functions located in Numeric_Std 10 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukUnsigned.Signed  Std_Logic Conversions Converted automatically. Example A_std <= J_unsigned(0); B_std <= K_signed(7); --to std_ulogic not preferred L_unsigned(0) <= C_std; M_signed(2) <= N_std(2); 11 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukUnsigned.Signed  Std_Logic_vector Conversions Use type casting to convert equal sized arrays Example A_std <= std_logic_vector( B_unsigned ) ; C_std <= std_logic_vector( D_signed ) ; G_unsigned <= unsigned( H_std ) ; J_signed <= signed( K_std ) ; 12 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukUnsigned.Signed  Integer Conversions Use conversion functions Example Signal A,B : integer; Signal A_unsigned : unsigned(7 downto 0); Signal B_signed : signed(7 downto 0); A <= TO_INTEGER ( A_unsigned ) ; B <= TO_INTEGER ( B_signed ) ; A_unsigned <= TO_UNSIGNED ( A, 8) ; B_signed <= TO_SIGNED ( B, 8) ; Data <= ROM(( TO_INTEGER( Addr_uv)); 13 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukStd_logic_vector  Integer Conversions Use conversion functions + type casting i.e. Needs 2 steps. Example Signal A,B : integer; Signal A_std : std_logic_vector (7 downto 0); Signal B_std : std_logic_vector (7 downto 0); A <= to_integer( unsigned( A_std )); B <= to_integer( signed( B_std )); A_std <= std_logic_vector( to_unsigned( A, 8 )); B_std <= std_logic_vector( to_signed( B, 8 )); 14 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukMultiplication and Division Operators * / mod rem **Signal * Constant Z_unsigned <= A_unsigned * 2 ; Size of result = 2 * size of input signal Signal* Signal Signal A_unsigned : unsigned (7 downto 0); Signal B_unsigned : unsigned (7 downto 0); Signal Z_unsigned : unsigned (15 downto 0); Z_unsigned <= A_unsigned * B_unsigned ; Size of result = size of 1st signal + size of 2nd signal Synthesis / mod rem are not synthesis 15 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukVHDL is Strongly typed <= Less Errors ;Strong Typing  Strong Error Checking Built into the Compiler less debugging. 16Without VHDL, you must have a good Testbench+ lots of time to catch your errors. Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.uk• Signed Adder Example 35 17 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukLIBRARY ieee ;USE ieee.std_logic_1164.all ;USE ieee.numeric_std.all ;---------------------------------------ENTITY adder ISPORT ( Cin : IN STD_LOGIC ; X,Y : IN STD_LOGIC_VECTOR(15 DOWNTO 0); S : OUT STD_LOGIC_VECTOR(15 DOWNTO 0));END adder ;---------------------------------------ARCHITECTURE Behavior OF adder IS SIGNAL Xs,Ys : SIGNED(15 DOWNTO 0); SIGNAL Sum : SIGNED(15 DOWNTO 0);BEGIN Xs <= signed(X); Ys <= signed(Y); Sum <= Xs + Ys + Cin ; S <= std_logic_vector(Sum);END Behavior ; 18 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukLIBRARY ieee ;USE ieee.std_logic_1164.all ;USE ieee.std_logic_signed.all ;---------------------------------------ENTITY adder ISPORT ( Cin : IN STD_LOGIC ; X, Y : IN STD_LOGIC_VECTOR(15 DOWNTO 0) ; S : OUT STD_LOGIC_VECTOR(15 DOWNTO 0)) ;END adder ;---------------------------------------ARCHITECTURE Behavior OF adder ISBEGIN S <= X + Y + Cin ;END Behavior ;Not Recommended 19 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukENTITY adder16 ISPORT (X,Y: IN INTEGER RANGE -32768 TO 32767 ; S : OUT INTEGER RANGE -32768 TO 32767 ) ;END adder16 ;---------------------------------------ARCHITECTURE Behavior OF adder16 ISBEGIN S <= X + Y ;END Behavior ;Not Recommended 20 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.uk• UnSigned Adder Example 35 21 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukLIBRARY ieee ;USE ieee.std_logic_1164.all ;USE ieee.numeric_std.all ;---------------------------------------ENTITY adder16 IS PORT ( Cin : IN STD_LOGIC ; X, Y : IN STD_LOGIC_VECTOR(15 DOWNTO 0) ; S : OUT STD_LOGIC_VECTOR(15 DOWNTO 0)) ;END adder16 ;---------------------------------------ARCHITECTURE Behavior OF adder16 IS SIGNAL Xus : UNSIGNED(15 DOWNTO 0); SIGNAL Yus : UNSIGNED(15 DOWNTO 0); SIGNAL Sum : UNSIGNED(15 DOWNTO 0);BEGIN Xus <= unsigned(X); Yus <= unsigned(Y); Sum <= Xus + Yus + Cin ; S <= std_logic_vector(Sum) ;END Behavior ; 22 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukLIBRARY ieee ;USE ieee.std_logic_1164.all ;USE ieee.std_logic_unsigned.all ;---------------------------------------ENTITY adder16 IS PORT ( Cin : IN STD_LOGIC ; X, Y : IN STD_LOGIC_VECTOR(15 DOWNTO 0) ; S : OUT STD_LOGIC_VECTOR(15 DOWNTO 0)) ;END adder16 ;---------------------------------------ARCHITECTURE Behavior OF adder16 IS SIGNAL Sum : STD_LOGIC_VECTOR(16 DOWNTO 0) ;BEGIN S <= X + Y + Cin ;END Behavior ;Not Recommended 23 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.uk• Multiplier Example 36 24 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukLIBRARY ieee;USE ieee.std_logic_1164.all;USE ieee.numeric_std.all ;--------------------------------------- beginentity multiply isport( -- signed multiplication a : in STD_LOGIC_VECTOR(7 downto 0); sa <= SIGNED(a); b : in STD_LOGIC_VECTOR(7 downto 0); sb <= SIGNED(b); cu : out STD_LOGIC_VECTOR(15 downto 0); sc <= sa * sb; cs : out STD_LOGIC_VECTOR(15 downto 0)); cs <= STD_LOGIC_VECTOR(sc);end multiply;--------------------------------------- -- unsigned multiplicationarchitecture rtl of multiply is ua <= UNSIGNED(a); ub <= UNSIGNED(b);SIGNAL sa: SIGNED(7 downto 0); uc <= ua * ub;SIGNAL sb: SIGNED(7 downto 0); cu <= STD_LOGIC_VECTOR(uc);SIGNAL sc: SIGNED(15 downto 0); end rtl;SIGNAL ua: UNSIGNED(7 downto 0);SIGNAL ub: UNSIGNED(7 downto 0);SIGNAL uc: UNSIGNED(15 downto 0); 25 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.uk• Half Adder Example 37 26 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukLIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;---------------------------------------ENTITY HALF_ADDER ISGeneric (WIDTH : INTEGER := 8 );PORT( A : IN STD_LOGIC_VECTOR( WIDTH-1 DOWNTO 0 ); B : IN STD_LOGIC_VECTOR( WIDTH-1 DOWNTO 0 ); P : OUT STD_LOGIC_VECTOR( WIDTH-1 DOWNTO 0 ); G : OUT STD_LOGIC_VECTOR( WIDTH-1 DOWNTO 0 ));END HALF_ADDER;---------------------------------------ARCHITECTURE RTL OF HALF_ADDER ISBEGIN P <= A XOR B; G <= A AND B;END; 27 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.uk• Full Adder Example 38 28 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukLIBRARY ieee;USE ieee.std_logic_1164.all;---------------------------------------ENTITY fullAdder IS PORT( In1, In2, CarryIn : IN std_logic; Sum : OUT std_logic; CarryOut : OUT std_logic);END fullAdder;---------------------------------------ARCHITECTURE expr OF fullAdder IS signal temp : std_logic;BEGIN temp <= In1 XOR In2; Sum <= temp XOR CarryIn; CarryOut <= (In1 AND In2) OR (CarryIn AND temp);END expr; 29 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukDescribe code performing this function C = A + B*2 A,B and C are of width = 16 signed bits C = B*A A,B and C are of width = 16 signed bits lab 15 30 Copyright 2006 – Biz/ed
  • http://www.bized.co.uk Next Part is inside Start Group tutorial [2] Start Group tutorial [2]Prepared by Alaa Salah Shehata Mahmoud A. M. Abd El Latif Mohamed Mohamed Tala’t Mohamed Salah Mahmoud Version 02 – October 2011 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.uk 32 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukDesign First Data, then Controller Keep it Simple and Stupid (KISS)-VHDL coding is not a -The world’s greatest FSMsubstitute for design. won’t solve your problems -The best data block is a-Draw a block diagram of in your data blocks. dumb one.your data path using -Make sure your data -Put all of the intelligencefamiliar building blocks blocks supports your into the controller, where itfrom digital logic. algorithm. belongs.-Make certain it will work. You can fake FSM signals during simulation while you get your data blocks working. 33 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukCode What You Know Generic Your Code Reduce Simulation Time- If you don’t know how a - Generic Codes are easierconstruct will synthesize, in reading and modifying. - Simulation is a way todon’t use it. debug a design.-If you can’t draw it, you -The more time you spendcan’t code it. up front thinking about your design and how it should behave, the less time you will spend simulating. 34 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukAvoid Synthesizing Non-Clocked Process Entity InterfaceUnwanted Latches Latches -USE only In and OUT-FSM output process - All Signals in a non- modes.should define a value for clocked process should be -USE only std_logic andall output signals. in the sensitivity list . std_logic_vectors. -Recommended : Register-Don’t use concurrent - Assign a default value for your output.statements to store all signals.values. 35 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukComments-Don’t think that I canunderstand all what yousay through your code.-Help me with a lot ofcomments !! And Finally write the Tips you notice when writing your first codes. You will repeat your errors a lot but this way may help you reducing this time. 36 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukQuestions Session-8 37 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukTake Your Notes Print the slides and take your notes here--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 38 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukTake Your Notes Print the slides and take your notes here--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 39 Copyright 2006 – Biz/ed
  • Session 8 http://www.bized.co.ukSee You Next Session 40 Copyright 2006 – Biz/ed