SlideShare une entreprise Scribd logo
1  sur  66
Télécharger pour lire hors ligne
http://www.bized.co.uk




                                   Session 3


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
http://www.bized.co.uk




                                               3
           -ALU mini project discussion

Contents   -Concurrent Statements
                 1-Assign Statement
                 2-Process
                 3-When-else
                 4-With-select

           -Data Objects
                  1-Signals
                  2-Variables
                  3-Constants




                                                   2
                                     Copyright 2006 – Biz/ed
Session 3

                                     http://www.bized.co.uk

                              Sel        Operation
                              0000       Y<= a
ALU mini project discussion
                              0001       Y<= a+1
                              0010       Y<= a-1
                              0011       Y<= b
                              0100       Y<= b+1
                              0101       Y<= b-1
                              0110       Y<= a+b
                              0111       Y<= a+b+cin
                              1000       Y<= not a
                              1001       Y<= not b
                              1010       Y<= a AND b
                              1011       Y<= a OR b
                              1100       Y<= a NAND b
                              1101       Y<= a NOR b
                              1110       Y<= a XOR b
                              1111       Y<= a XNOR b

                                                       3
                                        Copyright 2006 – Biz/ed
Session 3

                                                http://www.bized.co.uk




                            Assignment

                             Process
              Concurrent
                            When-Else

                            With-Select
Statements
                                          Concurrent
                                IF
                                          Statements
                              CASE
               Sequential
                               FOR

                              WAIT


                                                                 4
                                                   Copyright 2006 – Biz/ed
Session 3

                                                                http://www.bized.co.uk


Concurrent Statements                        Concurrency
We can consider any system to be consisted of many blocks each has a
specific function and work together concurrently (in parallel) to form the
whole function.

As VHDL is a Hardware Description Language so the default statements in
VHDL are those who are executed in parallel.
These statements are called Concurrent statements.




                                                                                  5
                                                                    Copyright 2006 – Biz/ed
Session 3

                                                               http://www.bized.co.uk


Concurrent Statements                       Illustrating Example

 In this Example, the value of x depends on a AND b, whenever a/b changes x will
 change accordingly

 Similarly the value of y will always change whenever c/d changes

 It might happen that the value of x changes at the same time the value of y changes
  Both changes happen concurrently                    a
                                                                      x
                                                      b
 BEGIN
                                                                                       e
           x <= a AND b;
                                                      c
           y <= c AND d;                                              y
 END ;
           e <= x AND y;
                                                      d

These assignment statements are concurrent, they can be written in any order
                                                                Think as Hardware
                                                                                  6
                                                                    Copyright 2006 – Biz/ed
Session 3

                                                 http://www.bized.co.uk


Concurrent Statements 1- Assign Statements


Assignments relating outputs to inputs
Non Blocking Assignment <= is used
Assign statements can be written in any order.

         architecture rtl of logic_gate is
         begin
                   x <= a AND b;
                   y <= c OR   b;
         end rtl;




                                                                  7
                                                    Copyright 2006 – Biz/ed
Session 3

                                                                        http://www.bized.co.uk


Concurrent Statements 2- Process

Process allows writing sequential statements within concurrent environment

Process declaration

        1              2               3
<Process Name> : PROCESS     (sensitivity list)

  4         process declaration;   5
Begin
            sequential statements ;    6

  7                                        1 <Process Name> : Optional Label
End PROCESS <Process Name> ;               2 PROCESS                       : Keyword
                                           3 sensitivity list              :
                                             Signals inside it when make an event, the process trigger
                                           4 process declaration
                                           5 Begin                : Keyword
                                           6 Sequential statements
                                           7 End                           : Process Suspend

                                                                                           8
                                                                            Copyright 2006 – Biz/ed
Session 3

                                                                 http://www.bized.co.uk


Concurrent Statements                      Transactions

Process (A,B)
begin
        C <= A AND B ;
end process ;

              A         B   C
              0         1   0
              1         0   0
              1         1   1
The current value of A,B is read and the process is begun .
C <= A AND B ; causes a transaction
The value updated in C when the process suspend.
                   Transaction occurs when the process suspend

                                                                                  9
                                                                    Copyright 2006 – Biz/ed
Session 3

                                                                    http://www.bized.co.uk


Concurrent Statements                          Events

Process (A,B)
begin
        C <= A AND B ;
end process ;

                A         B    C
                0         1    0
                1         0    0
                1         1    1


If the value of D is changed as a result of this transaction, an event occurs on this
signal.
                     Event occurs on signal when the value change

                                                                                        10
                                                                        Copyright 2006 – Biz/ed
Session 3

                                                                   http://www.bized.co.uk


Concurrent Statements                           Events vs Transactions
 All signal assignment cause a transaction to be scheduled, but not every
 transaction will result in an event on the target signal.

 Note
 Only an event on a given signal will cause a process to trigger if that signal is
 included in its sensitivity list.

 1-Signal A =0
 2-Signal B changes to 0
 3-process triggers on signal B event
 4-Expression reevaluated
 5-Transaction scheduled logic 0 on C
 6-Process suspend
 7-Tranasction applied to C
 8-Value of C does not changed
 9-No event on C       only Transaction
                                                                                     11
                                                                       Copyright 2006 – Biz/ed
Session 2

                                  http://www.bized.co.uk



• Find values of A,D and B
Process (A,B)
begin
        A <= B + C ;
        D <= B + E ;
        B <= F + G ;
end process ;

                             Example
    Signal     Value
       E           3
                                13
       C           2
       F           4
       B           1
       G           5

                                                    12
                                       Copyright 2006 – Biz/ed
Session 3

                                                  http://www.bized.co.uk




Process (A,B)
begin
        A <= B + C ;
        D <= B + E ;
        B <= F + G ;
end process ;


    Signal     Value     Signal   After first    After          Event
       E           3              time this     Process
                                   Process      Suspend
       C           2               Trigger
       F           4       A          3           11
       B           1       D          4           12
       G           5       B          9            9

                                                                    13
                                                       Copyright 2006 – Biz/ed
Session 3

                                                                http://www.bized.co.uk


Concurrent Statements                       Modeling Concurrency
  A VHDL simulator is event driven
  - At any single point of discrete simulation time:
              (1) All processes execute until they suspend
              (2) Signals are updated
              (3) Events on those signals cause more processes to resume execution
  This is referred to as a delta cycle




                                                                                 14
                                                                    Copyright 2006 – Biz/ed
