SlideShare a Scribd company logo
1 of 120
Bài 1 ,[object Object],[object Object]
VHDL là gì? ,[object Object],[object Object],[object Object]
VHDL - Mục đích và sự hình thành ,[object Object],[object Object],[object Object],[object Object]
Chuẩn hoá VHDL ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],VHDL-87 VHDL-93 VHDL-2X
Language Subsets ,[object Object],IEEE 1076 (modeling) IEEE 1076 (synthesis)
Các mức trừu tượng trong mô tả phần cứng  Behavioral Logic RTL Layout Ít chi tiết hơn, thiết kế và mô phỏng nhanh hơn Chi tiết hơn, phụ thuộc công nghệ, thiết kế và mô phỏng chậm hơn DFF AND_OR2 CLB_R5C5 CLB_R5C6 F
Sự chồng chéo trong VHDL   Behavioral Logic RTL Layout Place & Route Utility FPGA Vendor Library Synthesizable Code Hardware Model   Sum <= A + B  after 3 ns  ; Sum <= A + B ; component  Xlx_add2     port (  A:  in  bit ;   B:  in  bit ;   Sum:  out  bit   ); end component ;
Trình tự thiết kế Top-Down  ,[object Object]
Nguyên tắc phân đoạn  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Cấu trúc Top - Down  A[3:0] entity Add_4 B[3:0 ] C_in SUM [3:0] C_out C_out Sum A B C_in entity  Full_Add A B entity Half_Add Sum Carry Leaf Cell Macro
Kiểm tra thiết kế ,[object Object],VHDL  modules Synthesis Place & Route Behavioral Simulation   (Testbench driven) Gate-Level Functional  (Netlist-driven ) Gate-Level Timing  ( Back-annotated netlist ) V I T A L  VHDL  Initiative Toward  ASIC Libraries SDF (Standard Delay Format) & Structural VHDL File
Các bước kiểm tra thiết kế   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],VHDL  modules Synthesis Place & Route
Kiểm tra thiết kế? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Test-Bench Behavioral Module    MCU FPGA PLD Memory
Kết luận ,[object Object],[object Object],[object Object],[object Object]
Bài 2 ,[object Object]
Design Units trong VHDL ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Chương trình VHDL bao gồm các design units.  Một số design units độc lập với các design unit khác.
Các loại Design Unit  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Entity ,[object Object],entity  Half_Add  is port  (A, B :  in std_logic  ; Carry, Sum :  out std_logic ) ; end  Half_Add ;  A Carry Sum B Chú thích:  VHDL’93 cho phép dùng optional reserved word  entity  ngay sau  reserved word  end,  ví dụ ,  ‘end entity  Half_Add  ; ’
Architecture ,[object Object],[object Object],architecture   My_Arch   of   Half_Add  is begin Sum <= A xor B ; Carry <= A and B ; end  My_Arch ;   Note :  VHDL’93 cho phép sử dụng reserved word   architecture   sau reserved word   end
Multiple Architecture ,[object Object],[object Object],entity   Half_Add   is   . . . end   Half_Add  ;  architecture  BEH   of  Half_Add   is   . . . end  BEH  ;  architecture   RTL   of  Half_Add  is   . . . end  RTL  ;  architecture   XLX   of   Half_Add   is   . . . end  XLX  ;  entity   Cnt64   is   . . . end   Cnt64  ;  architecture  BEH   of  Cnt64   is   . . . end  BEH  ;  architecture   RTL   of  Cnt64  is   . . . end  RTL  ;  architecture   XLX   of   Cnt64   is   . . . end  XLX  ;
Package ,[object Object],[object Object],package   My_Pack  is constant. . .   . . . function. . . . . . component . . . . . . subtype. . . end package  My_pack ; library IEEE; use  IEEE.std_logic_1164.all ; . . . use work. My_Pack .all ; entity . . .
Package Body ,[object Object],[object Object],package  My_Pack  is constant. . .   . . . function bv_to_integer ( . . . component . . . . . . subtype. . . end My_Pack ; package body  My_Pack  is function bv_to_integer (BV: bit_v..   return  integer is   variable …   begin    for index in BV'range loop   . . . . . . . end  My_Pack ; declaration details
Library  ,[object Object],[object Object],[object Object],package   std_logic_1164  is .. package   std_logic_arith  is .. package   std_logic_unsigned  is .. library  IEEE ;
Library  ,[object Object],[object Object],package   std_logic_1164  is .. package   std_logic_arith  is .. package   std_logic_unsigned  is .. library  IEEE ;
Khởi tạo các Library  ,[object Object],[object Object],package   Fast_Counters  is .. package   DSP_Filters  is .. library  My_Lib ; use   My_Lib.Fast_Counters .all  ; entity  Mod1  is   port  ( . . . library  My_Lib
Khởi tạo các Library  ,[object Object],[object Object],package   Fast_Counters  is .. package   DSP_Filters  is .. library  My_Lib ; use   My_Lib.Fast_Counters .all  ; entity  Mod1  is   port  ( . . . library  My_Lib
Work Library ,[object Object],[object Object],[object Object]
Work Library ,[object Object],[object Object],Design Unit   Identifier entity  HALF_ADD entity  DFF entity  REG4 package  My_Counters . . . architecture  RTL architecture  STRUCTURAL Secondary (dependent) design units tham trỏ tới primary unit tương ứng với nó
Ví dụ về Hierarchy : DFF entity   DFF  is   port (D, Clock : in std_logic ;   Reset : in std_logic ;    Q : out std_logic) ; end entity DFF ;   architecture  RTL  of  DFF  is begin   process  (Clock, Reset)   begin   If  (Reset = ‘1’ ) then    Q <= ‘0’ ;   elsif (Clock’event and Clock = ‘1’) then    Q <= D ;   end if ;   end process  ; end architecture RTL ;   Clock Reset D Q
Ví dụ về Hierarchy : REG-4 entity  REG_4  is   port  (D_in :  in std_logic_vector  (3 downto 0);    Clk, Rst :  in std_logic ;   Q_out :  out std_logic_vector  (3 downto 0));  end  REG_4;  architecture  Structural  of  REG_4   is component  DFF    port (  D, Clock  : in  std_logic ;   Reset  : in  std_logic;   Q  : out  std_logic  ) ;  end component ;  begin U3  :  DFF   port map  ( D_in(3), Clk, Rst, Q_out(3)); U2  :  DFF   port map  ( D_in(2), Clk, Rst, Q_out(2));   U1  :  DFF  port map  ( D_in(1), Clk, Rst, Q_out(1));   U0  :  DFF  port map  ( D_in(0), Clk, Rst, Q_out(0)); end  Structural ;   Clk Rst D_in(3) D_in(2) D_in(1) D_in(0) Q_out(3) Q_out(2) Q_out(1) Q_out(0) DFF DFF DFF DFF U3 U0 U1 U2 REG_4
Liên kết Tín hiệu ,[object Object],[object Object],[object Object],component  DFF    port  ( D, Clock  : in std_logic ;    Reset  : in std_logic ;   Q  : out std_logic ) ; end  component ;
Liên kết Tín hiệu ,[object Object],[object Object],[object Object],component  DFF    port  ( D, Clock  : in std_logic ;    Reset  : in std_logic ;   Q  : out std_logic ) ; end  component ;
Signal Declaration ,[object Object],architecture   Structural  of  Top  is component  Sub_A    port  (A1, A2, A3 :  in std_logic ;   A4 :  out std_logic_vector (3 downto 0))  ;  end component  ;  component  Sub_B    port  (B1:  in  std_logic_vector (3 downto 0 ) ;   B2, B3, B4 :  out std_logic)  ;  end   component  ;  signal  Bus_1 :  std_logic_vector (3 downto 0) ; signal  Sig_1:  std_logic ; begin U0 : Sub_A   port map ( I1, I2,  Sig_1, Bus_1 )  ; U1 : Sub_B  port map  ( Bus_1, Sig_1 , O1, O2)  ;     end  Structural ;  Sub_A Sub_B Top I1 I2 O1 O2 Sig_1 Bus_1 A1 A2 A4 A3 B4 B3 B2 B1 entity  Top  is   port   (I1, I2 :  in std_logic;     01, 02 :  out std_logic)  ; end  Top ;
Cụ thể hoá phần tử  entity REG_4 is   port (D_in : in std_logic_vector (3 downto 0) ;    Clk, Rst : in std_logic ;   Q_out : out std_logic_vector (3 downto 0)) ;  end REG_4 ;   architecture Xilinx_Struct of REG_4 is component FDC    port  (D : in std_logic ;   Clock, Reset : in std_logic ;   Q : out std_logic) ;  end component ;  begin U3  :  FDC  port map (D=>D_in(3), Clock=>Clk,  Reset=>Rst, Q=> Q_out(3)) ; U2  :  FDC  port map (D=>D_in(2), Clock=>Clk,  Reset=>Rst, Q=> Q_out(2)) ; U1  :  FDC  port map (D=>D_in(1), Clock=>Clk,  Reset=>Rst, Q=> Q_out(1)) ; U0  :  FDC  port map (D=>D_in(0), Clock=>Clk,  Reset=>Rst, Q=> Q_out(0)) ; end Xilinx_Struct ;   ,[object Object],Clk Rst D_in(3) D_in(2) D_in(1) D_in(0) Q_out(3) Q_out(2) Q_out(1) Q_out(0) FDC FDC FDC FDC U3 U2 U1 U0
Sử dụng Generics ,[object Object],[object Object],library  IEEE; use  IEEE.std_logic_1164.all; use  IEEE.std_logic_unsigned_all; use  IEEE.std_logic_arith.all; entity  My_Cntr is    generic  ( Count_Width  :  integer  := 8 );   port  ( Data_In:  in std_logic_vector  ( Count_Width  -1  downto  0);   Clk, Reset, Load, UpDn :  in std_logic ;   Q_Out:  out std_logic_vector  ( Count_Width  -1  downto  0));   end entity  My_Cntr; architecture RTL of My_Cntr is •  •   •   •   end architecture RTL;    Lab Marker
Cập nhật giá trị của Generics ,[object Object],[object Object],library  IEEE; u se  IEEE.std_logic_1164.all; use  IEEE.std_logic_unsigned_all;  use  IEEE.std_logic_arith.all; entity  MY_TOP_DESIGN  is     port  ( DATA_BUS:  in std_logic_vector  (63  downto  0);   CLOCK, RST, LD, CNTRL :  in std_logic ;   DATA_Out:  out std_logic_vector  (63  downto  0)) ;   end entity  MY_TOP_DESIGN; architecture STRUCTURAL  of  MY_TOP_DESIGN  is component My_Cntr   generic  (  Count_Width  :  integer  := 8 );   port  ( Data_In:  in std_logic_vector  ( Count_Width  -1  downto  0);   Clk, Reset, Load, UpDn :  in std_logic ;   Q_Out:  out std_logic_vector  ( Count_Width  -1  downto  0));   end component  ; begin U0: My_Cntr  generic map  (Count_Width => 64)    port map   (DATA_BUS, CLOCK, RST, LD, CNTRL, DATA_OUT ) ;   • •  •   •   end architecture  RTL;
Biên dịch VHDL  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Quy trình biên dịch ,[object Object],Analyze Elaborate Execute Synthesize
Trình tự Biên dịch  ,[object Object],[object Object],[object Object],[object Object],[object Object]
Comments ,[object Object],- -  Comments bắt đầu bằng hai dấu gạch ngang  - -  Chúng chỉ tiếp tục cho đến hết dòng - -   Một comment trên nhiều dòng cần phải dùng  - -  hai dấu gạch ngang trên tất cả các dòng   A_OUT <= ‘1’   ;   - -  Comments có thể viết từ đây
Kết luận ,[object Object],[object Object],[object Object],[object Object]
Bài 3 ,[object Object]
Data Types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Signals và Ports ,[object Object],entity  REG_4  is port   ( D_in1 :  in  std_logic_vector (3 downto 0);   Cntrl  : in  std_logic_vector (1 downto 0);    Clock,   Reset :  in  std_logic ;   Q_out :  out  std_logic_vector (3 downto 0));  end entity  REG_4;  signal   A :   integer ;  signal  B  :  bit ; signal  C :  integer ; signal  D :  std_logic ;   A <= C; A <= C + 1; A <= B; D <= C; B <= D; Q_out <= Cntrl;
Các loại data type trong VHDL  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Scalar Data Types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Bit và Boolean  ,[object Object],[object Object],type  bit  is ( ‘0’, ‘1’ ) ; type  boolean  is   ( false, true ) ; architecture  BEHAVE  of  MUX is signal  A,B,Sel, Z  :   bit  ;  begin   if  Sel = ‘1’  then   Z <= A ;    else   Z <= B ;   end if  . . . if Sel =‘1’,  if  F  >=  G.. both yield boolean result
Integer và Real ,[object Object],[object Object],[object Object],[object Object],[object Object],type  integer  is range . . . type  real  is range . . . signal   A :  integer  range 0 to 7; signal  B  : integer  range 15 downto 0 ; type  CAPACITY  is range -25.0 to 25.0 ; signal  Sig_1 : CAPACITY := 3.0 ;
Physical ,[object Object],[object Object],[object Object],Time   l à kiểu vật lý duy nhất được định nghĩa trong  VHDL.  N ó rất cần thiết cho việc mô phỏng thời gian trễ và các tham số khác có liên quan thời gian . type  time  is range 1 to 1000000   units fs; ps = 1000 fs; ns = 1000 ps; us = 1000 ns; ms = 1000 us;   . . . constant  Tpd :   time   := 3ns ;  . . . Z <= A  after  Tpd ;
Std_logic và Std_ulogic ,[object Object],[object Object],[object Object],type  std_ulogic  is   ( ‘U’,  -- Uninitialized   ‘X’,  -- Forcing Unknown ‘0’,  --  Forcing Zero ‘1’,  --  Forcing One ‘Z’,  --  High Impedance   ‘W’,  -- Weak Unknown ‘L’,  --  Weak Zero ‘H’,  --  Weak One ‘ - ‘  --  Don’t Care    ) ; Recall:  type  bit  is limited to (‘0’, ‘1’).
So sánh Std_logic và Std_ulogic ,[object Object],[object Object],[object Object],[object Object],[object Object],signal   A,B,C,Res_Out :  std_logic   ; signal  Out_1 :  std_ulogic   ; Out_1 <= A ; Out_1 <= B ; Out_1 <= C ; C B A Out_1 C B A Res_Out <= A; Res_Out <= B; Res_Out <= C; Res_Out X
Signal Resolution ,[object Object],[object Object],signal   A,B,C,Res_Out :  std_logic   ;   C B A Res_Out <= A when En0 = ‘1’ else ‘Z’ ; Res_Out <= B when En1 = ‘1’ else ‘Z’ ; Res_Out <= C when En2 = ‘1’ else ‘Z’ ; Res_Out En0 En2 En1
Enumerated (liệt kê) ,[object Object],[object Object],[object Object],type   My_State   is   (  RST, LOAD, FETCH, STOR, SHIFT  ) ; . . . signal   STATE, NEXT_STATE  :  My_State  ; . . .   case  ( STATE )  is when  LOAD => . . . if  COND_A   and  COND_B  then NEXT_STATE  <=  FETCH ; else   NEXT_STATE  <= STOR ;
Composite Data Types ,[object Object],[object Object],[object Object],[object Object],signal  A_word  :  bit_vector  (3 downto 0)  :=  “0011”  ;
Array ,[object Object],type  WORD  is  array (3 downto 0) of  std_logic ; index position 0 1 2 3 B_bus Nếu B_bus có kiểu WORD, giá trị có thể có của các phần tử là?  Còn nếu B_bus có kiểu DATA? signal  B_bus   :   WORD ; type  DATA  is array (3 downto 0)  of  i nteger range 0 to 9  ; signal  B_bus   :   DATA ;
Phép gán các Array  ,[object Object],[object Object],[object Object],[object Object],signal My_BusA, My_BusB: bit_vector (3 downto 0) ; signal My_BusC : bit_vector (0 to 3) ; 3 0 1 2 3 0 1 2 My_BusA My_BusB My_BusB <= My_BusA ; My_BusA 3 0 1 2 0 3 2 1 My_BusC Inadvertent  bit-swap? My_BusC <= My_BusA ;
Cách viết lệnh gán Array ,[object Object],[object Object],Data_Word <= X”A6F”; Data_Word <= ”101001101111” ; Data_Word <= O”5157”; Data_Word <= B”1010_0110_1111” ; signal  Data_Word  : std_logic_vector (11 downto 0) ;
Records Record  là nhóm các phần tử đơn có kiểu ban đầu có thể khác nhau . type  OPCODE   is  record PARITY :  bit; ADDRESS :  std_logic_vector ( 0 to 3 ); DATA_BYTE :  std_logic_vector ( 7 downto 0 ); NUM_VALUE :  integer range 0 to 6; STOP_BITS : bit_vector (1 downto 0); end record  ; . . . signal  TX_PACKET, RX_PACKET  :  OPCODE ; PARITY ADDRESS DATA_BYTE NUM_VALUE STOP_BITS . . . T X _ P A C K E T
String String  là array của các character  signal Warning1: string (1 to 30) := “  Unexpected Outputs Detected”  ;   --declared within the architecture   variable Warning2: string (1 to 30) := “  Unstable, Aborting Now” ;   --declared within the process   constant Warning3: string (1 to 20) :=  “ Entering FSM  State2” ;   --declared within the package or architecture process  ( A_sig , B_sig, C_sig )   begin   if  ( A_sig  and  B_sig  ) /= ‘1’ then   report  Warning1 ;   elsif (  A_sig  and  C_sig  ) = ‘1’  then   report  Warning2 & “ Problem Mod2 “;    end if ; end process ; process  ( A_sig , B_sig, C_sig )   begin   assert  ( A_sig  and  B_sig  ) /= ‘1’ then   report  Warning1 ;   severity  note  ;    end if ; end process ; process  ( A_sig , B_sig, C_sig )   begin   if  ( A_sig  and  B_sig  ) /= ‘1’ then   report  “ Unexpected Outputs…”  ;   elsif (  A_sig  and  C_sig  ) = ‘1’  then   report  “ I need a vacation  “;    end if ; end process ;
Phép gộp các Array  ,[object Object],signal  H_BYTE, L_BYTE:  std_logic_vector ( 0 to 7);  signal  Q_Out :  std_logic_vector (31 downto 0);  signal  A, B, C, D  :  std_logic; signal  WORD   :  std_logic_vector (3 downto 0);  (A,B,C,D)<=WORD;   WORD  <=  (  A, B, C, D )  ; Q_Out  <=  (  others  => ‘0’ ) ;   WORD  <= ( 2 => ‘1’, 3 => D,  others  => ‘0’ ) ;   The total number of elements on both sides of any assignment must match, “others” can be used as a default assignment, regardless of the array size Only scalar data variables are allowed on the left-side aggregates. H_Byte  <= ( 7|6|0 => ‘1’, 2 to 5 => ‘0’ ) ;
Gộp các Record ,[object Object],type  D_WORD  is record   UPPER  : std_logic_vector (7 downto 0 ) ;   LOWER  : std_logic_vector (7 downto 0 ) ; end record ; signal  DATA_WORD : D_WORD  ; signal  H_BYTE, L_BYTE:  std_logic_vector (7 downto 0);  signal  TX_PACKET, RX_PACKET : OPCODE ; --defined earlier TX_PACKET  <= ( ‘1’,”0011”,”11101010”,5,”10” ) ;   TX_PACKET. ADDRESS  <= ( “0011” ) ; Only records can accept aggregate of arrays  TX_PACKET. ADDRESS(2)  <= ‘0’ ; DATA_WORD <= ( H_BYTE, L_BYTE) ;  DATA_WORD <= ( LOWER => L_BYTE, UPPER=> H_BYTE) ;  DATA_WORD <= ( LOWER |  UPPER=> H_BYTE);  DATA_WORD <= (  others =>  H_BYTE);
Tạo lập các Array 2-D ,[object Object],[object Object],type   Mem_Array  is  array ( 0 to 3 )   of  std_logic_vector ( 7  downto 0);   signal   My_Mem : Mem_Array ;  0   1   2   3 7  6  5  4  3  2  1  0
Tạo Array của các Record ,[object Object],type   Data_Array  is array ( 0 to 2 ) of  OPCODE ; signal   My_Data : Data_Array ;  My_Data type  OPCODE   is  record PARITY  :  bit; ADDRESS :  std_logic_vector ( 0 to 3 ); DATA_BYTE :  std_logic_vector ( 7 downto 0 ); NUM_VALUE :  integer range 0 to 6; STOP_BITS : bit_vector (1 downto 0); end record  ; . . . signal  TX_PACKET, RX_PACKET  :  OPCODE ; PARITY ADDRESS DATA_BYTE NUM_VALUE STOP_BITS . . . . . . . . .
Phép gán các Array 2-D ,[object Object],My_Mem ( conv_integer(  W_Addr)) <= Data_In ;   . . .   D_Out <= My_Mem ( conv_integer  (R_Addr));   type   Mem_Array  is array ( 0 to 3 ) of std_logic_vector ( 7 downto 0 ); signal   My_Mem : Mem_Array ; signal   R_Addr, W_Addr :  std_logic_vector   (1 downto 0 )  ;  7  6  5  4  3  2  1  0 0   1   2   3
Initializing a ROM Array  ,[object Object],constant  My_ROM : ROM_Array := (   0 => (others => ‘1’) ,   1 => “10100010”,   2 => “00001111”,   3 => “11110000”  ) ;  type   ROM_Array  is array  ( 0 to 3 ) of  std_logic_vector ( 7 downto 0); constant   My_ROM : ROM_Array :=  --continued below  7  6  5  4  3  2  1  0 0   1   2   3
Kiểu con trong VHDL ,[object Object],[object Object],[object Object],subtype   My_Int  is integer range  0  to  255 ; Label Base Type Constraint subtype  My_Small_Int  is  My_Int   range  5  to  30 ;
Sử dụng kiểu con trong VHDL type  My_State  is  ( Load, Jump,  Add, Sub, Div, Mult , StorA, StorB) ; signal  Curr_State, Next_State :  My_State  ; Label Base Type Constraint subtype  Arith_Ops  is  My_State  range   Add   to   Mult  ; subtype  My_OHE_State  is std_logic_vector ( 3 downto 0 ) ;    constant  Init_St0  : My_OHE_State := “0001” ;   constant  Load_St1  : My_OHE_State := “0010” ;   constant  Jump_St2  : My_OHE_State := “0100” ;   constant  Stor_St3  : My_OHE_State := “1000” ;
Bài 4 ,[object Object]
Các toán tử trong VHDL ,[object Object],[object Object],[object Object],[object Object],[object Object]
Operator Overloading ,[object Object],[object Object],Compiler tự động chọn sub-function thích hợp dựa trên data type của các operands signal  A, B  :  std_logic_vector  ( 3  downto  0 ) ; signal   C, D  :  integer range  0 to 31 ; signal   Q_Out :  std_logic_vector  ( 15 downto 0 );  Y <=  A + B  ;  -- add 2 vectors F <=  C + D  ;  -- add 2 integers Q_Out <= Q_Out + 1;  -- add vector and integer
Các toán tử Logic ,[object Object],and or nand nor xor not xnor   (VHDL-93) Y <= G  or  ( F  and  H ) ; Z <=  A  and   B ; Z B A F H G Y
Các toán tử Logic với biến kiểu Array Quy tắc sử dụng với biến kiểu Array 1. Các array phải có cùng kiểu (type) 2. Các array phải có cùng kích thước 3. Phép toán thực hiện với các phần tử cùng vị trí trong mỗi array, từ trái sang phải signal   A_vec,  B_vec,  C_vec  :   bit_vector  ( 7  downto  0 ) ; B_vec (7) A_vec (7) C_vec (7) B_vec (6) A_vec (6) C_vec (6) B_vec (5) A_vec (5) C_vec (5) B_vec (0) A_vec (0) C_vec (0) . . . C_vec   <=  A_vec  and   B_vec ;
Các toán tử quan hệ ,[object Object],[object Object],=  Equality /=   Inequality <  Less than <=   Less than or equal  >  Greater than >=  Greater than or equal signal   FLAG_BIT  :   boolean ; signal   A, B  :   integer ; FLAG_BIT  <=  (  A  >   B  ) ;  Nếu A lớn hơn B, FLAG_BIT sẽ được gán giá trị  true,  ngược lại  FLAG_BIT được gán giá trị   false
Toán tử quan hệ với các Array ,[object Object],[object Object],[object Object],Rules for use on Arrays 1. Arrays must be same type 2. Arrays may be different lengths 3. Arrays of different lengths are aligned left and then lexically compared -- Compares ASCII values signal   A_vec  :   bit_vector  ( 7  downto  0 ) := “11000110” ; signal   B_vec  :   bit_vector  ( 5  downto  0 ) := “111001” ; if  ( A_vec  >  B_vec )  then State  <=  Normal else State  <=  Code_Red end if  …
Các toán tử số học ,[object Object],[object Object],+   Addition -  Subtraction *  Multiplication /  Division  abs   Absolute Value **  Exponentiation signal   A_num, B_num  : integer  range  0 to 15 ;  signal   Z_num  : integer  range  0 to 31 ;  Z_num  <=  (  A_num  +  B_num  ) ;  + Z_num A_num B_num Infers a 5-bit adder
Phép tính số học với các biến Array ,[object Object],[object Object],[object Object],[object Object],package  STD_LOGIC_UNSIGNED   is   function   “+” (A,B: std_logic_vector) return  std_logic_vector ;   function “+” (A: std_logic_vector, B: integer ) return  std_logic_vector ;   function “+”  (A,B: std_logic_vector) return  integer ; . . . . library  IEEE ; use IEEE.std_logic_1164.all ; use  IEEE.Std_Logic_Unsigned.all ; use IEEE.Std_Logic_Arith.all;
Array Arithmetic  ,[object Object],[object Object],signal   A_vec  :   std_logic_vector  ( 7  downto  0 )  :=  “11001001”  ; signal   B_vec  :   std_logic_vector  ( 7  downto  0 )  :=  “11100100 ”  ; signal   Z_vec  :   std_logic_vector  ( 8  downto  0 )   ; signal   D_int  :  integer  range  ( 0  to  9 )   ; Z_vec  < =  A_vec  +  D_int  ; Z_vec  < =  A_vec  +  B_vec  ;
Các toán tử Shift (dịch) ,[object Object],[object Object],[object Object]
Các toán tử Shift (dịch) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Shift Operator - Các ví dụ   ,[object Object],[object Object],[object Object],D_vec <= A_vec sll  2; D_vec <= A_vec sra 2; D_vec <= A_vec ror  3; D_vec <= A_vec srl  2; D_vec <= A_vec sra -2; “ 00011000” “ 11110001” “ 11011000” “ 00110001” “ 00011000” cho kq
Concatenation ,[object Object],[object Object],signal   A_vec, B_vec :  std_logic_vector  ( 7  downto  0 ) ;  signal   Z_vec :  std_logic_vector  ( 15  downto  0 ) ; signal   A_bit, B_bit, C_bit, D_bit :  std_logic ; signal   X_vec :  std_logic_vector  ( 2  downto  0 ) ; signal   Y_vec :  std_logic_vector  ( 8  downto  0 ) ; Z_vec  <=  A_vec & B_vec ; X_vec  <=  A_bit & B_bit & C_bit ; Y_vec  <=  B_vec & D_bit ;
Nhóm các toán tử ,[object Object],Z  <=  A  +  B  +   C  +  D ; Z  <=  ( A  +  B )  +  ( C  +  D ) ; B A C D Z 3 logic levels D Z A B C 2 logic levels This is especially important when the target technology is LUT (Look-Up Table)  based.  Each added level of logic incurs additional block  and  routing delays + + + + + +
Các Slice của Array ,[object Object],[object Object],signal  A_vec, B_vec :  std_logic_vector  (7  downto  0) ;  signal  Z_vec :  std_logic_vector  (15  downto  0) ; signal  A_bit, B_bit, C_bit, D_bit :  std_logic ;  Z_vec  (15 downto 8)  <=  A_vec ; B_vec  <=  Z_vec  (12 downto 5)  ; A_vec  (1 downto 0)  <=  C_bit & D_bit ;   . . . Z_vec  (5 downto 1)  <=  B_vec  (1 to 5 )  ; The direction (ascending or descending) of the slice must be consistent with the direction of the array as it was originally declared
Slice và Concatenation ,[object Object],[object Object],signal   Status_Bus :  std_logic_vector  (15  downto  0) ; signal   Int_Bus :  std_logic_vector  ( 5  downto  0 ) ; . . .  Int_Bus <= Status_Bus ( 9  downto  8 ) & Status_Bus ( 3  downto  0 ) ; Inefficient !! process  ( Status_Bus ) begin case  ( Status_Bus )  is   when “110111 11 0101 0011 ” =>    < sequential statement(s) > ;   when . . . process  ( Status_Bus ) begin case  ( Status_Bus(9 downto 8) & Status_Bus (3 downto 0))  is   when “ 110011 ” =>    < sequential statement(s) > ;   when . . . Will Not Compile! process  ( Int_Bus ) begin case  ( Int_Bus )  is   when “ 110011 ” =>    < sequential statement(s) > ;   when . . . Optimal !!
Bài 5 ,[object Object]
Mô hình hoá phần cứng ,[object Object],[object Object],[object Object],[object Object]
Cấu trúc ngôn ngữ   architecture  RTL  of  ENTITY_1  is      .  .  .    begin   concurrent statements ; . . .   process   begin   sequential  statements ;   . . .   end process ; . . .   concurrent statements ;   . . .   process   begin   sequential  statements ;   . . .   end process ;   ... end architecture RTL  ; ,[object Object]
Process ,[object Object],[object Object],[object Object],[object Object],architecture   RTL of My_And2 is begin . . . process  (A, B) begin   C <= A and B ; end process  ; . . . end architecture RTL;
Các Process là đồng thời ,[object Object],[object Object],G1 G2 G3 B A C C<=A and B ... Process 1 process (C,..) begin Process 3 If  C = ‘1’ then   ... Process 2 C C
Mô hình kết nối trong VHDL ,[object Object],[object Object],C<=A and B ... Process n process (C,..) begin Process n2 If  C = ‘1’ then   ... Process n1 C C process n   process ( ... Rst Sig1 Sig2 Process n4 Process n3
Các thành phần của Process  architecture   Behave  of  DFF  is begin . . . Reg1 :  process   ( Clock, Reset ) begin if  Reset  = ‘1’  then  Q  <= ‘0’ ; elsif  (  Clock ’event and  Clock  = ‘1’ )  then  Q <=  D ; end  if ; end   process ; . . . end   Behave ;  Optional Label Signals in sensitivity  list create  implied     “wait” condition Signal updated with  new value when  process suspends All statements within  the process are handled  sequentially, in order Keyword Keywords “end”  and “process”
Bên trong và bên ngoài Process architecture ... process  (  )  begin   Out1 <= A;   Out1 <= B;   . . .   end  process   ; end  architecture ; architecture  . . .     begin   Out1 <= A;   Out1 <= B;   . . .  end  architecture  ; B B Chỉ có phép gán cuối cùng là có hiệu lực Out1 ? Out1 A Cần phải có một hàm resolution cho tín hiệu ra ‘Out1’
Tạm dừng các Process ,[object Object],[object Object],[object Object],[object Object],wait on...   An event on given signal  wait until... A specific condition  wait for   ...   A specified time amount  wait  Indefinite suspension wait on   A, B ; wait until  CLK = ‘1’   ; wait for  10  ns  ; wait;
Các điều kiện Wait ,[object Object],[object Object],FYI: Another important consideration is that all processes are initialized before simulation, that means they are run until the first ‘wait’ condition is met Given that fact, what is the value on ‘C’ at simulation time zero — assuming use of std_logic for each of the examples above ? process  (A, B)  begin   C <= A  and  B  ; end process ;   process  begin   wait on   A, B  ;   C <= A  and  B  ; end process ;   process  begin    C <= A  and  B  ;   wait on   A, B  ; end process ;
Modeling Concurrency ,[object Object],[object Object],[object Object],[object Object],Simulation  discrete time step  998 999 1000 1001 D1 D+n D+2 D+1 1002 . . . Delta cycles in-between  D1 D+2 D+1 . . . Delta cycles in-between  Concurrent Operations
Sắp xếp trình tự các Event ,[object Object],[object Object],[object Object]
Scheduling Events Simulation  discrete time steps  t t+1 t+2 t+3 D1 D+n D+2 D+1 t+4 . . . Delta cycles  D1 D+2 D+1 . . . Delta cycles  Transaction Queue t + 3 t + 4 t + 5 . . . . . . Int <= ‘1’ Data<= ‘0’ Out1 <= ‘1’ ; Out2 <= ‘0’ ; . . . Int <= ‘1’ after 1 ns; . . . Data <= ‘0’ after 2 ns; . . . . . . Out2<= ‘0’ Out1<= ‘1’ ns Discrete Time Delta  Cycles
[object Object],[object Object],Transactions process  (. . .)  begin   Z <= A ;   F <= G ;   . . . end process  ;
Events ,[object Object],[object Object],[object Object],process (A, G)   begin   Z <= A;   F <= G;   . . . end  process  ; Z<=A; ... Process 1 process (Z,..) begin Process 3 If  Z = ‘1’ then  ... Process 2 Z Z
Building Registers process   ( Clk)   begin   if  (Clk’ event   and  Clk = ‘1’)  then     C <= A  and   B ;    end if;  end process; Mọi phép gán tín hiệu xảy ra sau mệnh đề: if clock’event and clock = ‘1’ then... đều tạo ra một cấu trúc thanh ghi (register) C Clk B A
Khái quát về Signal và Variable trong VHDL  ,[object Object],[object Object],[object Object],[object Object],[object Object]
Phạm vi của Signal và Variable ,[object Object],[object Object],[object Object],entity architecture  Input Ports Signals process  Variables Output Ports
Phép gán với Signal  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Phép gán với Signal entity   Count_1  is port  (Clk, D :  in   bit  ;   Q :  out   integer  range...);  end  Count_1;  architecture   WRONG   of   Count_1  is begin process  (Clk) begin   If Clk’ event   and  Clk =‘1’  then     Q <= Q + 1; end if ; end process ; Q Internal_Cnt Will produce compiler error architecture  RTL  of   Count_1  is signal   Internal_Cnt :  integer range ... ; begin process  (Clk)   begin   If Clk’ event   and  Clk =‘1’  then     Internal_Cnt <=  Internal_Cnt + 1 ;   end if ; end process ; Q <=  Internal_Cnt ; Counter
Using Variables ,[object Object],[object Object],[object Object],[object Object],[object Object]
Variable trong các Process có Clock process   ( Clk )   variable   B, C, D  :  bit := ‘1’ ;    begin   If  ( Clk ’event and  Clk  =‘1’)  then   B := A ;     C := B ;   D := C ;   end  if  ;  end  process ; Clk A D process   ( Clk )   variable   B, C, D  :  bit := ‘1’  ;   begin   If (  Clk ’event and  Clk  =‘1’ ) then   D := C ;     C := B ;   B := A ;   end  if  ; end  process ; Clk A C B D
entity   Count_1  is port  (Clk, D :  in   std_logic  ;   Q :  out   std_logic_vector  ...);  end  Count_1;  architecture   WRONG   of   Count_1  is begin process  (Clk) begin   If Clk’ event   and  Clk =‘1’  then     Q <= Q + 1; end if ; end process ; Q Internal_Cnt Alternate Solution Will produce compiler error architecture  RTL  of   Count_1  is begin process  (Clk)   variable Internal_Cnt :  std_logic_vector ..   begin   If Clk’ event   and  Clk =‘1’  then     Internal_Cnt :=  Internal_Cnt + 1 ;   Q <=  Internal_Cnt ;   end if ; end process ; Counter
Các lệnh điều khiển chương trình trong VHDL Bài 6
Cấu trúc ngôn ngữ   architecture  RTL  of  ENTITY_1  is      .  .  .    begin   concurrent statements ; . . .   process   begin   case ( sel_a ) is   when…   . . .   end case ;   end process ; . . .   . . .   process   begin   if (sel_b = “00”) then   . . .   else….   end if ;   end process ;   ... end architecture RTL  ; ,[object Object]
Các câu lệnh  If/Else ,[object Object],process begin if  (boolean expression)   then sequential statements; end if  ;   process begin if  (boolean expression)   then sequential statements ; else  sequential statements ;  end if  ;   process begin if  (boolean expression 1)  then sequential statements ; elsif  (boolean expression 2)   then  sequential statements ;  elsif  (boolean expression 3)   then  sequential statements ;  else  sequential statements ;  end if  ;
Ví dụ về lệnh  If/Elsif ,[object Object],[object Object],[object Object],process (A, B, C, D, Sel) begin If   (Sel = “00”)  then Z <= A ; elsif  (Sel = “01”)  then Z <= B ; elsif   (Sel = “10”)  then Z <= C ;   elsif  (Sel = “11”)   then   Z <= D ;  end if;   end process ; Z D C B A Sel D C B A Z Late arriving signal? Sufficient for std_logic?
Câu lệnh  Case ,[object Object],[object Object],process  (…)  begin case  ( selector expression )  is when   ...  =>  sequential statements ; when   ...  =>  sequential statements ;   when  ...  =>  sequential statements ;   end case  ;  . . . end process ; process (...) begin case   (  selector expression  )  is when   ...  =>  sequential statements ;  . . .  when   others  => sequential statements ;   end case  ;  . . . end process ;
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Ví dụ về lệnh  Case   process  (A, B, C, D, Sel ) begin case   Sel  is   when   “00”  =>  Z  <= A ;   when   “01”  =>  Z  <= B ;   when   “10”  =>  Z  <= C ;   when   “11”  =>  Z  <= D ; end  case  ; . . . end process ; Is this sufficient for std_logic? Z D C B A Sel
Các điều kiện chồng chéo  ,[object Object],process (A, B, C, D, Sel) begin If   ( Sel <= 3 )  then Z <= A ; elsif   ( Sel <= 5 )  then Z <= B ; elsif  ( Sel <= 7 )  then Z <= C ;   elsif  ( Sel <= 9 )   then   Z <= D ;  end if;   end process ; D C B A Z
Giải hữu hạn các giá trị  ,[object Object],process  (…)  begin if (x =   12 to 14) then  sequential statements ;   . . .  case  ( selector expression )  is when   0 to 7    =>   sequential statements ; when   4.3 to 7.7  =>   sequential statements ;   when   “1000”  to “1010”  =>   sequential statements ;   when   “1000” | “1010”  =>   sequential statements ; . . . end process ;
Lệnh gán Signal có điều kiện  ,[object Object],[object Object],[object Object],  architecture ...  begin   process   ( A,B, C, Sel )   begin   if  (Sel = “00” )   then   Z <= A ;   elsif  (Sel = “10”)  then   Z <= B ;   elsif  (Sel = “11”)  then   Z <= C ;   else   Z <= ‘X’ ;   end  if ;   end  process ; end  architecture ; architecture ...   begin    Z <= A  when   Sel = “00”  else   B   when   Sel  =  “10”   else   C  when   Sel  =  “11”   else   ‘X’ ; end architecture ;
Lệnh gán Signal có lựa chọn ,[object Object],[object Object],[object Object],[object Object],architecture ...   begin   process   ( A,B,C, SEL )   begin   case  (SEL)   is    when   “00” =>   Z <= A ;   when   “10” =>   Z <= B ;   when  “11” => Z <= C ;   when others  => Z <= ‘X’ ;    end  case ;   end  process ; end  architecture ; architecture... with  SEL  select    Z <=  A  when   “00” ,   B   when   “10”  ,   C  when   “11”  ,   ‘X’  when others  ; end architecture ;
Outline ,[object Object],[object Object],[object Object],[object Object],[object Object]
Các câu lệnh  Loop   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],process  ( A, B_bus )   begin   for  i in 7 downto 0  loop   C_bus (i) <= A  and  B_bus (i) ;  end  loop  ;
Sử dụng các lệnh  Loop ,[object Object],[object Object],[object Object],[object Object],process  ( A, B_bus )   begin   for  i in 7 downto 0  loop   C_bus (i)  <=  A   and  B_bus (i) ;  end  loop  ; A B_bus (7) A . . . A B_bus (6) B_bus (0) C_bus (7) C_bus (6) C_bus (0)

More Related Content

What's hot

Các phương pháp thiết kế bộ điều khiển PID.docx
Các phương pháp thiết kế bộ điều khiển PID.docxCác phương pháp thiết kế bộ điều khiển PID.docx
Các phương pháp thiết kế bộ điều khiển PID.docxhunhlhongthi
 
Chương 5: Khối thu phát
Chương 5: Khối thu phátChương 5: Khối thu phát
Chương 5: Khối thu phátviendongcomputer
 
đồ áN phân loại sản phâm dùng plc s71200
đồ áN phân loại sản phâm dùng plc s71200đồ áN phân loại sản phâm dùng plc s71200
đồ áN phân loại sản phâm dùng plc s71200Lê Gia
 
Bai giang-vhdl
Bai giang-vhdlBai giang-vhdl
Bai giang-vhdlhoangclick
 
xử lý số tín hiệu -Chuong 5
xử lý số tín hiệu -Chuong 5xử lý số tín hiệu -Chuong 5
xử lý số tín hiệu -Chuong 5Ngai Hoang Van
 
Vi Điều Khiển Ứng Dụng AT89s52
Vi Điều Khiển Ứng Dụng AT89s52Vi Điều Khiển Ứng Dụng AT89s52
Vi Điều Khiển Ứng Dụng AT89s52Mr Giap
 
Vi du chi tiet giai thich lap trinh gui trong matlab
Vi du chi tiet  giai thich lap trinh gui trong matlabVi du chi tiet  giai thich lap trinh gui trong matlab
Vi du chi tiet giai thich lap trinh gui trong matlabPhạmThế Anh
 
Bài giảng kỹ thuật điều khiển tự động
Bài giảng kỹ thuật điều khiển tự độngBài giảng kỹ thuật điều khiển tự động
Bài giảng kỹ thuật điều khiển tự độngNguyễn Nam Phóng
 
Huong dan dung proteus
Huong dan dung proteusHuong dan dung proteus
Huong dan dung proteusĐức Đỗ
 
Tài liệu thiết kế mạch in altium
Tài liệu thiết kế mạch in altiumTài liệu thiết kế mạch in altium
Tài liệu thiết kế mạch in altiumNgai Hoang Van
 
[Báo cáo] Bài tập lớn Xử lý tín hiệu số: Thiết kế bộ lọc FIR
[Báo cáo] Bài tập lớn Xử lý tín hiệu số: Thiết kế bộ lọc FIR[Báo cáo] Bài tập lớn Xử lý tín hiệu số: Thiết kế bộ lọc FIR
[Báo cáo] Bài tập lớn Xử lý tín hiệu số: Thiết kế bộ lọc FIRThe Nguyen Manh
 
Chuong 5_ KỸ THUẬT ĐIỀU CHẾ SỐ.pdf
Chuong 5_ KỸ THUẬT ĐIỀU CHẾ SỐ.pdfChuong 5_ KỸ THUẬT ĐIỀU CHẾ SỐ.pdf
Chuong 5_ KỸ THUẬT ĐIỀU CHẾ SỐ.pdfCngNguynHuy8
 

What's hot (20)

Đề tài: Thiết kế hệ thống phân loại sản phẩm ứng dụng PLC, HOT
Đề tài: Thiết kế hệ thống phân loại sản phẩm ứng dụng PLC, HOTĐề tài: Thiết kế hệ thống phân loại sản phẩm ứng dụng PLC, HOT
Đề tài: Thiết kế hệ thống phân loại sản phẩm ứng dụng PLC, HOT
 
Đề tài: Hệ thống Iot điều khiển và giám sát ngôi nhà, HAY, 9đ
Đề tài: Hệ thống Iot điều khiển và giám sát ngôi nhà, HAY, 9đĐề tài: Hệ thống Iot điều khiển và giám sát ngôi nhà, HAY, 9đ
Đề tài: Hệ thống Iot điều khiển và giám sát ngôi nhà, HAY, 9đ
 
Qua trinh qua do
Qua trinh qua doQua trinh qua do
Qua trinh qua do
 
Các phương pháp thiết kế bộ điều khiển PID.docx
Các phương pháp thiết kế bộ điều khiển PID.docxCác phương pháp thiết kế bộ điều khiển PID.docx
Các phương pháp thiết kế bộ điều khiển PID.docx
 
Chương 5: Khối thu phát
Chương 5: Khối thu phátChương 5: Khối thu phát
Chương 5: Khối thu phát
 
đồ áN phân loại sản phâm dùng plc s71200
đồ áN phân loại sản phâm dùng plc s71200đồ áN phân loại sản phâm dùng plc s71200
đồ áN phân loại sản phâm dùng plc s71200
 
Xử lý tín hiệu số
Xử lý tín hiệu sốXử lý tín hiệu số
Xử lý tín hiệu số
 
Luận văn: Nghiên cứu thiết bị bay không người lái, HOT
Luận văn: Nghiên cứu thiết bị bay không người lái, HOTLuận văn: Nghiên cứu thiết bị bay không người lái, HOT
Luận văn: Nghiên cứu thiết bị bay không người lái, HOT
 
Bai giang-vhdl
Bai giang-vhdlBai giang-vhdl
Bai giang-vhdl
 
xử lý số tín hiệu -Chuong 5
xử lý số tín hiệu -Chuong 5xử lý số tín hiệu -Chuong 5
xử lý số tín hiệu -Chuong 5
 
Đề tài: Mô phỏng kênh truyền vô tuyến số bằng matlab, 9đ
Đề tài: Mô phỏng kênh truyền vô tuyến số bằng matlab, 9đ Đề tài: Mô phỏng kênh truyền vô tuyến số bằng matlab, 9đ
Đề tài: Mô phỏng kênh truyền vô tuyến số bằng matlab, 9đ
 
Vi Điều Khiển Ứng Dụng AT89s52
Vi Điều Khiển Ứng Dụng AT89s52Vi Điều Khiển Ứng Dụng AT89s52
Vi Điều Khiển Ứng Dụng AT89s52
 
Vi du chi tiet giai thich lap trinh gui trong matlab
Vi du chi tiet  giai thich lap trinh gui trong matlabVi du chi tiet  giai thich lap trinh gui trong matlab
Vi du chi tiet giai thich lap trinh gui trong matlab
 
Bài giảng kỹ thuật điều khiển tự động
Bài giảng kỹ thuật điều khiển tự độngBài giảng kỹ thuật điều khiển tự động
Bài giảng kỹ thuật điều khiển tự động
 
Huong dan dung proteus
Huong dan dung proteusHuong dan dung proteus
Huong dan dung proteus
 
Tài liệu thiết kế mạch in altium
Tài liệu thiết kế mạch in altiumTài liệu thiết kế mạch in altium
Tài liệu thiết kế mạch in altium
 
[Báo cáo] Bài tập lớn Xử lý tín hiệu số: Thiết kế bộ lọc FIR
[Báo cáo] Bài tập lớn Xử lý tín hiệu số: Thiết kế bộ lọc FIR[Báo cáo] Bài tập lớn Xử lý tín hiệu số: Thiết kế bộ lọc FIR
[Báo cáo] Bài tập lớn Xử lý tín hiệu số: Thiết kế bộ lọc FIR
 
Chuong 5_ KỸ THUẬT ĐIỀU CHẾ SỐ.pdf
Chuong 5_ KỸ THUẬT ĐIỀU CHẾ SỐ.pdfChuong 5_ KỸ THUẬT ĐIỀU CHẾ SỐ.pdf
Chuong 5_ KỸ THUẬT ĐIỀU CHẾ SỐ.pdf
 
Tài liệu chi tiết bộ điều khiển PLC Siemens S7-1500
Tài liệu chi tiết bộ điều khiển PLC Siemens S7-1500Tài liệu chi tiết bộ điều khiển PLC Siemens S7-1500
Tài liệu chi tiết bộ điều khiển PLC Siemens S7-1500
 
Đề tài: Thiết kế hệ thống nuôi cá tự động, HOT, 9đ
Đề tài: Thiết kế hệ thống nuôi cá tự động, HOT, 9đĐề tài: Thiết kế hệ thống nuôi cá tự động, HOT, 9đ
Đề tài: Thiết kế hệ thống nuôi cá tự động, HOT, 9đ
 

Similar to Vhdl Slides

De-cuong-on-tap-NNMTPC.pdf
De-cuong-on-tap-NNMTPC.pdfDe-cuong-on-tap-NNMTPC.pdf
De-cuong-on-tap-NNMTPC.pdfAnhTVit1
 
Tong quan ve_fpga__1226
Tong quan ve_fpga__1226Tong quan ve_fpga__1226
Tong quan ve_fpga__1226KowLoon1
 
Sinh vienit.net --57669587-c-dhkh-hue
Sinh vienit.net --57669587-c-dhkh-hueSinh vienit.net --57669587-c-dhkh-hue
Sinh vienit.net --57669587-c-dhkh-hueTuấn Nguyễn Văn
 
Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)
Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)
Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)Levis Nickaster
 
Reverse Engineering .NET - Advanced Patching, Playing with IL
Reverse Engineering .NET - Advanced Patching, Playing with ILReverse Engineering .NET - Advanced Patching, Playing with IL
Reverse Engineering .NET - Advanced Patching, Playing with ILLevis Nickaster
 
Bai 1 Gioi Thieu Verilog Va Quartus
Bai 1   Gioi Thieu Verilog Va QuartusBai 1   Gioi Thieu Verilog Va Quartus
Bai 1 Gioi Thieu Verilog Va Quartusngoclanhoa116
 
Những thuật ngữ thường gặp trong Reverse Engineering .NET
Những thuật ngữ thường gặp trong Reverse Engineering .NETNhững thuật ngữ thường gặp trong Reverse Engineering .NET
Những thuật ngữ thường gặp trong Reverse Engineering .NETLevis Nickaster
 
OOP_02_Java can ban.pdf
OOP_02_Java can ban.pdfOOP_02_Java can ban.pdf
OOP_02_Java can ban.pdfssuserd01a5c
 
Control builder
Control builderControl builder
Control builderquanglocbp
 
Lập trình PLC S7 1200 tiếng Việt-Chuong 4 khái niệm lập trình
Lập trình PLC S7 1200 tiếng Việt-Chuong 4 khái niệm lập trìnhLập trình PLC S7 1200 tiếng Việt-Chuong 4 khái niệm lập trình
Lập trình PLC S7 1200 tiếng Việt-Chuong 4 khái niệm lập trìnhXuân Thủy Nguyễn
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#Hihi Hung
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#LanLT2011
 
Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]
Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]
Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]leduyk11
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#LanLT2011
 
