Friday, February 26, 2016

Delays in VHDL


Compilation and Simulation of VHDL Code
Compiler (Analyzer) – checks the VHDL source code
·         Does it conforms with VHDL syntax and semantic rules
·         Are references to libraries correct
Intermediate form used by a simulator or by a synthesizer Elaboration create ports, allocate memory storage, create interconnections, establish mechanism for executing of VHDL process.



Transactions and Events

 We need to analyse a sub module only when its inputs change. The change in the value of a signal is called an “event”.
Whenever an event occurs at the input, we re-evaluate the output(s). However, the output(s) will not change immediately. Depending on the delay, we make a note of the time in future when the newly calculated values for the output(s) should appear.
Each one of these is called a “transaction”.
Note that when the time comes for the output to acquire this value, it may or may not result in an event. (For example, an AND gate may have one of its inputs at 0 and the other input may experiences an event. The recalculated output will remain the same – i.e. 0.
       Thus there is no change in its value and hence, no event.)
If it does cause an event, we must re-calculate the outputs of all those sub modules for which this output signal is an input. And so on……..

Timing “Delta”

The delay in the output acquiring its calculated value can be made zero, if desired. However, we assume that the output appears after a time d and then take the limit as d0.
This has scheduling consequences. (Events occurring at T+d are handled before those occurring at T+2d, even though both appear to be simultaneous if d0).



Types of Delay

       Consider an RC delay followed by a buffer. A pulse much wider than the RC time will be replicated at the output after some delay. A pulse much narrower than the RC time will vanish. If the same amount of delay is caused by an optical fibre, both the narrow and the wide pulse will appear at the output after being delayed. The amount of delay is the same, but their type is different and must be modeled differently.

Delay Types in VHDL

 All VHDL signal assignment statements prescribe an amount of time that must transpire before the signal assumes its new value
       This prescribed delay can be in one of three forms:
Transport -- prescribes propagation delay only

Inertial -- prescribes propagation delay and minimum input pulse width
     
Delta -- the default if no delay time is explicitly specified

We call the two types of delay as “inertial” and “transport” type.
Inertial delay is by far the most common type encountered in electronic circuits.
Transport delay can be useful in behavioural descriptions. For example, a shift register based delay line can be modelled as transport delay. Delta delay is used in VHDL for queuing up sequential events. The time between the two sequential events is called delta delay. Delta delay has no equivalent in real time. In a signal assignment the value is not assigned to the signal directly but after a delta delay at the earliest. Default signal assignment propagation delay if no delay is explicitly prescribed Delta is an infinitesimal VHDL time unit so that all signal assignments can result in signals assuming their values at a future time
 
Example:

Output <= NOT Input;
-- Output assumes new value in one delta cycle supports a model of concurrent VHDL process execution order in which processes are executed by simulator does not affect simulation output

Example.

B<=a;
Here signal b is assigned a value of signal a after one delta delay.( Reference for a simulator and not seen in real time).
     C<= a and b;
       D<=not c;
     In the above example:
      ‘a’ and ‘b’ are evaluated and assigned to ‘c’ after 1delta delay time as shown in the wave form.
Inverted value of ‘c’ assigned after 2 delta delays as shown in the wave form.
But these delays we won’t be able to observe on the simulator.

Inertial Delay

Provides for specification propagation delay and input pulse width, i.e. ‘inertia’ of output:
target <= [REJECT time_expression] INERTIAL waveform
Inertial delay is default and REJECT is optional
Output <= NOT Input AFTER 10 ns;

-- Propagation delay and minimum pulse width are 10ns
Example of gate with ‘inertia’ smaller than propagation delay
     Example:  Inverter with propagation delay of 10ns which suppresses pulses shorter than 5ns
     Output <= REJECT 5ns INERTIAL NOT Input AFTER 10ns;

     Inertial delay is the default delay in VHDL. Inertial delay the values appears at the output only when  specified   time the input is stable.
     If the input is not stable for specified limit no output change occur.
Example:
    Z<= not A after 10 ns;
       OR
     Z<= not A inertial after 10 ns;

VHDL-87 Inertial delay model

Any input signal change that does not persist for at least a propagation delay of the device is not reflected at the output.
Inertial delay (pulse rejection limit) = propagation delay
VHDL-93 Enhanced inertial delay model
VHDL-93 allows the inertial delay model to be declared explicitly as well as implicitly.

Explicitly:

Z_OUT <= inertial   (not A_IN and B_IN and C_IN) or
  (A_IN and not B_IN and C_IN) or
  (A_IN and B_IN and not C_IN) or
  (A_IN and B_IN and C_IN) after 20 ns;

Implicitly:

Z_OUT <=   (not A_IN and B_IN and C_IN) or
  (A_IN and not B_IN and C_IN) or
  (A_IN and B_IN and not C_IN) or
  (A_IN and B_IN and C_IN) after 20 ns;

