Академический Документы
Профессиональный Документы
Культура Документы
Nilesh
Chaurasia
Submitted by:Description of VHDL Codes
The original standard for VHDL was adopted in 1987 called IEEE 1076. A
Input and output signals for entity are called its ports and written by
keyword PORT. Each port has an associated mode that specifies whether
In2: in std_logic;
Out1:out std_logic);
end orgate;
architecture behavioral of orgate is
begin
out1<=in1 or in2;
end behavioral;
(a: in std_logic;
b: in std_logic;
y:out std_logic);
end andgate;
architecture behavioral of andgate is
begin
out1<=a and b;
end behavioral;
use ieee.std_logic_unsigned.all;
entity mux is
port
(a,b,c,d,s1,s2:in std_logic;
y:out std_logic);
end mux;
architecture behavioral of mux is
begin
y<=(a and not s1 and not s2)or(b and not s1 and s2)or(c and s1 and not s2)or(d
and s1 and s2);
end behavioral;
port(a,b: in std_logic;
sum,carry: out std_logic);
end fa;
architecture behavioral of fa is
signal d: std_logic;
begin
d<=(a and not b)or(not a and b);
sum<=(d and not c)or(not d and c);
carry<=(d and c)or(a and b);
end behavioral;
Structural coding
Or gate
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity or1 is
port
(x,y:in std_logic;
z: out std_logic);
end or1;
architecture behavioral of or1 is
begin
z<=x or y;
end behavioral;
entity circuit is
port(a,b: in bit;
c:out bit);
end circuit;
architecture str of circuit is
component orstr
port(x,y: in bit;
y:out bit);
end component;
begin
gate:orstr portmap(a,b,c);
end orstr;
And gate
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity and1 is
port(x:in std_logic;
y: in std_logic
z: out std_logic);
end and1;
architecture behavioral of and1 is
begin
z<=x and y;
end behavioral;
entity circuit is
port(a,b: in bit;
c:out bit);
end circuit;
architecture str of circuit is
component andstr
port(x,y: in bit;
z:out bit);
end component;
begin
gate:andstr portmap(a,b,c);
end notstr;
Not gate
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity not1 is
port(x:in std_logic;
y: out std_logic);
end not1;
architecture behavioral of not1 is
begin
y<=not x;
end behavioral;
entity circuit is
port(a: in bit;
b:out bit);
end circuit;
architecture str of circuit is
component notstr
port(x: in bit;
y:out bit);
end component;
begin
gate:notstr portmap(a,b);
end notstr;
Half adder
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity ha1 is
port
(w,x:in std_logic;
y,z: out std_logic);
end ha1;
architecture behavioral of ha1 is
begin
s<=(a and not b)or(not a and b);
c<=a and b;
end behavioral;
entity circuit is
port(a,b: in bit;
c,d:out bit);
end circuit;
architecture str of circuit is
component hastr
port(w,x: in bit;
y,z:out bit);
end component;
begin
gate:hastr portmap(a,b,c,d);
end hastr;
Full adder
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity fa1 is
port(x0,x1,x2:in std_logic;
y0,y1: out std_logic);
end fa1;
architecture behavioral of fa1 is
begin
a<=(x0 and not x1)or(not x0 and x1);
multiplexer
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity notx2 is
port(inn: in bit;
outn: out bit);
end notx2;
outn:out bit);
component andx2
port(ina1,ina2,ina3,ina4: in bit;
outa1: out bit);
end component;
component orx2
port(ino1,ino2,ino3,ino4: in bit;
outo1: out bit);
end component;
signal d0,d1,d2,d3,m1,m2: bit;
begin
notg1:notx2 portmap(s1,m1);
notg2:notx2 portmap(s2,m2);
andg1:andx2 portmap(m1,m2,in1,d0);
andg1:andx2 portmap(m1,s2,in2,d1);
andg1:andx2 portmap(s1,m2,in3,d2);
andg4:andx2 portmap(s1,s2,in4,d3);
org1:orx2 portmap(d0,d1,d2,d3,out1);
end behavioural;
De-multiplexer
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity notx2 is
port(inn: in bit;
(d: in std_logic;
clk:in std_logic;
q<=out std_logic);
end dl;
architecture behavioral of dl is
begin process(d,clk)
begin if clk=1 then
q<=d;
end if;
end process;
end behavioral;
D-flipflop
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity dl is
port
(d: in std_logic;
clk:in std_logic;
q<=out std_logic);
end dl;
architecture behavioral of dl is
begin process(d,clk)
begin if clkevent and clk=1, then
q<=d;
end if;
end process;
end behavioral;
D-register
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity dr is
port(d: in std_logic_vector(3 downto 0);
resetn,clk:in std_logic;
q:out std_logic_vector(3 downto 0));
end dr;
architecture behaviour of dr is
begin
process
begin if resetn=1 then
q<=0000;
else
q<=d;
end if;
end process;
end behaviour;
shift register
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity df is
port(d,clk,resetn:in bit;
q:out bit);
end df;
architecture behavioral of df is
begin process (d,clk,resetn)
begin
if resetn=0 then
q<=0;
else if clkevent and clk=1 then q<=d;
else
end if;
end process;
end behavioral;
entity reg is
port(dl,clkl,resetnl:in bit;
q<=out bit);
end reg;
architecture str of reg is
component df
port(d,clk,resetn:in bit;
q<=out bit);
end component;
signal m1.m2,m3:bit;
dfg1:df portmap(dl,clkl,m1,resetnl);
dfg1:df portmap(dl,m1,m2,resetnl);
dfg1:df portmap(dl,m2,m3,resetnl);
dfg4:df portmap(dl,m3,q1,resetnl);
end str;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity jk is
port(j,k,clk:in bit;
q:inout bit);
end jk;
architecture behavioral of jk is
signal qm: std_logic;
begin
process(j,k,clk)
begin if clkevent and clk=1 then
qm<=(j and not q)or(not k and q);
end if;
end process;
q<=qm;
end behavioral;
Up-counter
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity upcnt is
port(clk: in std_logic;
q:inout std_logic_vector(3 downto 0);
rst:in std_logic);
end upcnt;
architecture behavioral of dn is
begin
process(clk)
begin
if rst=1 and clk=1 then
q<=0000;
end if;
if rst=0and clk=1 then
q<=q+1;
end if;
end process;
end behavioral;
Down-counter
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity dncnt is
port(clk: in std_logic;
q:inout std_logic_vector(3 downto 0);
rst:in std_logic);
end dncnt;
architecture behavioral of dncnt is
begin
process(clk)
begin
7- Segment driver
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity seven_segment is
port(d: in std_logic_vector(3 downto 0);
y: out std_logic_vector(6 downto 0));
architecture behavioral of seven_segment is
begin
with d select
y<=1111110when0000,
0110000when0001,
1101101when0010,
1111001when0011,
0110011when0100,
1011011when0101,
1011111when0110,
1110000when0111,
1111111when1000,
1111011when1001;
0000000when others;
end behavioral;
Simulation
Steps for simulation
1.
2.
3.
4.
5.
6.
Demultiplexer
Multiplexer
Seven segment
Encoder
d-latch
Half Adder
J-K Flip-Flop
Down-Counter