Giáo trình vb.net
Giáo trình vb.netGiáo trình vb.net
Giáo trình vb.netHung Pham
 

Similar to Vhdl Slides (20)

De-cuong-on-tap-NNMTPC.pdf
De-cuong-on-tap-NNMTPC.pdfDe-cuong-on-tap-NNMTPC.pdf
De-cuong-on-tap-NNMTPC.pdf
 
Tong quan ve_fpga__1226
Tong quan ve_fpga__1226Tong quan ve_fpga__1226
Tong quan ve_fpga__1226
 
Sinh vienit.net --57669587-c-dhkh-hue
Sinh vienit.net --57669587-c-dhkh-hueSinh vienit.net --57669587-c-dhkh-hue
Sinh vienit.net --57669587-c-dhkh-hue
 
Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)
Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)
Các công cụ cần thiết cho quá trình Reverse Engineering .NET (bản đầy đủ)
 
Reverse Engineering .NET - Advanced Patching, Playing with IL
Reverse Engineering .NET - Advanced Patching, Playing with ILReverse Engineering .NET - Advanced Patching, Playing with IL
Reverse Engineering .NET - Advanced Patching, Playing with IL
 
Bai 1 Gioi Thieu Verilog Va Quartus
Bai 1   Gioi Thieu Verilog Va QuartusBai 1   Gioi Thieu Verilog Va Quartus
Bai 1 Gioi Thieu Verilog Va Quartus
 