VHDL-93 Enhanced inertial delay model

VHDL-93 allows inertial delay, also called a pulse rejection limit, to be different from the propagation delay.
SIG_OUT <= reject 5 ns inertial not SIG_IN after 7 ns;

Transport delay:

With a transport delay model, all input signal changes are reflected at the output, regardless of how long the signal changes persist. Transport delay model must be declared explicitly using the keyword transport.
Inertial delay model is a default delay model because it reflects better the actual behaviour of logic components.
Transport delay model is used for high-level modelling. Transport delay transports any changes on an input to the output after the specified time.

Example:

      Z<= transport not A after 10 ns; 
In the previous slide the output ‘Z’ assigned the inverted value of ‘A’ after 10 ns;
Here the any changes on an input will be transported to the output after the specified time
10 ns.
Routing delays are modelled using transport delay.

CAN (CONTRLLER AREA NETWORK) code in VHDL


Thursday, February 25, 2016

Traffic light controller using Finite state machine with VHDL

The objective of traffic light control system is  to control the flow of vehicles to avoid the traffic jam.
The basic idea behind the project is work with four lane.Further it can be extended for 8 lane system.
The four lanes are east,west,north and south direction.The traffic moving activity is controlled by RED,GREEN,YELLOW signals.



When traffic is moving from west to east then it may move from west to east or west to south where intersection is there, hence control is required. To move from west to north there is no intersection hence a control is not required for that. Similarly when traffic is moving from east to west, then it may also go to east to north, because there is an intersection, but it can go through east to south smoothly without traffic indication. Same rule follows for north to south and south to north vice versa.
Based on above assumption following will be Traffic light state.
STATE
EAST-WEST
NORTH-SOUTH
COUNTER
0
GREEN
RED
120
1
YELLOW
RED
5
2
RED
RED
60
3
RED
GREEN
120
4
RED
YELLOW
5
5
RED
RED
60



BLOCK DIAGRAM:















VHDL Programme:
1) Counter program which can count upto 120 count.


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;


entity cntr_120is
    Port ( clk : in  STD_LOGIC;
reset : in  STD_LOGIC;
           ce_120 : in  STD_LOGIC;
           co_120_out : out  STD_LOGIC_vector(6 downto 0);
           co_120 : out  STD_LOGIC);
end cntr_120;

architecture Behavioral of cntr_120 is
signal cnt120 : std_logic_vector(6 downto 0);
begin

process(clk,reset,  cnt120)
begin
if (reset = '1') then
  cnt120 <= (others => '0');
elsif(clk'event and clk = '1') then
if (ce_120 = '1') then
  
if (cnt120 = "1111000" ) then
     co_120 <= '1';
     cnt120<=(others=>'0');
else
 cnt120<= cnt120 + 1;
 co_120 <= '0';
end if;
end if;
co_120_out<=  cnt120;
end if;
end process;

end Behavioral;


2) Counter program which can count upto 60 count.



library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;


entity cntr_60 is
    Port ( clk : in  STD_LOGIC;
reset : in  STD_LOGIC;
           ce_60 : in  STD_LOGIC;
           co_60_out : out  STD_LOGIC_vector(6 downto 0);
           co_60 : out  STD_LOGIC);
end cntr_60;

architecture Behavioral of cntr_60 is
signal cnt60 : std_logic_vector(5 downto 0);
begin

process(clk,reset,  cnt60)
begin
if (reset = '1') then
   cnt60 <= (others => '0');
elsif(clk'event and clk = '1') then
if (ce_60 = '1') then
   
if (cnt60 = "111100" ) then
      co_60 <= '1';
      cnt60<=(others=>'0');
else
  cnt60<= cnt60 + 1;
  co_60 <= '0';
end if;
end if;
co_60_out<=  cnt60;
end if;
end process;

end Behavioral;


3) Counter program which can count upto 5 count.



library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;


entity cntr_5 is
    Port ( clk : in  STD_LOGIC;
reset : in  STD_LOGIC;
           ce_5 : in  STD_LOGIC;
           co_5_out : out  STD_LOGIC_vector(2 downto 0);
           co_5 : out  STD_LOGIC);
end cntr_5;

architecture Behavioral of cntr_5 is
signal cnt5 : std_logic_vector(2 downto 0);
begin

process(clk,reset,  cnt5)
begin
if (reset = '1') then
   cnt5 <= (others => '0');
elsif(clk'event and clk = '1') then
if (ce_5 = '1') then
   
if (cnt5= "101" ) then
      co_5 <= '1';
      cnt5<=(others=>'0');
else
  cnt5<= cnt5 + 1;
  co_5 <= '0';
end if;
end if;
co_60_out<=  cnt60;
end if;
end process;

end Behavioral;