Session 3

                                                               http://www.bized.co.uk


Concurrent Statements                       Modeling Concurrency

The event scheduler is the heart of the HDL behavioral environment
Each transaction is scheduled at its appropriate discrete time
Discrete time advances only when no more transactions are scheduled at the current time




                                                                                15
                                                                   Copyright 2006 – Biz/ed
Session 3

                                                                http://www.bized.co.uk


Concurrent Statements                        Connecting Processes

Processes and other concurrent operations are seen to take place at the same point in
discrete simulation time




                                                                                 16
                                                                    Copyright 2006 – Biz/ed
Session 3

                     http://www.bized.co.uk


Multiple Processes




                                     17
                        Copyright 2006 – Biz/ed
Session 3

                                                             http://www.bized.co.uk


Concurrent vs Sequential
   a suspended process is activated when any of signal of sensitivity list
    changes.

   If we have multiple process and all is activated then all statement is
    each process is executed sequentially .


   all process in any architecture are executed concurrently with each
    other.




                                                                              18
                                                                 Copyright 2006 – Biz/ed
Session 3

                                                                         http://www.bized.co.uk


Concurrent Statements                           3- when-else

<target> <=       <expression> when <condition>
        else      <expression> when <condition>
        else      <expression> when <condition>
         …
        else <expression> ;



–LHS can be an internal signal or an output port
–RHS is an expression that operates on internal signal and/or input ports when the branch
condition is true
–Last “else” branch covers all missing conditions




                                                                                            19
                                                                              Copyright 2006 – Biz/ed
Session 3

                                         http://www.bized.co.uk



• 4X1 Multiplexer using when-else




                                    Example
                                       14




                                                           20
                                              Copyright 2006 – Biz/ed
Session 3

                                                  http://www.bized.co.uk



4X1 MUX                     (when-else)


Architecture behave of mux_when is
Begin
     F <=    a when sel = "00" else
             b when sel = "01" else
             c when sel = "10" else
             d when sel = "11" else
             „Z‟;
-- This is one statement with semicolon at the end only
End behave ;




                                                                  21
                                                     Copyright 2006 – Biz/ed
Session 3

                                                                          http://www.bized.co.uk



Concurrent Statements                             4- With – select - when
With <select_signal> select
        <target> <= <expression> when <value>,
                         <expression> when <value>,
                   ….
                         < expression> when others;



    –<select_signal> can be an internal signal or an input port
    –<target> can be an internal signal or an output port
    –<value> constants representing one of possible <select_signal> values.
    –“When others” is a must if not all values of <select_signal> are covered




                                                                                             22
                                                                                Copyright 2006 – Biz/ed
Session 3

                                                http://www.bized.co.uk



• 4X1 Multiplexer using with-select-when




                                           Example
                                              15




                                                                  23
                                                     Copyright 2006 – Biz/ed
Session 3

                                                 http://www.bized.co.uk



4X1 MUX                     (With – select - when)


Architecture behave of mux_with is
Begin
       With sel select
               F <=   a when "00",
                      b when "01",
                      c when "10",
                      d when "10",
                      „Z‟ when others;
       -- needed to cover missing “sel” values
End behave ;




                                                                 24
                                                    Copyright 2006 – Biz/ed
Session 3

                                               http://www.bized.co.uk



• Simulate 2X4 Decoder and 4X2 Encoder
  Using When-else and With-Select-When




                                         lab
                                          2




                                                               25
                                                  Copyright 2006 – Biz/ed
Session 3

                                                                                       http://www.bized.co.uk




With <select_signal> select
      <target> <= <expression> when <value>,
                          <expression> when <value>,
                   ….
                                 < expression> when others;
------------------------------------------------------------------------------------

<target> <=      <expression> when <condition>
        else     <expression> when <condition>
        else     <expression> when <condition>
         …
        else <expression> ;




                                                                                                       26
                                                                                          Copyright 2006 – Biz/ed
Session 3

                                           http://www.bized.co.uk



2x4 Decoder                 (when-else)


Architecture behave of decoder2x4   is
Begin
     F <=    "0001" when a = "00"   else
             "0010" when a = "01"   else
             "0100" when a = "10"   else
             “1000" when a = "11"   else
             “ZZZZ";
End behave ;




                                                           27
                                              Copyright 2006 – Biz/ed
Session 3

                                                 http://www.bized.co.uk



4X2 Encoder                       (when-else)


Architecture behave of   encoder2x4 is
Begin
     F <=    “00" when   a   =   “1000"   else
             "01" when   a   =   “0100"   else
             "10" when   a   =   “0010"   else
             "11" when   a   =   “0001"   else
             “ZZ";
End behave ;




                                                                 28
                                                    Copyright 2006 – Biz/ed
Session 3

                                            http://www.bized.co.uk



2x4 Decoder                  (With – select - when)


 Architecture behave of decoder4x2 is
 Begin
        With a select
        F <= "0001" when "00",
              "0010" when "01",
              “0100" when "10",
              “1000" when "11",
              “ZZZZ" when others;
 End behave ;




                                                            29
                                               Copyright 2006 – Biz/ed
Session 3

                                            http://www.bized.co.uk



4X2 Encoder                  (With – select - when)

 Architecture behave of encoder2x4 is
 Begin
        with A select
        F <= "00" when “1000",
              "01" when "0100",
              "10" when “0010",
              "11" when “0001",
              “ZZ" when others;
 End behave ;




                                                            30
                                               Copyright 2006 – Biz/ed
Session 3

                             http://www.bized.co.uk




Questions
                 Session-3




                                             31
                                Copyright 2006 – Biz/ed
http://www.bized.co.uk