Asp.net 3.5 _1
Asp.net 3.5 _1Asp.net 3.5 _1
Asp.net 3.5 _1
 
Những thuật ngữ thường gặp trong Reverse Engineering .NET
Những thuật ngữ thường gặp trong Reverse Engineering .NETNhững thuật ngữ thường gặp trong Reverse Engineering .NET
Những thuật ngữ thường gặp trong Reverse Engineering .NET
 
OOP_02_Java can ban.pdf
OOP_02_Java can ban.pdfOOP_02_Java can ban.pdf
OOP_02_Java can ban.pdf
 
Phan 1 sv
Phan 1   svPhan 1   sv
Phan 1 sv
 
Linux+03
Linux+03Linux+03
Linux+03
 
Control builder
Control builderControl builder
Control builder
 
Lập trình PLC S7 1200 tiếng Việt-Chuong 4 khái niệm lập trình
Lập trình PLC S7 1200 tiếng Việt-Chuong 4 khái niệm lập trìnhLập trình PLC S7 1200 tiếng Việt-Chuong 4 khái niệm lập trình
Lập trình PLC S7 1200 tiếng Việt-Chuong 4 khái niệm lập trình
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#
 
C# cơ bản hay
C# cơ bản hayC# cơ bản hay
C# cơ bản hay
 
Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]
Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]
Lập trình c# 2008 cơ bản (nhất nghệ) [thủ thuật it 360]
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#
 
