HDL Lab Manual VTU
HDL Lab Manual VTU
Hardware Description
Language
Lab Manual
L.K.S
L.K.S
ll Cycle
I. Write a VHDL/VERILOG code to simulate and synthesize the function of Full
Adder using the following modeling styles and demonstrate the operation.
a) Data Flow. b) Behavioral. c) Structural.
2. Write a VHDL/VERILOG code to simulate SRFF and demonstrate the
operation.
3. Write a VHDL/VERILOG code to simulate JKFF.
4. Write a VIIDL/VERILOG code to synthesize T flip-flop.
5. Write a VHDL/VERILOG code to synthesize D flip-flop.
Ill Cycle
1. Write a VHDL/VERILOG code to synthesize 4 bit binary to gray code
converter.
2. Write a VHDL/VERILOG model for 4-bit ALU to simulate the following
functions
i) A + B
v) A AND B
ii) A-B
vi)A or B
iii) A Complement
vii) A NAND B
iv) A * B
viii) A XOR B.
3. Write a VHDL/VERILOG to synthesize BCD counter with
synchronous/asynchronous reset.
4. Write a VHDL/VERILOG code to synthesize 4 bit binary counter with
synchronous/ asynchronous reset.
5. Write a VHDL/VERILOG code to simulate a counter which counts the
sequence ______.
L.K.S
L.K.S
L.K.S
L.K.S
1. Write HDL code to realize logic gates and demonstrate the operation.
i) VHDL code
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity basic_gates is
Port ( a,b : in std_logic;
and_g, or_g, not_a, nand_g, nor_g, xor_g, xnor_g : out std_logic);
end basic_gates;
architecture logic_gates of basic_gates is
begin
Truth Table
and_g <= a and b;
a b And_g or_g not_a nor_g nand_g
or_g <= a or b;
0 0
0
0
1
1
1
not_a <= not a ;
0 1
0
1
1
0
1
nor_g <= a nor b;
1 0
0
1
0
0
1
nand_g <= a nand b;
1
1
1
0
0
1
0
xor_g <= a xor b;
xnor_g <=a xnor b;
end logic_gates;
xor_g
xnor_
g
0
1
1
0
1
0
0
1
RESULT: The gates were simulated and the truth table and waveforms were
observed on modelsim and verified.
L.K.S
2. Describe the function of full adder using the following modeling styles
and demonstrate the operation.
a) Data flow
b) Behavioral
c) Structural
a) Data flow
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity fad is
Port (cin, a, b: in std_logic;
s, c: out std_logic);
end fad;
architecture Behavioral of fad is
begin
s<=(a xor b) xor cin;
c<=(a and b)or (b and cin) or (cin and a);
end Behavioral;
ii) Verilog Code
module dataflow(a, b, c, sum, carry);
input a;
input b;
input c;
output sum;
output carry;
assign sum = a ^ b ^ c;
assign carry = (a & b) | (b & c) | (c & a);
endmodule
b) Behavioral
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity fab is
Port ( d : in std_logic_vector(2 downto 0);
e : out std_logic_vector(1 downto 0));
end fab;
architecture Behavioral of fab is
begin
process(d)
begin
if (d="000") then e<="00";
elsif (d="001") then e<="10";
elsif (d="010") then e<="10";
elsif (d="011") then e<="01";
elsif (d="100") then e<="10";
elsif (d="101") then e<="01";
elsif (d="110") then e<="01";
else e<="11";
end if;
end process;
end Behavioral;
L.K.S
a
0
0
0
0
1
1
1
1
b c
0 0
0 1
1 0
1 1
0 0
0 1
1 0
1 1
Truth Table
Sum Carry
0
0
1
0
1
0
0
1
1
0
0
1
0
1
1
1
e=sc
00
10
10
01
10
01
01
11
L.K.S
C) Structural
i) VHDL code
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FullAdder is
Port ( Ain : in std_logic; Bin : in std_logic; Cin : in std_logic; Cout : out std_logic;
Sum : out std_logic);
end FullAdder;
architecture FullAdder of FullAdder is
-- Half Adder Component being Instantiated
Component Halfadder
Port ( Ain : in std_logic;
Bin : in std_logic;
Sum : out std_logic;
Carry : out std_logic);
end Component;
Signal temp1,temp2, temp3: std_logic; -- Signal Declaration
Begin
L1: Halfadder port map (Ain, Bin, temp1, temp2);
L2: Halfadder port map (temp1, Cin, Sum, temp3);
Cout <= temp2 or temp3;
end FullAdder;
ii) Verilog Code
module fulladd(a, b, c, sum, carry);
input a;
input b;
input c;
output sum;
output carry;
ha h1(b, c, s0, c0);
ha h2(a, s0, sum, c1);
or(carry, c0, c1);
endmodule
RESULT: The full adder using data flow, behavioral and structural models was simulated
and the truth table was verified and waveforms were observed on modelsim.
L.K.S
3. Write HDL code for the following combinational design and demonstrate
the operation.
a) 2 to 4 decoder
b) 4 bit binary to gray code converter.
a) 2 to 4 decoder
i)
VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity 2dec is
Port ( x : in std_logic_vector(1 downto 0);
e : in std_logic;
y : out std_logic_vector(3 downto 0));
end 2dec;
architecture Behavioral of 2dec is
begin
process (x,e)
begin
if (e=0) then y<=0000;
else
case x is
when "00"=>y<="0001";
when "01"=>y<="0010";
when "10"=>y<="0100";
when "11"=>y<="1000";
when others => null;
end case;
end if;
end process;
end Behavioral;
10
L.K.S
RESULT: The HDL program for 2 to 4 decoder is simulated and Truth Table is
verified and the waveforms were observed on modelsim
11
L.K.S
Verilog code:
RESULT: The HDL program for 4 bit binary to gray code converter were
simulated and the truth table was verified and waveforms were
observed on modelsim.
Department of Electronics & Instrumentation, BIT
12
L.K.S
4. Write HDL code for the following combinational design and demonstrate
the operation.
a) 8:1 Multiplexer. b) 1:4 Demultiplexer.
a) 8:1 Multiplexer.
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity multi_81 is
Port ( i : in STD_LOGIC_VECTOR (7 downto 0);
sel : in STD_LOGIC_VECTOR (2 downto 0);
y : out STD_LOGIC;
en : in STD_LOGIC);
end multi_81;
architecture Behavioral of multi_81 is
begin
process(sel,i,en)
begin
if(en='0')then y<='0';
else
case (sel) is
when "000"=>y<=i(0);
when "001"=>y<=i(1);
when "010"=>y<=i(2);
when "011"=>y<=i(3);
when "100"=>y<=i(4);
when "101"=>y<=i(5);
when "110"=>y<=i(6);
when "111"=>y<=i(7);
when others=>null;
end case;
end if;
end process;
end Behavioral;
13
L.K.S
RESULT: The gates were simulated and the truth table and waveforms were
observed on modelsim and verified.
14
L.K.S
b) 1:4 Demultiplexers.
i)
VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity mux_14 is
Port (sel: in std_logic_vector (1 downto 0) ;
d: out std_logic_vector(3 downto 0) ;
y: in std_logic);
end mux_14;
architecture Behavioral of mux_14 is
begin
process (sel,y)
begin
d<= 0000;
case sel is
when "00"=> d(0)<=y;
when "01"=> d(1)<=y;
when "10"=> d(2)<=y;
when "11"=> d(3)<=y;
when others=> null;
end case;
end process;
end Behavioral;
15
L.K.S
WAVEFORM
RESULT: The gates were simulated and the truth table and waveforms were
observed on modelsim and verified.
16
L.K.S
5. Write VHDL code to realize 8 to 3 encoder with and without priority and
demonstrate the operation.
a) WITH PRIORITY
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity withp1 is
Port ( i : in std_logic_vector(7 downto 0);
y : out std_logic_vector(2 downto 0));
end withp1;
architecture Behavioral of withp1 is
begin
y<="000" when i(0)='1'else
"001" when i(1)='1'else
"010" when i(2)='1'else
"011" when i(3)='1'else
"100" when i(4)='1'else
"101" when i(5)='1'else
"110" when i(6)='1'else
"111" when i(7)='1'else
"000";
end Behavioral;
17
L.K.S
WAVEFORM
RESULT: The VHDL program for 8 to 3 encoder with priority was simulated
and the truth table was verified and the waveforms were observed on
modelsim.
18
L.K.S
b) WITHOUT PRIORITY:
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity enc_83 is
Port ( i : in std_logic_vector(7 downto 0);
y : out std_logic_vector(2 downto 0));
end enc_83;
architecture Behavioral of enc_83 is
begin
process (i)
begin
case i is
when "00000001"
when "00000010
when "00000100"
when "00001000"
when "00010000"
when "00100000"
when "01000000"
when "10000000"
when others
=> y<="111";
=> y<="110";
=> y<="101";
=> y<="100";
=> y<="011";
=> y<="010";
=> y<="001";
=> y<="000";
=> y<="000";
end case;
end process;
end Behavioral;
19
L.K.S
WAVEFORM
20
L.K.S
6. Design and implement HDL code for any Sequence counter and
demonstrate its operation:
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity anyseq is
Port ( clk,rst : in std_logic;
q : out std_logic_vector(3 downto 0));
end anyseq;
architecture Behavioral of anyseq is
signal a1: std_logic_vector (3 downto 0);
signal clkdiv : std_logic_vector (20 downto 0);
signal clk1 : std_logic;
begin
process(clk)
begin
if(clkevent and clk=1) then
clkdiv <= clkdiv+1;
end if;
clk1<= clkdiv(15);
end process;
process(clk1)
begin
if (rst ='1') then
a1<="0001";
elsif (clk1'event and clk1='1')then
case a1 is
when "0001" => a1 <="0011";
when "0011" => a1 <="0101";
when "0101" => a1 <="1001";
when "1001" => a1 <="0001";
when others=> a1<="0000";
end case;
end if;
end process;
q<=a1;
end Behavioral;
21
L.K.S
RESULT: The VHDL code for Sequence counter was simulated and waveforms
were observed on modelsim and verified.
Department of Electronics & Instrumentation, BIT
22
L.K.S
7. Design and implement HDL code for a BCD counter using synchronous
and asynchronous reset and demonstrate its operation:
a) Synchronous BCD counter :
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity syncbcdcntr is
Port ( clk,rst : in std_logic;
q : out std_logic_vector(3 downto 0));
end syncbcdcntr;
architecture Behavioral of syncbcdcntr is
signal q1 : std_logic_vector (3 downto 0);
signal clkdiv : std_logic_vector (20 downto 0);
signal clk1 : std_logic;
begin
process(clk)
begin
if(clkevent and clk=1) then
clkdiv <= clkdiv+1;
end if;
clk1<= clkdiv(15);
end process;
process(clk1)
begin
if(clk1'event and clk1='1')then
if(rst='1')then q1 <= "0000";
else
q1 <= q1+1;
if(q1=1001)then
q1=0000;
end if;
end if;
end if;
end process;
q <= q1;
end Behavioral;
23
L.K.S
WAVEFORM
24
L.K.S
25
L.K.S
WAVEFORM
RESULT: The HDL code for BCD Counter using both synchronous and
asynchronous reset was simulated and waveforms were observed on
modelsim and verified.
Department of Electronics & Instrumentation, BIT
26
L.K.S
8. Design and implement HDL code for a Binary counter using synchronous
and asynchronous reset and demonstrate its operation:
a) Synchronous Binary counter
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity synbincntr is
Port ( clk,rst : in std_logic;
q : out std_logic_vector(3 downto 0));
end synbincntr;
architecture Behavioral of synbincntr is
signal q1 : std_logic_vector (3 downto 0);
signal clkdiv : std_logic_vector (20 downto 0);
signal clk1 : std_logic;
begin
process(clk)
begin
if(clkevent and clk=1) then
clkdiv <= clkdiv+1;
end if;
clk1<= clkdiv(15);
end process;
process(clk1)
begin
if(clk1'event and clk1='1')then
if(rst='1')then
q1 <= "0000";
else
q1 <= q1+1;
end if;
end if;
end process;
q <= q1;
end Behavioral;
27
L.K.S
Verilog code:
module synreset_bin_upcounter(clk,rst,qout);
input clk,rst;
output [3:0] qout;
reg [3:0] qout;
reg [20:0] temp1;
reg clk1;
always@(posedge clk)
begin
temp1 =temp1+1;
clk1=temp1[15];
end
always@(posedge clk1)
begin
if (rst)
qout =4b0000;
else
qout=qout+1;
end
endmodule
28
L.K.S
VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity asy_bin is
Port ( clk,rst : in std_logic;
count : out std_logic_vector(3 downto 0));
end asy_bin;
architecture Behavioral of asy_bin is
signal temp:std_logic_vector(3 downto 0);
signal clkdiv : std_logic_vector (20 downto 0);
signal clk1 : std_logic;
begin
process(clk)
begin
if(clkevent and clk=1) then
clkdiv <= clkdiv+1;
end if;
clk1<= clkdiv(15);
end process;
process(clk1,rst)
begin
if (rst='1') then
temp<=0000;
elsif (clk1'event and clk1='1') then
temp <= temp+1;
end if;
end process;
count<=temp;
end Behavioral;
29
ii)
L.K.S
Verilog code:
module asynreset_bin_upcounter(clk,rst,qout);
input clk,rst;
output [3:0] qout;
reg [3:0] qout;
reg [20 :0] temp1;
reg clk1;
always@(posedge clk)
begin
temp1 =temp1+1;
clk1=temp1[15];
end
always@(posedge clk1 or posedge rst)
if (rst==1)
qout=4b0000;
else
begin
qout =qout+1;
end
endmodule
RESULT: The HDL program for 4 bit comparator was simulated and the
truth table was verified and waveforms were observed on modelsim.
30
L.K.S
9. Write HDL code for 4 bit comparator and demonstrate the operation.
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity comparator is
Port ( a,b : in std_logic_vector(3 downto 0);
e,g,l : out std_logic);
end comparator;
architecture Behavioral of comparator is
begin
process(a,b)
begin
if a=b then e<='1';g<='0';l<='0';
elsif a<b then l<='1';e<='0';g<='0';
else g<='1';l<='0';e<='0';
end if;
end process;
end Behavioral;
31
L.K.S
RESULT: The HDL program for 4 bit comparator was simulated and the
truth table was verified and waveforms were observed on modelsim.
32
L.K.S
10. Write a HDL for model for 4 - bit ALU to implement the
following functions:
(i) A + B
(ii) A B
(iii) not A
(iv) A x B
(v) A and B
(VI) A or B
(vii) A nand B
(viii) A xor B
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ALU is
Port ( a1,b1 : in STD_LOGIC_VECTOR (3 downto 0);
opcode: in STD_LOGIC_VECTOR (2 downto 0);
zout: out STD_LOGIC_VECTOR (7 downto 0));
end ALU;
architecture Behavioral of ALU is
signal a: std_logic_vector(7 downto 0);
signal b: std_logic_vector(7 downto 0);
begin
a<="0000" & a1;
b<="0000" & b1;
zout<= a+b when opcode="000" else
a-b when opcode="001" else
a or b when opcode="010" else
a and b when opcode="011" else
not a when opcode="100" else
a1*b1 when opcode="101" else
a nand b when opcode="110" else
a xor b when opcode="111";
end Behavioral;
33
L.K.S
WAVEFORM
RESULT: The HDL program for 4 bit ALU was simulated and the truth
table was verified and waveforms were observed on modelsim.
34
L.K.S
11. Develop the HDL code for the following flip-flops and demonstrate the
operation.
a) SR-FF
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity s_r_flip_flop is
Port (s, r, clk: in std_logic;
q: inout std_logic);
end s_r_flip_flop;
architecture Behavioral of s_r_flip_flop is
begin
process (clk)
begin
if (clk'event and clk = '1')then
if(s='0' and r='0') then
q <= q;
elsif (s = '0' and r = '1') then
q <= '0';
elsif (s = '1' and r = '0') then
q <= '1';
elsif (s= '1' and r = '1') then
q <= '0';
end if ;
end if ;
end process;
end Behavioral;
35
L.K.S
q = q;
q = 0;
q = 1;
q = 0;
endmodule
WAVEFORM
36
L.K.S
b) T- FF
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity t_ff is
Port ( t,clk : in std_logic;
q : inout std_logic:=0;
qb: out std_logic);
end t_ff;
architecture Behavioral of t_ff is
signal clkdiv : std_logic_vector (20 downto 0);
signal clk1 : std_logic;
begin
process(clk)
begin
if(clk'event and clk='1') then
clkdiv <= clkdiv+1;
end if;
clk1<= clkdiv (15);
end process;
process (clk1,t)
begin
if (clk1'event and clk1 = '1')then
if (t='0') then
q<= '0';
elsif ( t = '1') then
q<= not q;
end if ;
end if ;
end process;
qb<=not q;
end Behavioral;
37
L.K.S
WAVEFORM
38
L.K.S
c) D-FF
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity d_ff is
Port ( d,clk : in std_logic;
q,qb : inout std_logic);
end d_ff;
architecture Behavioral of d_ff is
begin
process (clk)
begin
if (clk'event and clk = '1') then
q<= d;
qb<=not d;
end if ;
end process;
end Behavioral;
ii) Verilog code:
module dff(clk, d, q, qb);
input clk,d;
output q,qb;
reg q,qb;
always @ (posedge clk)
begin
q=d;
qb = ~q;
end
endmodule
WAVEFORM
39
L.K.S
d) JK-FF
i) VHDL code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity jkff is
Port ( clk,rst,j,k : in std_logic;
q : inout std_logic:=0;
qb : out std_logic);
end jkff;
architecture Behavioral of jkff is
signal clkdiv : std_logic_vector (20 downto 0);
signal clk1 : std_logic;
begin
process(clk)
begin
if(clk'event and clk='1') then
clkdiv <= clkdiv+1;
end if;
clk1<= clkdiv(15);
end process;
process(clk1,rst)
begin
if(rst='1')then q<='0';
elsif(clk1'event and clk1='1')then
if(j='0' and k='0')then q<=q;
elsif(j='0' and k='1')then q<='0';
elsif(j='1' and k='0')then q<='1';
elsif(j='1' and k='1')then q<=not q;
end if;
end if;
end process;
qb<= not q;
end Behavioral;
40
L.K.S
RESULT: The HDL program for all flip flops were simulated and the
Truth table was verified and waveforms were observed on modelsim.
Department of Electronics & Instrumentation, BIT
41
L.K.S
42
L.K.S
LOC = "S:PIN20";
LOC = "S:PIN1";
LOC = "S:PIN2";
LOC = "S:PIN3";
LOC = "S:PIN9";
PIN CONNECTION ON CPLD BOARD
43
L.K.S
44
L.K.S
-- process keyval
process(skeyhit)
begin
if( rising_edge(skeyhit)) then
if(lkeyscn = "1110" and lkeyret = "1110")
then skeyflr <= 0;
elsif(lkeyscn = "1110" and lkeyret = "1101")
then skeyflr <= 1;
elsif(lkeyscn = "1110" and lkeyret = "1011")
then skeyflr <= 2;
elsif(lkeyscn = "1110" and lkeyret = "0111")
then skeyflr <= 3;
elsif(lkeyscn = "1101" and lkeyret = "1110")
then skeyflr <= 4;
elsif(lkeyscn = "1101" and lkeyret = "1101")
then skeyflr <= 5;
elsif(lkeyscn = "1101" and lkeyret = "1011")
then skeyflr <= 6;
elsif(lkeyscn = "1101" and lkeyret = "0111")
then skeyflr <= 7;
elsif(lkeyscn = "1011" and lkeyret = "1110")
then skeyflr <= 8;
elsif(lkeyscn = "1011" and lkeyret = "1101")
then skeyflr <= 9;
elsif(lkeyscn = "1011" and lkeyret = "1011")
then skeyflr <= 10;
elsif(lkeyscn = "1011" and lkeyret = "0111")
then skeyflr <= 11;
elsif(lkeyscn = "0111" and lkeyret = "1110")
then skeyflr <= 12;
elsif(lkeyscn = "0111" and lkeyret = "1101")
then skeyflr <= 13;
elsif(lkeyscn = "0111" and lkeyret = "1011")
then skeyflr <= 14;
elsif(lkeyscn = "0111" and lkeyret = "0111")
then skeyflr <= 15;
end if;
end if;
end process;
45
L.K.S
begin
pdspseg <= segval(scurflr);
pdspmux <= "1110";
end process;
end behavioral;
Department of Electronics & Instrumentation, BIT
46
L.K.S
LOC = "P14" ;
LOC = "P15" ;
LOC = "P17" ;
LOC = "P18" ;
LOC = "P31"
LOC = "P32"
LOC = "P33"
LOC = "P34"
LOC = "P35"
LOC = "P36"
LOC = "P37"
;
;
;
;
;
;
;
CNKEY
Header-2
CHANNEL
MUX
Header-3
Of CPLD
SEGMENT
47
L.K.S
48
L.K.S
-- process keyval
process(skeyhit)
begin
if( rising_edge(skeyhit)) then
if(lkeyscn = "1110" and lkeyret = "1110")
then skeyval <= 0;
elsif(lkeyscn = "1110" and lkeyret = "1101")
then skeyval <= 1;
elsif(lkeyscn = "1110" and lkeyret = "1011")
then skeyval <= 2;
elsif(lkeyscn = "1110" and lkeyret = "0111")
then skeyval <= 3;
elsif(lkeyscn = "1101" and lkeyret = "1110")
then skeyval <= 4;
elsif(lkeyscn = "1101" and lkeyret = "1101")
then skeyval <= 5;
elsif(lkeyscn = "1101" and lkeyret = "1011")
then skeyval <= 6;
elsif(lkeyscn = "1101" and lkeyret = "0111")
then skeyval <= 7;
elsif(lkeyscn = "1011" and lkeyret = "1110")
then skeyval <= 8;
elsif(lkeyscn = "1011" and lkeyret = "1101")
then skeyval <= 9;
elsif(lkeyscn = "1011" and lkeyret = "1011")
then skeyval <= 10;
elsif(lkeyscn = "1011" and lkeyret = "0111")
then skeyval <= 11;
elsif(lkeyscn = "0111" and lkeyret = "1110")
then skeyval <= 12;
elsif(lkeyscn = "0111" and lkeyret = "1101")
then skeyval <= 13;
elsif(lkeyscn = "0111" and lkeyret = "1011")
then skeyval <= 14;
elsif(lkeyscn = "0111" and lkeyret = "0111")
then skeyval <= 15;
end if;
end if;
end process;
-- process clk divider
process(pclk100k)
begin
if( rising_edge(pclk100k)) then
sclkdiv <= sclkdiv+1;
end if;
skeyclk <= sclkdiv(6);
Department of Electronics & Instrumentation, BIT
49
L.K.S
end process;
-- process for key scan clkscan
process(skeyclk)
begin
if(rising_edge(skeyclk)) then
if skeyscn = "1110" then skeyscn <= "1101";
elsif skeyscn = "1101" then skeyscn <= "1011";
elsif skeyscn = "1011" then skeyscn <= "0111";
elsif skeyscn = "0111" then skeyscn <= "1110";
else skeyscn <= "1110";
end if;
end if;
pkeyscn <= skeyscn;
end process;
-- process display 7seg
process(skeyval)
type tseg7 is array(0 to 15) of std_logic_vector (6 downto 0);
constant segval
: tseg7 :=
("0111111","0000110","1011011","1001111","1100110","1101101","1111101","
0000111","1111111","1101111","1110111","1111100","1011000","1011110","111
1001","1110001");
begin
pdspseg <= segval(skeyval);
pdspmux <= "1101";
end process;
end behavioral;
UCF FILE FOR HEXKEYPAD
NET "pclk100K"
LOC = "p66" ;
NET "pkeyret<0>"
NET "pkeyret<1>"
NET "pkeyret<2>"
NET "pkeyret<3>"
NET "pkeyscn<0>"
NET "pkeyscn<1>"
NET "pkeyscn<2>"
NET "pkeyscn<3>"
LOC = "P1"
LOC = "P2"
LOC = "P3"
LOC = "P4"
LOC = "P5"
LOC = "P6"
LOC = "P7"
LOC = "P9"
NET "pdspmux<0>"
NET "pdspmux<1>"
NET "pdspmux<2>"
NET "pdspmux<3>"
NET "pdspseg<0>"
NET "pdspseg<1>"
NET "pdspseg<2>"
NET "pdspseg<3>"
;
;
;
;
;
;
;
;
LOC = "P14"
LOC = "P15"
LOC = "P17"
LOC = "P18"
LOC = "P31"
LOC = "P32"
LOC = "P33"
LOC = "P34"
;
;
;
;
;
;
;
;
50
L.K.S
CNKEY
Header-2
CHANNEL
MUX
Header-3
Of CPLD
SEGMENT
51
L.K.S
52
L.K.S
begin
if(falling_edge(sdspclk) ) then
vdspseq := vdspseq+1;
end if;
if(falling_edge(sdspclk) ) then
if(vdspseq > 3) then
vdspnum := vdspnum+1;
end if;
end if;
if(vdspseq < 4) then
plcddat <= tlcddat(vdspseq);
vdspnum := 0;
else
plcddat <= tlcddat(vdspseq);
tchr1 <= mystr(vdspnum);
plcddat <=
std_logic_vector(to_unsigned(character'pos(tchr1),8));
end if;
plcdrw <= '0';
if(vdspseq < 4) then
plcdrs <= '0';
else
plcdrs <= '1';
end if;
end process;
end behavioral;
LOC = P77";
LOC = P1";
LOC = P2";
LOC = P3";
53
L.K.S
Header-1
Control
Header-2
of CPLD
Data
54
L.K.S
op<=q;
end Behavioral;
#PINLOCK_BEGIN
NET "clk"
LOC =
NET "rst"
LOC =
NET "op<0>"
LOC =
NET "op<1>"
LOC =
NET "op<2>"
LOC =
NET "op<3>"
LOC =
NET "op<4>"
LOC =
NET "op<5>"
LOC =
NET "op<6>"
LOC =
NET "op<7>"
LOC =
#PINLOCK_END
"S:PIN1";
"S:PIN2";
"S:PIN3";
"S:PIN4";
"S:PIN5";
"S:PIN6";
"S:PIN7";
"S:PIN9";
"S:PIN10";
"S:PIN11";
55
L.K.S
56
L.K.S
57
L.K.S
58
L.K.S
LOC = "S:PIN10";
NET "pkeycol<0>"
NET "pkeycol<1>"
NET "pkeycol<2>"
NET "pkeycol<3>"
LOC =
LOC =
LOC =
LOC =
"S:PIN1";
"S:PIN2";
"S:PIN3";
"S:PIN4";
LOC =
LOC =
LOC =
LOC =
"S:PIN11";
"S:PIN12";
"S:PIN13";
"S:PIN14";
Interfacing Module
Motor
2
HEADER 1
Power
CNKEY
59
L.K.S
60
L.K.S
end Behavioral;
#PINLOCK_BEGIN
NET "clk"
NET "rst"
NET "op<0>"
NET "op<1>"
NET "op<2>"
NET "op<3>"
NET "op<4>"
NET "op<5>"
NET "op<6>"
NET "op<7>"
#PINLOCK_END
LOC =
LOC =
LOC =
LOC =
LOC =
LOC =
LOC =
LOC =
LOC =
LOC =
"S:PIN1";
"S:PIN2";
"S:PIN3";
"S:PIN4";
"S:PIN5";
"S:PIN6";
"S:PIN7";
"S:PIN9";
"S:PIN10";
"S:PIN11";
61
L.K.S
Ramp / Triangular
CPLD Pin Nos:-
1 is connected to clk
2 is connected to reset
3 is connected to pin21of Interfacing-Module
4 is connected to pin22of Interfacing-Module
5 is connected to pin19of Interfacing-Module
6 is connected to pin20of Interfacing-Module
7 is connected to pin17of Interfacing-Module
9 is connected to pin18of Interfacing-Module
10 is connected to pin15of Interfacing-Module
11 is connected to pin16of Interfacing-Module
Pin no.26 of Interfacing Module is connected to ground
CPLD Board Pins
1
* *
26
24
22
20
18
16
6
4
2
Zigzag pattern
(4)22
21(3)
2 3 4 5 6 7 8 9 10 11 12
*
*
*
*
*
*
*
*
*
*
*
*
* * * * * * * *
*
*
*
*
*
*
*
*
*
*
*
*
25
23
21
19
17
15
*
(6)20
19(5)
(9)18
17(7)
(11)16
15(10)
DAC
Interfacing Module
5
3
1
Power supply
62