Break
Be ready for the second part of this session




           Start
           1:00
           1:01
           1:02
           1:03
           1:04
           1:05
           1:06
           1:07
           1:08
           1:09
           1:10
           1:12
           1:13
           1:14
           1:15
           1:16
           1:17
           1:18
           1:19
           1:20
           1:21
           1:22
           1:23
           1:24
           1:25
           1:26
           1:27
           1:28
           1:29
           1:30
           1:31
           1:32
           1:33
           1:34
           1:35
           1:36
           1:37
           1:38
           1:39
           1:40
           1:41
           1:42
           1:43
           1:44
           1:45
           1:46
           1:47
           1:48
           1:49
           1:50
           1:51
           1:52
           1:53
           1:54
           1:55
           1:56
           1:57
           1:58
           1:59
           2:00
           0:01
           0:02
           0:03
           0:04
           0:05
           0:06
           0:07
           0:08
           0:09
           0:10
           0:12
           0:13
           0:14
           0:15
           0:16
           0:17
           0:18
           0:19
           0:20
           0:21
           0:22
           0:23
           0:24
           0:25
           0:26
           0:27
           0:28
           0:29
           0:30
           0:31
           0:32
           0:33
           0:34
           0:35
           0:36
           0:37
           0:38
           0:39
           0:40
           0:41
           0:42
           0:43
           0:44
           0:45
           0:46
           0:47
           0:48
           0:49
           0:50
           0:51
           0:52
           0:53
           0:54
           0:55
           0:56
           0:57
           0:58
           0:59
           1:11
           0:11                                                32
                                                  Copyright 2006 – Biz/ed
Session 3

                    http://www.bized.co.uk




            Data Objects




                                    33
                       Copyright 2006 – Biz/ed
Session 3

                                                                 http://www.bized.co.uk


Data Objects


 -Data Objects are the Value holders
 -VHDL offers different data objects:
 1-Signals           Used to model connections
                     Signals can be:
                              External Signals
                              Internal Signals
 2-Variables         Used for computations

 3-Constants         Used to store values that can’t be changed during simulation time




                                                                                  34
                                                                     Copyright 2006 – Biz/ed
Session 3

                                                                 http://www.bized.co.uk


Data Objects                       1-Signals

Signals Used to model connections, signals can be divided into two main types :

         External Signals (Ports)
                   Used as an interface for the Entity to the outside world
                   pass values in and out the circuit, between its internal units.
                   Declared in Entity
                   All PORTS of an ENTITY are signals by default

         Internal Signals
                   Used inside the Architecture to connect different logic parts
                   Declared in Architecture
                   Represents circuit interconnects (wires)




                                                                                   35
                                                                     Copyright 2006 – Biz/ed
Session 3

                                                                http://www.bized.co.uk


Data Objects                       1-Signals

External Signal declaration

         entity <entity_name> is                 Example
         port (                                            ENTITY AND_GATE IS
                <port_name> : <mode> <type>;               port (   a,b : in BIT;
                  -----                                             C   : out BIT
                <port_name> : <mode> <type>                         );
          );                                               END ENTITY AND_GATE ;
         End <entity_name> ; NAND_GATE ;

Internal Signal declaration

         architecture <arch_name> of <entity_name> is
            -- architecture declarations
         signal <sig_name> : <sig_type>;
         begin                               Example

         End <arch_name> ;                     SIGNAL control: BIT ;
                                               SIGNAL y: STD_LOGIC_VECTOR(7 DOWNTO 0);

                                                                                 36
                                                                    Copyright 2006 – Biz/ed
Session 3

                                                                    http://www.bized.co.uk


Data Objects                          1-Signals
Assignment Operator
        Assigned using “<=”
        Non-Blocking Assignment
Example
        inp_x <=“0000”;
        sig_1 <=„1‟;



Behavior
Used in Concurrent or Sequential
         Outside a process
                   its value is updated when their signal assignment is executed.
         Inside a process
                   its value is updated after the process suspends
                   only last assignment to signal listed inside the process is effective .

                                                                                     37
                                                                        Copyright 2006 – Biz/ed
Session 3

                                                      http://www.bized.co.uk




Objective
 -Be familiar with signals declaration
 -Using Signals inside and outside the process




                                                 Example
                                                    16




                                                                        38
                                                           Copyright 2006 – Biz/ed
Session 3

                                             http://www.bized.co.uk




A=1 ,B=1 ,C=1, D=2  C changes from 1 to 2
What is the values of A,B and C ?

Process (C,D)
Begin
   A<=2;                  A=
   B<=A+C;
   A<=D+1;
                          B=
   C<=B+A;                C=
End process;




                                                             39
                                                Copyright 2006 – Biz/ed
Session 3

                                             http://www.bized.co.uk




A=1 ,B=1 ,C=1, D=2  C changes from 1 to 2
What is the values of A,B and C ?

Process (C,D)
Begin
   A<=2;                  A=3
   B<=A+C;
   A<=D+1;
                          B=3
   C<=B+A;                C=2
End process;




                                                             40
                                                Copyright 2006 – Biz/ed
Session 3

                                                       http://www.bized.co.uk




Objective
 -Be familiar with signals declaration
 -Using Signals inside and outside the process




                                                 Exercise
                                                    2




                                                                         41
                                                            Copyright 2006 – Biz/ed
Session 3

                                                http://www.bized.co.uk



signal signal1: integer :=1; -- initial value
signal signal2: integer :=2; -- initial value
signal signal3: integer :=3; -- initial value
begin
process (………)
begin
                 ……………
      signal1 <= signal2;
      signal2 <= signal1 + signal3;
      signal3 <= signal2;
      RESULT <= signal1 + signal2 + signal3;
                 ……………
end process;

  Find the value of result?




                                                                42
                                                   Copyright 2006 – Biz/ed
Session 3

                                                           http://www.bized.co.uk

         -- All Signals have the uninitialized value ‘U’
         -- Force A = '1' then force A='0' then A='1'
library IEEE;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;

entity signal_lab is
  port( A: in std_logic
        );
End signal_lab;

Architecture behave of signal_lab is
Signal Z,G,F,X : STD_LOGIC;
begin
process (A)
Begin             A             1             0            1
  Z <= A;
  G <= '1';       Z             ?             ?            ?
  F <= G;
  X <= F;         G             ?             ?            ?
  G <= '0';
  Z <= G;         F             ?             ?            ?
end process ;     X             ?             ?            ?
end behave;

                                                                            43
                                                               Copyright 2006 – Biz/ed
Session 3

                                                           http://www.bized.co.uk

         -- All Signals have the uninitialized value ‘U’
         -- Force A = '1' then force A='0' then A='1'
library IEEE;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;

entity signal_lab is
  port( A: in std_logic
        );
End signal_lab;

Architecture behave of signal_lab is
Signal Z,G,F,X : STD_LOGIC;
begin
process (A)
Begin             A             1             0            1
  Z <= A;
  G <= '1';       Z             U             0            0
  F <= G;
  X <= F;         G             0             0            0
  G <= '0';
  Z <= G;         F             U             0            0
end process ;     X             U             U            0
end behave;

                                                                            44
                                                               Copyright 2006 – Biz/ed