Nhat nghe c#
Nhat nghe   c#Nhat nghe   c#
Nhat nghe c#
 
Giáo trình vb.net
Giáo trình vb.netGiáo trình vb.net
Giáo trình vb.net
 

More from hoadktd

Traffic Light Control
Traffic Light ControlTraffic Light Control
Traffic Light Controlhoadktd
 
Traffic Light Control
Traffic Light ControlTraffic Light Control
Traffic Light Controlhoadktd
 
Profibus Em277
Profibus   Em277Profibus   Em277
Profibus Em277hoadktd
 
Giaotrinh Win Cc
Giaotrinh Win CcGiaotrinh Win Cc
Giaotrinh Win Cchoadktd
 
Dientuso Sld2
Dientuso Sld2Dientuso Sld2
Dientuso Sld2hoadktd
 
Dientuso Sld
Dientuso SldDientuso Sld
Dientuso Sldhoadktd
 

More from hoadktd (7)

Traffic Light Control
Traffic Light ControlTraffic Light Control
Traffic Light Control
 
Traffic Light Control
Traffic Light ControlTraffic Light Control
Traffic Light Control
 
Usb
UsbUsb
Usb
 
Profibus Em277
Profibus   Em277Profibus   Em277
Profibus Em277
 
Giaotrinh Win Cc
Giaotrinh Win CcGiaotrinh Win Cc
Giaotrinh Win Cc
 
