Professional Documents
Culture Documents
EMBEDDED SYSTEMS
Laboratory Assignment 1
Submitted by submitted to
Aditi Gupta Dr. Shubhajit Roy Chowdhary
DD23015 SCEE
M.Tech(R) + PhD
1. Consider a 2x2 switch. It has two input data ports, x(0) and x(1), and a 2 bit
control signal ctrl. The input data are routed to output ports y(0) and y(1) according
to the ctrl signal. The function table is specified as follows:
Input Output Function
ctrl y1 y0
00 x1 x0 pass
01 x0 x1 cross
10 x0 x0 Broadcast x0
11 x1 x1 Broadcast x1
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity switch2x2 is
Port ( x0 : in STD_LOGIC;
x1 : in STD_LOGIC;
y0 : out STD_LOGIC;
y1 : out STD_LOGIC);
end switch2x2;
Code:-
x0 = 0 and x1 = 1(given input constants)
Simulation:-
2. Consider an arithmetic circuit that can perform four operations: a+b, a-b, a+1 and
a-1, where a and b are 16 bit unsigned numbers and the desired operation is
specified by a 2 bit control signal ctrl. (a) Design the circuit using two adders, one
incrementer and one decrementer. Derive the VHDL code. (b) Design the circuit
using only one adder. Derive the VHDL code. In both the cases, start with the
data-flow model of a half adder circuit. Then use the half adder as components in
your hierarchical structural design.
Solution:-
(A)
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity addsub is
port (
a,b: in std_logic_vector(15 downto 0);
r: out std_logic_vector(15 downto 0);
ctrl: IN std_logic_vector(1 downto 0));
end addsub;
begin
process(ctrl)
begin
temp0 <= unsigned(a);
temp1 <= unsigned(b);
if(ctrl="00")then
sum <= temp0 + temp1 ;
elsif (ctrl = "01")then
sum <= temp0 - temp1 ;
elsif (ctrl = "10")then
sum <= temp0 + 1 ;
elsif (ctrl = "11")then
sum <= temp0 - 1 ;
end if ;
end process;
r <= std_logic_vector(sum);
end arch;
Code:-
a= 1000010001010001; b= 0000100000000011
When ctrl =00 then a+b = 1000110001010100 ; when ctrl = 01 then a-b =
0111110001001110
When ctrl =10 then a+1 = 1000010001010010; when ctrl =11 then a-1 =
100010001010000
Simulation:-
(B)
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
entity arithmetic_b is
Port (
a,b : in STD_LOGIC_VECTOR(15 DOWNTO 0);
ctrl : in std_logic_vector(1 downto 0);
r : out STD_LOGIC_VECTOR(15 DOWNTO 0));
end arithmetic_b;
Simulation:-
3. In an analog amplifier, the output voltage becomes saturated (i.e. reaching the
most positive voltage, +Vcc or the most negative voltage, -Vcc), when the output
exceeds the maximal range. In some digital signal processing applications, we wish
to design an 8 bit signed saturation adder that mimics the behavior of an analog
amplifier; i.e. if the addition result overflows, the result becomes the most positive
or the most negative numbers. Draw the top level diagram and derive the VHDL
code accordingly.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity sum_amp is
port ( a, b: in signed(7 downto 0);
sum: out signed(7 downto 0));
end sum_amp;
else
sum <=result(7 downto 0);
end if;
end process;
end behv;
Simulation :-
a = 125, b = 25, sum = 127(positive saturation) as result = 150 exceeds upper limit
a = -125, b = -25, sum =-127(negative saturation ) as result = -150 exceeds lower limit