Session 3

                                                           http://www.bized.co.uk

         -- All Signals have the uninitialized value ‘U’
         -- Force A = '1' then force A='0' then A='1'
library IEEE;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;

entity signal_lab is
  port( A: in std_logic
        );
End signal_lab;

Architecture behave of signal_lab is
Signal Z,G,F,X : STD_LOGIC;
begin
process (A)
Begin
  Z <= A;
  G <= '1';
  F <= G;
  X <= F;
end process ;
  G <= '0';
  Z <= G;
end behave;

                                                                           45
                                                              Copyright 2006 – Biz/ed
Session 3

                                                           http://www.bized.co.uk

         -- All Signals have the uninitialized value ‘U’
         -- Force A = '1' then force A='0' then A='1'
library IEEE;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;

entity signal_lab is
  port( A: in std_logic
        );
End signal_lab;

Architecture behave of signal_lab is
Signal Z,G,F,X : STD_LOGIC;
begin
process (A)
Begin                                Any statement written out side
  Z <= A;
  G <= '1';
                                         process is concurrent statement ,
  F <= G;                            It execute concurrently with process
  X <= F;
end process ;
  G <= '0';                          G and Z has two values at same time
  Z <= G;                                value of A and value of G.
end behave;

                                                                           46
                                                              Copyright 2006 – Biz/ed
Session 3

                                                            http://www.bized.co.uk



Data Objects                      2-Variables
Variables are used for computations
         Represent only local information
         Declared inside a process
         can only be used inside a PROCESS (in sequential code).

Variable declaration
         architecture behave of MPU is
         begin
         process(…)
                  variable x, y : std_logic ;
                  variable intbus : std_logic_vector(7 downto 0);
         begin
                  .
                  .              .
         end process ;
                  .
                  .
         end behave;
                                                                            47
                                                               Copyright 2006 – Biz/ed
Session 3

                                                                http://www.bized.co.uk



Data Objects                          2-Variables

Assignment Operator
       Assigned using “:=”
       Blocking Assignment

Example
           var_x :=“0000”;
           var_1 :=„1‟;

Behavior
           its value can not be passed out directly
           its update is immediate, so the new value is used in the next line of code.
           As long as signal and variable have same type they can be assign to each
other .




                                                                                 48
                                                                    Copyright 2006 – Biz/ed
Session 3

                                               http://www.bized.co.uk




Objective
 -Be familiar with variable declaration
 -Using variable inside the process




                                          Example
                                             17




                                                                 49
                                                    Copyright 2006 – Biz/ed
Session 3

                                               http://www.bized.co.uk




process(……)
      variable variable1: integer :=1;
      variable variable2: integer :=2;
      variable variable3: integer :=3;
begin
                 ………
      variable1 := variable2;
      variable2 := variable1 + variable3;
      variable3 := variable2;
      RESULT <= variable1 + variable2 + variable3;
                 ………..
end process;




                                                                  50
                                                     Copyright 2006 – Biz/ed
Session 3

                                                       http://www.bized.co.uk




Objective
 -Be familiar with variables declaration
 -Using Signals inside and outside the process




                                                 Exercise
                                                    3




                                                                         51
                                                            Copyright 2006 – Biz/ed
Session 3

                                                   http://www.bized.co.uk


         -- Force A = "001"
library IEEE;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_unsigned.all;

entity signal_lab is
  port( A : in std_logic_vector(2 downto 0)
        );
End signal_lab;

Architecture behave of signal_lab is
begin
process (A)
Variable Z,G,F,X : std_logic_vector(2 downto 0);
Begin
  G := A + A;
  F := G + A;
  X := G + F;
  Z := X + F;
end process ;
end behave;



                                                                   52
                                                      Copyright 2006 – Biz/ed
Session 3

                                                    http://www.bized.co.uk


Data Objects                     Initialization

made when we declare the variable or the function
using   :=
   signal sigbus : std_logic_vector(7 downto 0) := "01011110";
   variable z : std_logic := '1';
   variable varbus : std_logic_vector(3 downto 0) := "0001";




                                                                    53
                                                       Copyright 2006 – Biz/ed
Session 3

                                                                       http://www.bized.co.uk

                                        2-Initializations

Signals inside your design should have initial values
Synthesis tools ignore initial values specified for a variable or a signal in its declaration.
The best way for initialization is to initialize the signals when the reset is active.

          If reset = „1‟ then
                 sig_1 <= „0‟ ;
                 sig_2 <= “00000”;
                 sig_3 <= “10101010”;
                 out_1 <= “00”
          elsif ris……
                 ………




                                                                                        54
                                                                           Copyright 2006 – Biz/ed
Session 3

                                                                         http://www.bized.co.uk



Data Objects                                 Signal vs Variable
                             Signals                               Variables
Declaration                  Internal :                            Inside Process Declaration
                             Inside Architecture Declaration
                             External :
                              Inside Port entity
Assignment                   Non-Blocking Assign <=                Blocking Assign :=
Initialization               :=                                    :=
Update                       After the process suspend             Immediately
Scope                        Seen by the whole code                Local onside process

                             Can be used in either type of code,   Can only be used inside
                             concurrent or sequential.             a sequential code
UTILITY                      Represents circuit interconnects      Represents local information
                             (wires)



                                                                                             55
                                                                               Copyright 2006 – Biz/ed
Session 3

                                                            http://www.bized.co.uk



Data Objects                         Object Scope
-Ports are signals and declared at the top level (entity)
-Within the architecture, local signals are declared
-Within the process, local variables can be declared




                                                                            56
                                                               Copyright 2006 – Biz/ed
Session 3

                                                             http://www.bized.co.uk


Data Objects                      3-Constants

A constant can have a single value of a given type and cannot be changed during
the simulation.

Constant Declaration
         constant <con_name> : <data_type>; := <con_value>;

Constants can be declared at the start of an architecture and can then be used
anywhere within the architecture.

Constants declared within a process can only be used inside that specific a
Process.

Example
          CONSTANT set_bit : BIT := '1';




                                                                              57
                                                                 Copyright 2006 – Biz/ed
Session 3

                           http://www.bized.co.uk




Objective
 -General Example




                      Example
                         18




                                             58
                                Copyright 2006 – Biz/ed
Session 3

                                              http://www.bized.co.uk

Calculate the values of var1, sig1& Q


process (a,b)
  variable var1: integer;
begin
   var1 := a + b;
   sig1 <= var1;
   Q <= sig1;