Dientuso Sld2
Dientuso Sld2Dientuso Sld2
Dientuso Sld2
 
Dientuso Sld
Dientuso SldDientuso Sld
Dientuso Sld
 

Vhdl Slides

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. Các mức trừu tượng trong mô tả phần cứng Behavioral Logic RTL Layout Ít chi tiết hơn, thiết kế và mô phỏng nhanh hơn Chi tiết hơn, phụ thuộc công nghệ, thiết kế và mô phỏng chậm hơn DFF AND_OR2 CLB_R5C5 CLB_R5C6 F
  • 7. Sự chồng chéo trong VHDL Behavioral Logic RTL Layout Place & Route Utility FPGA Vendor Library Synthesizable Code Hardware Model Sum <= A + B after 3 ns ; Sum <= A + B ; component Xlx_add2 port ( A: in bit ; B: in bit ; Sum: out bit ); end component ;
  • 8.
  • 9.
  • 10. Cấu trúc Top - Down A[3:0] entity Add_4 B[3:0 ] C_in SUM [3:0] C_out C_out Sum A B C_in entity Full_Add A B entity Half_Add Sum Carry Leaf Cell Macro
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29. Ví dụ về Hierarchy : DFF entity DFF is port (D, Clock : in std_logic ; Reset : in std_logic ; Q : out std_logic) ; end entity DFF ; architecture RTL of DFF is begin process (Clock, Reset) begin If (Reset = ‘1’ ) then Q <= ‘0’ ; elsif (Clock’event and Clock = ‘1’) then Q <= D ; end if ; end process ; end architecture RTL ; Clock Reset D Q
  • 30. Ví dụ về Hierarchy : REG-4 entity REG_4 is port (D_in : in std_logic_vector (3 downto 0); Clk, Rst : in std_logic ; Q_out : out std_logic_vector (3 downto 0)); end REG_4; architecture Structural of REG_4 is component DFF port ( D, Clock : in std_logic ; Reset : in std_logic; Q : out std_logic ) ; end component ; begin U3 : DFF port map ( D_in(3), Clk, Rst, Q_out(3)); U2 : DFF port map ( D_in(2), Clk, Rst, Q_out(2)); U1 : DFF port map ( D_in(1), Clk, Rst, Q_out(1)); U0 : DFF port map ( D_in(0), Clk, Rst, Q_out(0)); end Structural ; Clk Rst D_in(3) D_in(2) D_in(1) D_in(0) Q_out(3) Q_out(2) Q_out(1) Q_out(0) DFF DFF DFF DFF U3 U0 U1 U2 REG_4
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58. Records Record là nhóm các phần tử đơn có kiểu ban đầu có thể khác nhau . type OPCODE is record PARITY : bit; ADDRESS : std_logic_vector ( 0 to 3 ); DATA_BYTE : std_logic_vector ( 7 downto 0 ); NUM_VALUE : integer range 0 to 6; STOP_BITS : bit_vector (1 downto 0); end record ; . . . signal TX_PACKET, RX_PACKET : OPCODE ; PARITY ADDRESS DATA_BYTE NUM_VALUE STOP_BITS . . . T X _ P A C K E T
  • 59. String String là array của các character signal Warning1: string (1 to 30) := “ Unexpected Outputs Detected” ; --declared within the architecture variable Warning2: string (1 to 30) := “ Unstable, Aborting Now” ; --declared within the process constant Warning3: string (1 to 20) := “ Entering FSM State2” ; --declared within the package or architecture process ( A_sig , B_sig, C_sig ) begin if ( A_sig and B_sig ) /= ‘1’ then report Warning1 ; elsif ( A_sig and C_sig ) = ‘1’ then report Warning2 & “ Problem Mod2 “; end if ; end process ; process ( A_sig , B_sig, C_sig ) begin assert ( A_sig and B_sig ) /= ‘1’ then report Warning1 ; severity note ; end if ; end process ; process ( A_sig , B_sig, C_sig ) begin if ( A_sig and B_sig ) /= ‘1’ then report “ Unexpected Outputs…” ; elsif ( A_sig and C_sig ) = ‘1’ then report “ I need a vacation “; end if ; end process ;
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67. Sử dụng kiểu con trong VHDL type My_State is ( Load, Jump, Add, Sub, Div, Mult , StorA, StorB) ; signal Curr_State, Next_State : My_State ; Label Base Type Constraint subtype Arith_Ops is My_State range Add to Mult ; subtype My_OHE_State is std_logic_vector ( 3 downto 0 ) ; constant Init_St0 : My_OHE_State := “0001” ; constant Load_St1 : My_OHE_State := “0010” ; constant Jump_St2 : My_OHE_State := “0100” ; constant Stor_St3 : My_OHE_State := “1000” ;
  • 68.
  • 69.
  • 70.
  • 71.
  • 72. Các toán tử Logic với biến kiểu Array Quy tắc sử dụng với biến kiểu Array 1. Các array phải có cùng kiểu (type) 2. Các array phải có cùng kích thước 3. Phép toán thực hiện với các phần tử cùng vị trí trong mỗi array, từ trái sang phải signal A_vec, B_vec, C_vec : bit_vector ( 7 downto 0 ) ; B_vec (7) A_vec (7) C_vec (7) B_vec (6) A_vec (6) C_vec (6) B_vec (5) A_vec (5) C_vec (5) B_vec (0) A_vec (0) C_vec (0) . . . C_vec <= A_vec and B_vec ;
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91. Các thành phần của Process architecture Behave of DFF is begin . . . Reg1 : process ( Clock, Reset ) begin if Reset = ‘1’ then Q <= ‘0’ ; elsif ( Clock ’event and Clock = ‘1’ ) then Q <= D ; end if ; end process ; . . . end Behave ; Optional Label Signals in sensitivity list create implied “wait” condition Signal updated with new value when process suspends All statements within the process are handled sequentially, in order Keyword Keywords “end” and “process”
  • 92. Bên trong và bên ngoài Process architecture ... process ( ) begin Out1 <= A; Out1 <= B; . . . end process ; end architecture ; architecture . . . begin Out1 <= A; Out1 <= B; . . . end architecture ; B B Chỉ có phép gán cuối cùng là có hiệu lực Out1 ? Out1 A Cần phải có một hàm resolution cho tín hiệu ra ‘Out1’
  • 93.
  • 94.
  • 95.
  • 96.
  • 97. Scheduling Events Simulation discrete time steps t t+1 t+2 t+3 D1 D+n D+2 D+1 t+4 . . . Delta cycles D1 D+2 D+1 . . . Delta cycles Transaction Queue t + 3 t + 4 t + 5 . . . . . . Int <= ‘1’ Data<= ‘0’ Out1 <= ‘1’ ; Out2 <= ‘0’ ; . . . Int <= ‘1’ after 1 ns; . . . Data <= ‘0’ after 2 ns; . . . . . . Out2<= ‘0’ Out1<= ‘1’ ns Discrete Time Delta Cycles
  • 98.
  • 99.
  • 100. Building Registers process ( Clk) begin if (Clk’ event and Clk = ‘1’) then C <= A and B ; end if; end process; Mọi phép gán tín hiệu xảy ra sau mệnh đề: if clock’event and clock = ‘1’ then... đều tạo ra một cấu trúc thanh ghi (register) C Clk B A
  • 101.
  • 102.
  • 103.
  • 104. Phép gán với Signal entity Count_1 is port (Clk, D : in bit ; Q : out integer range...); end Count_1; architecture WRONG of Count_1 is begin process (Clk) begin If Clk’ event and Clk =‘1’ then Q <= Q + 1; end if ; end process ; Q Internal_Cnt Will produce compiler error architecture RTL of Count_1 is signal Internal_Cnt : integer range ... ; begin process (Clk) begin If Clk’ event and Clk =‘1’ then Internal_Cnt <= Internal_Cnt + 1 ; end if ; end process ; Q <= Internal_Cnt ; Counter
  • 105.
  • 106. Variable trong các Process có Clock process ( Clk ) variable B, C, D : bit := ‘1’ ; begin If ( Clk ’event and Clk =‘1’) then B := A ; C := B ; D := C ; end if ; end process ; Clk A D process ( Clk ) variable B, C, D : bit := ‘1’ ; begin If ( Clk ’event and Clk =‘1’ ) then D := C ; C := B ; B := A ; end if ; end process ; Clk A C B D
  • 107. entity Count_1 is port (Clk, D : in std_logic ; Q : out std_logic_vector ...); end Count_1; architecture WRONG of Count_1 is begin process (Clk) begin If Clk’ event and Clk =‘1’ then Q <= Q + 1; end if ; end process ; Q Internal_Cnt Alternate Solution Will produce compiler error architecture RTL of Count_1 is begin process (Clk) variable Internal_Cnt : std_logic_vector .. begin If Clk’ event and Clk =‘1’ then Internal_Cnt := Internal_Cnt + 1 ; Q <= Internal_Cnt ; end if ; end process ; Counter
  • 108. Các lệnh điều khiển chương trình trong VHDL Bài 6
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.