Lab Assignment 1
Lab Assignment 1
Lab Assignment 1
Example-1
4 to 1 Multiplexer:
Figure 1. 4 to 1 Multiplexer
port (
I0 : in std_logic;
I1 : in std_logic;
I2 : in std_logic;
I3 : in std_logic;
sel : in std_logic_vector (1 downto 0);
output : out std_logic
);
end entity;
begin
case sel is
end case;
end process;
Test-bench code:
library ieee;
use ieee.std_logic_1164.all;
entity tb_mux4_to_1 is
end tb_mux4_to_1;
component mux4_to_1
port (
I0 : in std_logic;
I1 : in std_logic;
I2 : in std_logic;
I3 : in std_logic;
end component;
begin
-- stimulus process
stim_process: process
begin
wait for 50 ns;
end process;
end architecture behavioral;
D Flip-Flop:
In general, we define a synchronous sequential circuit, or just sequential circuit as a circuit with m inputs,
n outputs, and a distinguished clock input.
Figure 3. D Flip-Flop
Source code:
library ieee;
use ieee.std_logic_1164.all;
entity d_flipflop is
port (
clk : in std_logic;
D : in std_logic;
Q : out std_logic
);
end entity;
begin
process (clk, D)
begin
if (clk'event and clk = '1') then
Q <= D;
end if;
end process;
end architecture behavioral;
Test-bench code:
library ieee;
use ieee.std_logic_1164.all;
entity tb_d_flipflop is
end tb_d_flipflop;
component d_flipflop
port (
begin
-- stimulus process
stim_process: process
begin
wait for 50 ns;
tb_D <= '0';
end process;
A binary encoder has 2n input lines and n output lines, hence it encodes the information from 2n inputs into
an n-bit code. From all the input lines, only one of an input line is activated at a time, and depending on the
input line, it produces the n bit output code.
Depending on the number of input lines, digital or binary encoders produce the output codes in the form of
2 or 3 or 4 bit codes.
(a)
Input Output
A[3] A[2] A[1] A[0] B[1] B[0]
0 0 0 1 0 0
0 0 1 0 0 1
0 1 0 0 1 0
1 0 0 0 1 1
(b)
Source code:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity encoder is
port(
A: in STD_LOGIC_VECTOR(3 downto 0);
B: out STD_LOGIC_VECTOR(1 downto 0)
);
end encoder;
process(a)
begin
if (A = "1000") then
B <= "00";
elsif (A = "0100") then
B <= "01";
elsif (A = "0010") then
Test-bench code:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_encoder IS
END tb_encoder;
COMPONENT encoder
PORT(
A : IN std_logic_vector(3 downto 0);
B : OUT std_logic_vector(1 downto 0)
);
END COMPONENT;
--Inputs
signal tb_A : std_logic_vector(3 downto 0) := (others => '0');
--Outputs
signal tb_B : std_logic_vector(1 downto 0);
BEGIN
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 100 ns;
tb_A <= "0000";
wait;
end process;