end process;

      Var1     sig1          Q          Exercise
A=1     3        4           6
B=2
                                           4
A=2         During process

B=3         Process suspend

A=5         During process
B=2         Process suspend




                                                                59
                                                   Copyright 2006 – Biz/ed
Session 3

                                                      http://www.bized.co.uk

Calculate the values of var1, sig1& Q



          Var1    sig1      Q
    A=1     3         4      6
    B=2
    A=2     5         4      6       During process

    B=3     5         5      4      Process suspend

    A=5     7         5      4       During process
    B=2     7         7      5      Process suspend

                      process (a,b)
                        variable var1: integer;
                      begin
                         var1 := a + b;
                         sig1 <= var1;
                         Q <= sig1;
                      end process;
                                                                      60
                                                         Copyright 2006 – Biz/ed
Session 3

                                                          http://www.bized.co.uk




• Do one of the Previous Exercises on ModelSim
  to sense the difference between signals and variables




                                                    lab
                                                     4




                                                                          61
                                                             Copyright 2006 – Biz/ed
Session 3

                                            http://www.bized.co.uk




Assignment
                                Session-3



Study the three sessions well




                                                            62
                                               Copyright 2006 – Biz/ed
Session 3

                                         http://www.bized.co.uk


Download Session 3 material



        Session 3.pdf




Ask for the material through mail
          start.courses@gmail.com

Facebook group
       start.group@groups.facebook.com



                                                         63
                                            Copyright 2006 – Biz/ed
Session 3

                             http://www.bized.co.uk




Questions
                 Session-3




                                             64
                                Copyright 2006 – Biz/ed
Session 3

                                                                                                      http://www.bized.co.uk

Take Your Notes
              Print the slides and take your notes here

---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
                                                                                                                              65
                                                                                                           Copyright 2006 – Biz/ed
Session 3

                       http://www.bized.co.uk




See You Next Session




                                       66
                          Copyright 2006 – Biz/ed

Contenu connexe

Plus de Mahmoud Abdellatif (12)

Evaluation test
Evaluation testEvaluation test
Evaluation test
 
Session nine
Session nineSession nine
Session nine
 
Session eight
Session eightSession eight
Session eight
 
Session seven
Session sevenSession seven
Session seven
 
Session six
Session sixSession six
Session six
 
Session five
Session fiveSession five
Session five
 
Session four
Session fourSession four
Session four
 
Xilinx ise tutorial-a
Xilinx ise tutorial-aXilinx ise tutorial-a
Xilinx ise tutorial-a
 
Session two
Session twoSession two
Session two
 
Session one
Session oneSession one
Session one
 
Intrduction To The Course
Intrduction To The  CourseIntrduction To The  Course
Intrduction To The Course
 
Intrduction to the course
Intrduction to the courseIntrduction to the course
Intrduction to the course
 

Dernier

[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 

Dernier (20)

[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 

Session three

  • 1. http://www.bized.co.uk Session 3 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
  • 2. http://www.bized.co.uk 3 -ALU mini project discussion Contents -Concurrent Statements 1-Assign Statement 2-Process 3-When-else 4-With-select -Data Objects 1-Signals 2-Variables 3-Constants 2 Copyright 2006 – Biz/ed
  • 3. Session 3 http://www.bized.co.uk Sel Operation 0000 Y<= a ALU mini project discussion 0001 Y<= a+1 0010 Y<= a-1 0011 Y<= b 0100 Y<= b+1 0101 Y<= b-1 0110 Y<= a+b 0111 Y<= a+b+cin 1000 Y<= not a 1001 Y<= not b 1010 Y<= a AND b 1011 Y<= a OR b 1100 Y<= a NAND b 1101 Y<= a NOR b 1110 Y<= a XOR b 1111 Y<= a XNOR b 3 Copyright 2006 – Biz/ed
  • 4. Session 3 http://www.bized.co.uk Assignment Process Concurrent When-Else With-Select Statements Concurrent IF Statements CASE Sequential FOR WAIT 4 Copyright 2006 – Biz/ed
  • 5. Session 3 http://www.bized.co.uk Concurrent Statements Concurrency We can consider any system to be consisted of many blocks each has a specific function and work together concurrently (in parallel) to form the whole function. As VHDL is a Hardware Description Language so the default statements in VHDL are those who are executed in parallel. These statements are called Concurrent statements. 5 Copyright 2006 – Biz/ed
  • 6. Session 3 http://www.bized.co.uk Concurrent Statements Illustrating Example In this Example, the value of x depends on a AND b, whenever a/b changes x will change accordingly Similarly the value of y will always change whenever c/d changes It might happen that the value of x changes at the same time the value of y changes  Both changes happen concurrently a x b BEGIN e x <= a AND b; c y <= c AND d; y END ; e <= x AND y; d These assignment statements are concurrent, they can be written in any order Think as Hardware 6 Copyright 2006 – Biz/ed
  • 7. Session 3 http://www.bized.co.uk Concurrent Statements 1- Assign Statements Assignments relating outputs to inputs Non Blocking Assignment <= is used Assign statements can be written in any order. architecture rtl of logic_gate is begin x <= a AND b; y <= c OR b; end rtl; 7 Copyright 2006 – Biz/ed
  • 8. Session 3 http://www.bized.co.uk Concurrent Statements 2- Process Process allows writing sequential statements within concurrent environment Process declaration 1 2 3 <Process Name> : PROCESS (sensitivity list) 4 process declaration; 5 Begin sequential statements ; 6 7 1 <Process Name> : Optional Label End PROCESS <Process Name> ; 2 PROCESS : Keyword 3 sensitivity list : Signals inside it when make an event, the process trigger 4 process declaration 5 Begin : Keyword 6 Sequential statements 7 End : Process Suspend 8 Copyright 2006 – Biz/ed
  • 9. Session 3 http://www.bized.co.uk Concurrent Statements Transactions Process (A,B) begin C <= A AND B ; end process ; A B C 0 1 0 1 0 0 1 1 1 The current value of A,B is read and the process is begun . C <= A AND B ; causes a transaction The value updated in C when the process suspend. Transaction occurs when the process suspend 9 Copyright 2006 – Biz/ed
  • 10. Session 3 http://www.bized.co.uk Concurrent Statements Events Process (A,B) begin C <= A AND B ; end process ; A B C 0 1 0 1 0 0 1 1 1 If the value of D is changed as a result of this transaction, an event occurs on this signal. Event occurs on signal when the value change 10 Copyright 2006 – Biz/ed
  • 11. Session 3 http://www.bized.co.uk Concurrent Statements Events vs Transactions All signal assignment cause a transaction to be scheduled, but not every transaction will result in an event on the target signal. Note Only an event on a given signal will cause a process to trigger if that signal is included in its sensitivity list. 1-Signal A =0 2-Signal B changes to 0 3-process triggers on signal B event 4-Expression reevaluated 5-Transaction scheduled logic 0 on C 6-Process suspend 7-Tranasction applied to C 8-Value of C does not changed 9-No event on C only Transaction 11 Copyright 2006 – Biz/ed
  • 12. Session 2 http://www.bized.co.uk • Find values of A,D and B Process (A,B) begin A <= B + C ; D <= B + E ; B <= F + G ; end process ; Example Signal Value E 3 13 C 2 F 4 B 1 G 5 12 Copyright 2006 – Biz/ed
  • 13. Session 3 http://www.bized.co.uk Process (A,B) begin A <= B + C ; D <= B + E ; B <= F + G ; end process ; Signal Value Signal After first After Event E 3 time this Process Process Suspend C 2 Trigger F 4 A 3 11 B 1 D 4 12 G 5 B 9 9 13 Copyright 2006 – Biz/ed
  • 14. Session 3 http://www.bized.co.uk Concurrent Statements Modeling Concurrency A VHDL simulator is event driven - At any single point of discrete simulation time: (1) All processes execute until they suspend (2) Signals are updated (3) Events on those signals cause more processes to resume execution This is referred to as a delta cycle 14 Copyright 2006 – Biz/ed
  • 15. Session 3 http://www.bized.co.uk Concurrent Statements Modeling Concurrency The event scheduler is the heart of the HDL behavioral environment Each transaction is scheduled at its appropriate discrete time Discrete time advances only when no more transactions are scheduled at the current time 15 Copyright 2006 – Biz/ed
  • 16. Session 3 http://www.bized.co.uk Concurrent Statements Connecting Processes Processes and other concurrent operations are seen to take place at the same point in discrete simulation time 16 Copyright 2006 – Biz/ed
  • 17. Session 3 http://www.bized.co.uk Multiple Processes 17 Copyright 2006 – Biz/ed
  • 18. Session 3 http://www.bized.co.uk Concurrent vs Sequential  a suspended process is activated when any of signal of sensitivity list changes.  If we have multiple process and all is activated then all statement is each process is executed sequentially .  all process in any architecture are executed concurrently with each other. 18 Copyright 2006 – Biz/ed
  • 19. Session 3 http://www.bized.co.uk Concurrent Statements 3- when-else <target> <= <expression> when <condition> else <expression> when <condition> else <expression> when <condition> … else <expression> ; –LHS can be an internal signal or an output port –RHS is an expression that operates on internal signal and/or input ports when the branch condition is true –Last “else” branch covers all missing conditions 19 Copyright 2006 – Biz/ed
  • 20. Session 3 http://www.bized.co.uk • 4X1 Multiplexer using when-else Example 14 20 Copyright 2006 – Biz/ed
  • 21. Session 3 http://www.bized.co.uk 4X1 MUX (when-else) Architecture behave of mux_when is Begin F <= a when sel = "00" else b when sel = "01" else c when sel = "10" else d when sel = "11" else „Z‟; -- This is one statement with semicolon at the end only End behave ; 21 Copyright 2006 – Biz/ed
  • 22. Session 3 http://www.bized.co.uk Concurrent Statements 4- With – select - when With <select_signal> select <target> <= <expression> when <value>, <expression> when <value>, …. < expression> when others; –<select_signal> can be an internal signal or an input port –<target> can be an internal signal or an output port –<value> constants representing one of possible <select_signal> values. –“When others” is a must if not all values of <select_signal> are covered 22 Copyright 2006 – Biz/ed
  • 23. Session 3 http://www.bized.co.uk • 4X1 Multiplexer using with-select-when Example 15 23 Copyright 2006 – Biz/ed
  • 24. Session 3 http://www.bized.co.uk 4X1 MUX (With – select - when) Architecture behave of mux_with is Begin With sel select F <= a when "00", b when "01", c when "10", d when "10", „Z‟ when others; -- needed to cover missing “sel” values End behave ; 24 Copyright 2006 – Biz/ed
  • 25. Session 3 http://www.bized.co.uk • Simulate 2X4 Decoder and 4X2 Encoder Using When-else and With-Select-When lab 2 25 Copyright 2006 – Biz/ed
  • 26. Session 3 http://www.bized.co.uk With <select_signal> select <target> <= <expression> when <value>, <expression> when <value>, …. < expression> when others; ------------------------------------------------------------------------------------ <target> <= <expression> when <condition> else <expression> when <condition> else <expression> when <condition> … else <expression> ; 26 Copyright 2006 – Biz/ed
  • 27. Session 3 http://www.bized.co.uk 2x4 Decoder (when-else) Architecture behave of decoder2x4 is Begin F <= "0001" when a = "00" else "0010" when a = "01" else "0100" when a = "10" else “1000" when a = "11" else “ZZZZ"; End behave ; 27 Copyright 2006 – Biz/ed
  • 28. Session 3 http://www.bized.co.uk 4X2 Encoder (when-else) Architecture behave of encoder2x4 is Begin F <= “00" when a = “1000" else "01" when a = “0100" else "10" when a = “0010" else "11" when a = “0001" else “ZZ"; End behave ; 28 Copyright 2006 – Biz/ed
  • 29. Session 3 http://www.bized.co.uk 2x4 Decoder (With – select - when) Architecture behave of decoder4x2 is Begin With a select F <= "0001" when "00", "0010" when "01", “0100" when "10", “1000" when "11", “ZZZZ" when others; End behave ; 29 Copyright 2006 – Biz/ed
  • 30. Session 3 http://www.bized.co.uk 4X2 Encoder (With – select - when) Architecture behave of encoder2x4 is Begin with A select F <= "00" when “1000", "01" when "0100", "10" when “0010", "11" when “0001", “ZZ" when others; End behave ; 30 Copyright 2006 – Biz/ed
  • 31. Session 3 http://www.bized.co.uk Questions Session-3 31 Copyright 2006 – Biz/ed
  • 32. http://www.bized.co.uk Break Be ready for the second part of this session Start 1:00 1:01 1:02 1:03 1:04 1:05 1:06 1:07 1:08 1:09 1:10 1:12 1:13 1:14 1:15 1:16 1:17 1:18 1:19 1:20 1:21 1:22 1:23 1:24 1:25 1:26 1:27 1:28 1:29 1:30 1:31 1:32 1:33 1:34 1:35 1:36 1:37 1:38 1:39 1:40 1:41 1:42 1:43 1:44 1:45 1:46 1:47 1:48 1:49 1:50 1:51 1:52 1:53 1:54 1:55 1:56 1:57 1:58 1:59 2:00 0:01 0:02 0:03 0:04 0:05 0:06 0:07 0:08 0:09 0:10 0:12 0:13 0:14 0:15 0:16 0:17 0:18 0:19 0:20 0:21 0:22 0:23 0:24 0:25 0:26 0:27 0:28 0:29 0:30 0:31 0:32 0:33 0:34 0:35 0:36 0:37 0:38 0:39 0:40 0:41 0:42 0:43 0:44 0:45 0:46 0:47 0:48 0:49 0:50 0:51 0:52 0:53 0:54 0:55 0:56 0:57 0:58 0:59 1:11 0:11 32 Copyright 2006 – Biz/ed
  • 33. Session 3 http://www.bized.co.uk Data Objects 33 Copyright 2006 – Biz/ed
  • 34. Session 3 http://www.bized.co.uk Data Objects -Data Objects are the Value holders -VHDL offers different data objects: 1-Signals Used to model connections Signals can be: External Signals Internal Signals 2-Variables Used for computations 3-Constants Used to store values that can’t be changed during simulation time 34 Copyright 2006 – Biz/ed
  • 35. Session 3 http://www.bized.co.uk Data Objects 1-Signals Signals Used to model connections, signals can be divided into two main types : External Signals (Ports) Used as an interface for the Entity to the outside world pass values in and out the circuit, between its internal units. Declared in Entity All PORTS of an ENTITY are signals by default Internal Signals Used inside the Architecture to connect different logic parts Declared in Architecture Represents circuit interconnects (wires) 35 Copyright 2006 – Biz/ed
  • 36. Session 3 http://www.bized.co.uk Data Objects 1-Signals External Signal declaration entity <entity_name> is Example port ( ENTITY AND_GATE IS <port_name> : <mode> <type>; port ( a,b : in BIT; ----- C : out BIT <port_name> : <mode> <type> ); ); END ENTITY AND_GATE ; End <entity_name> ; NAND_GATE ; Internal Signal declaration architecture <arch_name> of <entity_name> is -- architecture declarations signal <sig_name> : <sig_type>; begin Example End <arch_name> ; SIGNAL control: BIT ; SIGNAL y: STD_LOGIC_VECTOR(7 DOWNTO 0); 36 Copyright 2006 – Biz/ed
  • 37. Session 3 http://www.bized.co.uk Data Objects 1-Signals Assignment Operator Assigned using “<=” Non-Blocking Assignment Example inp_x <=“0000”; sig_1 <=„1‟; Behavior Used in Concurrent or Sequential Outside a process its value is updated when their signal assignment is executed. Inside a process its value is updated after the process suspends only last assignment to signal listed inside the process is effective . 37 Copyright 2006 – Biz/ed
  • 38. Session 3 http://www.bized.co.uk Objective -Be familiar with signals declaration -Using Signals inside and outside the process Example 16 38 Copyright 2006 – Biz/ed
  • 39. Session 3 http://www.bized.co.uk A=1 ,B=1 ,C=1, D=2  C changes from 1 to 2 What is the values of A,B and C ? Process (C,D) Begin A<=2; A= B<=A+C; A<=D+1; B= C<=B+A; C= End process; 39 Copyright 2006 – Biz/ed
  • 40. Session 3 http://www.bized.co.uk A=1 ,B=1 ,C=1, D=2  C changes from 1 to 2 What is the values of A,B and C ? Process (C,D) Begin A<=2; A=3 B<=A+C; A<=D+1; B=3 C<=B+A; C=2 End process; 40 Copyright 2006 – Biz/ed
  • 41. Session 3 http://www.bized.co.uk Objective -Be familiar with signals declaration -Using Signals inside and outside the process Exercise 2 41 Copyright 2006 – Biz/ed
  • 42. Session 3 http://www.bized.co.uk signal signal1: integer :=1; -- initial value signal signal2: integer :=2; -- initial value signal signal3: integer :=3; -- initial value begin process (………) begin …………… signal1 <= signal2; signal2 <= signal1 + signal3; signal3 <= signal2; RESULT <= signal1 + signal2 + signal3; …………… end process; Find the value of result? 42 Copyright 2006 – Biz/ed
  • 43. Session 3 http://www.bized.co.uk -- All Signals have the uninitialized value ‘U’ -- Force A = '1' then force A='0' then A='1' library IEEE; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; entity signal_lab is port( A: in std_logic ); End signal_lab; Architecture behave of signal_lab is Signal Z,G,F,X : STD_LOGIC; begin process (A) Begin A 1 0 1 Z <= A; G <= '1'; Z ? ? ? F <= G; X <= F; G ? ? ? G <= '0'; Z <= G; F ? ? ? end process ; X ? ? ? end behave; 43 Copyright 2006 – Biz/ed
  • 44. Session 3 http://www.bized.co.uk -- All Signals have the uninitialized value ‘U’ -- Force A = '1' then force A='0' then A='1' library IEEE; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; entity signal_lab is port( A: in std_logic ); End signal_lab; Architecture behave of signal_lab is Signal Z,G,F,X : STD_LOGIC; begin process (A) Begin A 1 0 1 Z <= A; G <= '1'; Z U 0 0 F <= G; X <= F; G 0 0 0 G <= '0'; Z <= G; F U 0 0 end process ; X U U 0 end behave; 44 Copyright 2006 – Biz/ed
  • 45. Session 3 http://www.bized.co.uk -- All Signals have the uninitialized value ‘U’ -- Force A = '1' then force A='0' then A='1' library IEEE; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; entity signal_lab is port( A: in std_logic ); End signal_lab; Architecture behave of signal_lab is Signal Z,G,F,X : STD_LOGIC; begin process (A) Begin Z <= A; G <= '1'; F <= G; X <= F; end process ; G <= '0'; Z <= G; end behave; 45 Copyright 2006 – Biz/ed
  • 46. Session 3 http://www.bized.co.uk -- All Signals have the uninitialized value ‘U’ -- Force A = '1' then force A='0' then A='1' library IEEE; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; entity signal_lab is port( A: in std_logic ); End signal_lab; Architecture behave of signal_lab is Signal Z,G,F,X : STD_LOGIC; begin process (A) Begin Any statement written out side Z <= A; G <= '1'; process is concurrent statement , F <= G; It execute concurrently with process X <= F; end process ; G <= '0'; G and Z has two values at same time Z <= G; value of A and value of G. end behave; 46 Copyright 2006 – Biz/ed
  • 47. Session 3 http://www.bized.co.uk Data Objects 2-Variables Variables are used for computations Represent only local information Declared inside a process can only be used inside a PROCESS (in sequential code). Variable declaration architecture behave of MPU is begin process(…) variable x, y : std_logic ; variable intbus : std_logic_vector(7 downto 0); begin . . . end process ; . . end behave; 47 Copyright 2006 – Biz/ed
  • 48. Session 3 http://www.bized.co.uk Data Objects 2-Variables Assignment Operator Assigned using “:=” Blocking Assignment Example var_x :=“0000”; var_1 :=„1‟; Behavior its value can not be passed out directly its update is immediate, so the new value is used in the next line of code. As long as signal and variable have same type they can be assign to each other . 48 Copyright 2006 – Biz/ed
  • 49. Session 3 http://www.bized.co.uk Objective -Be familiar with variable declaration -Using variable inside the process Example 17 49 Copyright 2006 – Biz/ed
  • 50. Session 3 http://www.bized.co.uk process(……) variable variable1: integer :=1; variable variable2: integer :=2; variable variable3: integer :=3; begin ……… variable1 := variable2; variable2 := variable1 + variable3; variable3 := variable2; RESULT <= variable1 + variable2 + variable3; ……….. end process; 50 Copyright 2006 – Biz/ed
  • 51. Session 3 http://www.bized.co.uk Objective -Be familiar with variables declaration -Using Signals inside and outside the process Exercise 3 51 Copyright 2006 – Biz/ed
  • 52. Session 3 http://www.bized.co.uk -- Force A = "001" library IEEE; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; entity signal_lab is port( A : in std_logic_vector(2 downto 0) ); End signal_lab; Architecture behave of signal_lab is begin process (A) Variable Z,G,F,X : std_logic_vector(2 downto 0); Begin G := A + A; F := G + A; X := G + F; Z := X + F; end process ; end behave; 52 Copyright 2006 – Biz/ed
  • 53. Session 3 http://www.bized.co.uk Data Objects Initialization made when we declare the variable or the function using := signal sigbus : std_logic_vector(7 downto 0) := "01011110"; variable z : std_logic := '1'; variable varbus : std_logic_vector(3 downto 0) := "0001"; 53 Copyright 2006 – Biz/ed
  • 54. Session 3 http://www.bized.co.uk 2-Initializations Signals inside your design should have initial values Synthesis tools ignore initial values specified for a variable or a signal in its declaration. The best way for initialization is to initialize the signals when the reset is active. If reset = „1‟ then sig_1 <= „0‟ ; sig_2 <= “00000”; sig_3 <= “10101010”; out_1 <= “00” elsif ris…… ……… 54 Copyright 2006 – Biz/ed
  • 55. Session 3 http://www.bized.co.uk Data Objects Signal vs Variable Signals Variables Declaration Internal : Inside Process Declaration Inside Architecture Declaration External : Inside Port entity Assignment Non-Blocking Assign <= Blocking Assign := Initialization := := Update After the process suspend Immediately Scope Seen by the whole code Local onside process Can be used in either type of code, Can only be used inside concurrent or sequential. a sequential code UTILITY Represents circuit interconnects Represents local information (wires) 55 Copyright 2006 – Biz/ed
  • 56. Session 3 http://www.bized.co.uk Data Objects Object Scope -Ports are signals and declared at the top level (entity) -Within the architecture, local signals are declared -Within the process, local variables can be declared 56 Copyright 2006 – Biz/ed
  • 57. Session 3 http://www.bized.co.uk Data Objects 3-Constants A constant can have a single value of a given type and cannot be changed during the simulation. Constant Declaration constant <con_name> : <data_type>; := <con_value>; Constants can be declared at the start of an architecture and can then be used anywhere within the architecture. Constants declared within a process can only be used inside that specific a Process. Example CONSTANT set_bit : BIT := '1'; 57 Copyright 2006 – Biz/ed
  • 58. Session 3 http://www.bized.co.uk Objective -General Example Example 18 58 Copyright 2006 – Biz/ed
  • 59. Session 3 http://www.bized.co.uk Calculate the values of var1, sig1& Q process (a,b) variable var1: integer; begin var1 := a + b; sig1 <= var1; Q <= sig1; end process; Var1 sig1 Q Exercise A=1 3 4 6 B=2 4 A=2 During process B=3 Process suspend A=5 During process B=2 Process suspend 59 Copyright 2006 – Biz/ed
  • 60. Session 3 http://www.bized.co.uk Calculate the values of var1, sig1& Q Var1 sig1 Q A=1 3 4 6 B=2 A=2 5 4 6 During process B=3 5 5 4 Process suspend A=5 7 5 4 During process B=2 7 7 5 Process suspend process (a,b) variable var1: integer; begin var1 := a + b; sig1 <= var1; Q <= sig1; end process; 60 Copyright 2006 – Biz/ed
  • 61. Session 3 http://www.bized.co.uk • Do one of the Previous Exercises on ModelSim to sense the difference between signals and variables lab 4 61 Copyright 2006 – Biz/ed
  • 62. Session 3 http://www.bized.co.uk Assignment Session-3 Study the three sessions well 62 Copyright 2006 – Biz/ed
  • 63. Session 3 http://www.bized.co.uk Download Session 3 material Session 3.pdf Ask for the material through mail start.courses@gmail.com Facebook group start.group@groups.facebook.com 63 Copyright 2006 – Biz/ed
  • 64. Session 3 http://www.bized.co.uk Questions Session-3 64 Copyright 2006 – Biz/ed
  • 65. Session 3 http://www.bized.co.uk Take Your Notes Print the slides and take your notes here --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------- 65 Copyright 2006 – Biz/ed
  • 66. Session 3 http://www.bized.co.uk See You Next Session 66 Copyright 2006 – Biz/ed