Documente Academic
Documente Profesional
Documente Cultură
SITEC ELECTRONICS
# 13, 1ST Floor, Srinivas Theater Road,
Subramanyapura Post, Bangalore-560061
TeleFax: 91-80-26667618,Cell:9448367618
Email: sitec@vsnl.net, info@chipmaxasia.com
Web: www.chipmaxasia.com
VTU LAB MANUAL
(EC/TC)
Note: Programming can be done using any VHDL compiler. Download the programs on a FPGA/CPLD board and
test performance using 16/32 channel pattern generator and logic analyzer apart from verification by simulation.
Use the pattern generator to generate input signal and truth tables.
PROGRAMMING
1. Write VHDL code to realize all the logic gates
2. Write a VHDL program for the following combinational designs
a. 2 to 4 decoder
b. 8 to 3 (encoder without priority & with priority)
c. 8 to 1 multiplexer
d. 4 bit binary to gray converter
e. Multiplexer, demultiplexer, comparator
3. Write a VHDL code to describe the functions of a Full Adder Using following modeling styles,
4. Write a model for 32 bit ALU using the schematic diagram shown below.(example only)
A(31:0) B(31:0)
Opcode(3:0)
E bl
Out
ALU should use combinational logic to calculate an output based on the four bit op-code input
ALU should pass the result to the out bus when enable line in high, and tri-state the out bus when
the enable line is low.
ALU should decode the 4 bit op-code according to the given in example below
©Copyright Reserved 2
VTU LAB MANUAL
INTERFACING
1. Write VHDL code to display messages on the given seven segment display and LCD and accepting Hex key
pad input data.
2 Write a VHDL code to accept 8 channel Analog signal, Temperature sensors and display the data on LCD
panel or Seven segment display.
6. Write VHDL Code to generate different waveforms (Sine square Triangle, Ramp etc) using DAC change the
frequency and amplitude.
------------------------------------------------------------- -----------------------------------------------------------------
©Copyright Reserved 3
VTU LAB MANUAL
PREFACE
The VLSI industry has already crossed the quarter-micron threshold and devices with 0.18
micron feature-size are already in market. Thus, it becomes extremely difficult to design
complex circuits with the help of conventional designing methods. The computer aided
design tools introduced serve the purpose.
We are very happy to see that VTU has introduced the VHDL Lab into its curriculum so
that students will be studying the emerging and ever-growing technology.
We expect this Manual will make all the students able to work from day one in the industry
and impart their knowledge to expand the information pool for a better life.
To realize the design, programmable logic devices such as CPLDs (Complex Programmable
Logic Devices) and FPGAs (Field Programmable Gate Arrays), come in very handy. Since
these devices are programmable, the user can modify their designs very easily and
conveniently.
This manual is prepared with a purpose of bring out the complete solution to cover the
whole syllabus of the VIth semester Electronics and Communication VHDL LAB as per VTU
Syllabus.
------------------------------------------------ ------------------------------------------------------
©Copyright Reserved 4
VTU LAB MANUAL
Requirement
1.VHDL software with both front-end and backend (Design entry, synthesis, simulation,
implementation and programming.
2. FPGA kit with minimum 100,000 gate density
3.Interfacing cards like LCD,7-segment display, keyboard, ADC, DAC, Stepper Motor, DC Motor &
Relays.
4. Bit pattern generator cum Logic analyzer
Procedure.
Software part
1. Click on the Project navigator icon on the desktop of your PC. Write the vhdl code , check syntax,
perform the functional simulation using ModelsimXE. **
2. Open a new UCF file and lock the pins of the design with FPGA I/O pins.*
3. Implement the design by double clicking on the implementation tool selection.**
4. Check the implementation reports. **
5. Create programming file. **
Note :
* refer FPGA KIT user manual for I/O pins.
** refer ISE flow Manual
Hardware part
Lab session -1
Connect the FPGA kit to the parallel port of the PC through the cable provided along with the Kit.
Connect the FRC cable provided with the kit to the Bit Pattern generator and logic analyzer.
Hardware part
Lab session -2
3. For interfacing the cards connect the required part of the interfacing card to the FRC connector
Provided on the FPGA kit.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity gates is
Port ( Ain : in std_logic; ---- First Input
Bin : in std_logic; ---- Second Input
Op_not : out std_logic;
Op_or : out std_logic;
Op_and : out std_logic;
Op_nor : out std_logic;
Op_nand : out std_logic;
Op_xor : out std_logic;
Op_xnor : out std_logic);
end gates;
architecture Behavioral of gates is
begin
Op_not <= not Ain;
Op_or <= Ain or Bin;
Op_and <= Ain and Bin;
Op_nor <= Ain nor Bin;
Op_nand <= Ain nand Bin;
Op_xor <= Ain xor Bin;
Op_xnor <= Ain xnor Bin;
end Behavioral;
UCF file(User constraint file)
NET "Ain" LOC = "p74";
NET "Bin" LOC = "p75";
NET "Op_and" LOC = "p84";
NET "Op_nand" LOC = "p85";
NET "Op_nor" LOC = "p86";
NET "Op_not" LOC = "p87";
NET "Op_or" LOC = "p93";
NET "Op_xnor" LOC = "p94";
NET "Op_xor" LOC = "p95";
Device utilization summary:
---------------------------
Selected Device : 2s100tq144-6
Number of Slices: 1 out of 1200 0%
Number of 4 input LUTs: 2 out of 2400 0%
Number of bonded IOBs: 9 out of
©Copyright Reserved 6
VTU LAB MANUAL
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity Decoder2_4 is
port ( Enable: in STD_LOGIC;
D_IN: in STD_LOGIC_VECTOR (1 downto 0); -- Two Bit Input for the Decoder
D_OUT: out STD_LOGIC_VECTOR (3 downto 0)); -- Four Bit Output for the Decoder
end Decoder2_4;
===============================================================
©Copyright Reserved 7
VTU LAB MANUAL
entity Encoder8_3 is
end Encoder8_3;
Synthesis Report
===============================================================
Device utilization summary:
---------------------------
Selected Device : 2s100tq144-5/-6
©Copyright Reserved 9
VTU LAB MANUAL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Mux8_1 is
port ( SEL: in STD_LOGIC_VECTOR(2 downto 0); -- Select Lines
A,B,C,D,E,F,G,H :in STD_LOGIC; -- Inputs of the Mux.
MUX_OUT: out STD_LOGIC ); -- OutPut of the Mux.
end Mux8_1;
begin
process (SEL,A,B,C,D,E,F,G,H)
begin
case SEL is
when "000" => MUX_OUT <= A;
when "001" => MUX_OUT <= B;
when "010" => MUX_OUT <= C;
when "011" => MUX_OUT <= D;
when "100" => MUX_OUT <= E;
when "101" => MUX_OUT <= F;
when "110" => MUX_OUT <= G;
when "111" => MUX_OUT <= H;
when others => null;
end case;
end process;
end mux4_1_arch;
Synthesis Report
===============================================================
Device utilization summary:
---------------------------
Selected Device : 2s100tq144-5 /-6
©Copyright Reserved 11
VTU LAB MANUAL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Binary_Gray is
end binary_gray;
b(3)<= a(3);
b(2)<= a(3) xor a(2);
b(1)<= a(2) xor a(1);
b(0)<= a(1) xor a(0);
end behavioral;
Synthesis Report
===============================================================
Device utilization summary:
---------------------------
Selected Device : 2s100tq144-5/-6
©Copyright Reserved 12
VTU LAB MANUAL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Demux1_4 is
port ( d_in: in STD_LOGIC; --Input For Demultiplexer
sel: in STD_LOGIC_VECTOR (1 downto 0); --Select Line of Demux
d_out: out STD_LOGIC_VECTOR (3 downto 0)); --Output Lines of Demux
end Demux1_4;
begin
process(d_in,sel)
begin
d_out<="0000";
case sel is
when "00" => d_out(0)<=d_in;
when "01" => d_out(1)<=d_in;
when "10" => d_out(2)<=d_in;
when others => d_out(3)<=d_in;
end case;
end process;
end demux1_4_arch;
Synthesis Report
===============================================================
Device utilization summary:
---------------------------
Selected Device : 2s100tq144-5
Number of Slices: 2 out of 1200 0%
Number of 4 input LUTs: 4 out of 2400 0%
Number of bonded IOBs: 7 out of 96 7%
©Copyright Reserved 13
VTU LAB MANUAL
7.-- Combinational VHDL Code for N Bit Comparator
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity comparator is
Generic (N: integer := 3); --- Generalizing the Inputs
©Copyright Reserved 14
VTU LAB MANUAL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Halfadder is
Port ( Ain, Bin : in std_logic; --2Bit Input
Sum, Carry : out std_logic);--sum& carry
end Halfadder;
begin
Sum <= Ain xor Bin;
Carry<= Ain and Bin;
end Behavioral;
8b.-- VHDL Code for Full Adder Using Component Instantiation Method.
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; --Input One
Bin : in std_logic; --Input Two
Cin : in std_logic; --Carry Input
Cout : out std_logic; --Carry Output
Sum : out std_logic); --Sum Output
end FullAdder;
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
©Copyright Reserved 15
VTU LAB MANUAL
Synthesis Report
===============================================================
Device utilization summary:
Selected Device : 2s100tq144-5
Number of Slices: 1 out of 1200 0%
Number of 4 input LUTs: 2 out of 2400 0%
Number of bonded IOBs: 5 out of 96 5%
©Copyright Reserved 16
VTU LAB MANUAL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_SIGNED.ALL;
entity ALU is
Port ( A : in std_logic_vector(15 downto 0); -- First Input
B : in std_logic_vector(15 downto 0); -- Second Input
Opcode : in std_logic_vector(2 downto 0); -- Op-code to select the operations
enb : in std_logic; -- Enable Signal
op : out std_logic_vector(15 downto 0)); -- Output of the ALU
end ALU;
end process;
end Behavioral;
©Copyright Reserved 17
VTU LAB MANUAL
===============================================================
---Synthesis Report
Device utilization summary:
---------------------------
Selected Device : 2s100tq144-5 /-6
Number of Slices: 337 out of 1200 28%
Number of 4 input LUTs: 674 out of 2400 28%
Number of bonded IOBs: 100 out of 96 104% (*)
©Copyright Reserved 18
VTU LAB MANUAL
Sequential circuits
entity SRFF is
port (
s: in bit; -- S Bit Input
r: in bit; -- R Bit Input
clk: in bit; -- Global Clock
q: buffer std_logic );
end SRFF;
begin
process(clk)
begin
end process;
end s_r_ff_arch;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity DFF is
port (
clk: in STD_LOGIC; --Global Clock as Input
d: in STD_LOGIC; -- Single bit Input
q: out STD_LOGIC ); -- Single bit output
end DFF;
Synthesis Report
===============================================================
Device utilization summary:
---------------------------
Selected Device : 2s100tq144-5/-6
©Copyright Reserved 20
VTU LAB MANUAL
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 : in BIT; -- Global Input Clock Signal.
J : in BIT; -- Single Bit Input J.
K : in BIT; -- Single Bit Input K.
Reset :in BIT; -- Global Input Reset Signal.
Q : buffer BIT ); -- Q as the Buffered Output.
end JKFF;
©Copyright Reserved 21
VTU LAB MANUAL
Synthesis Report
===============================================================
Device utilization summary:
---------------------------
Selected Device : 2s100tq144-5 /-6
©Copyright Reserved 22
VTU LAB MANUAL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity TFF is
port ( T: in STD_LOGIC; -- Input T
clk: in STD_LOGIC; -- Global Clock Signal
q: out STD_LOGIC ); -- Q Output
end TFF;
--Synthesis Report
===============================================================
Device utilization summary:
---------------------------
Selected Device : 2s100tq144-5 /-6
Number of Slices: 1 out of 1200 0%
Number of Slice Flip Flops: 1 out of 2400 0%
Number of bonded IOBs: 2 out of 96 2%
Number of GCLKs: 1 out of 4 25%
©Copyright Reserved 23
VTU LAB MANUAL
entity sync_counter is
port( CLK: in STD_LOGIC; -- GLOBAL CLOCK SIGNAL
RESET: in STD_LOGIC; -- Global Reset Signal
COUNT: out STD_LOGIC_VECTOR( 3 DOWNTO 0)); --Counter Output
end sync_counter;
begin
process (CLK)
begin
end process;
end counter_arch;
©Copyright Reserved 24
VTU LAB MANUAL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity async_counter is
port( CLK: in STD_LOGIC; -- GLOBAL CLOCK SIGNAL
RESET: in STD_LOGIC; -- Global Reset Signal
COUNT: out STD_LOGIC_VECTOR( 3 DOWNTO 0)); --Counter Output
end async_counter;
©Copyright Reserved 25
VTU LAB MANUAL
INTERFACING
--Package for LCD Display (This Package must be added to display all the messages on LCD)
-- THE NUMBERS
constant ONE : std_logic_vector(7 downto 0) := "00110001";
constant TWO : std_logic_vector(7 downto 0) := "00110010";
constant THREE : std_logic_vector(7 downto 0) := "00110011";
constant FOUR : std_logic_vector(7 downto 0) := "00110100";
constant FIVE : std_logic_vector(7 downto 0) := "00110101";
constant SIX : std_logic_vector(7 downto 0) := "00110110";
constant SEVEN : std_logic_vector(7 downto 0) := "00110111";
constant EIGHT : std_logic_vector(7 downto 0) := "00111000";
constant NINE : std_logic_vector(7 downto 0) := "00111001";
constant ZERO : std_logic_vector(7 downto 0) := "00110000";
-- THE CHARACTERS
-- SMAL LETTERS
constant SA : std_logic_vector(7 downto 0) := "01100001";
constant SB : std_logic_vector(7 downto 0) := "01100010";
constant SC : std_logic_vector(7 downto 0) := "01100011";
constant SD : std_logic_vector(7 downto 0) := "01100100";
constant SE : std_logic_vector(7 downto 0) := "01100101";
constant SF : std_logic_vector(7 downto 0) := "01100110";
constant SG : std_logic_vector(7 downto 0) := "01100111";
constant SH : std_logic_vector(7 downto 0) := "01101000";
constant SI : std_logic_vector(7 downto 0) := "01101001";
constant SJ : std_logic_vector(7 downto 0) := "01101010";
constant SK : std_logic_vector(7 downto 0) := "01101011";
constant SL : std_logic_vector(7 downto 0) := "01101100";
constant SM : std_logic_vector(7 downto 0) := "01101101";
constant SN : std_logic_vector(7 downto 0) := "01101110";
constant SO : std_logic_vector(7 downto 0) := "01101111";
constant SP : std_logic_vector(7 downto 0) := "01110000";
constant SQ : std_logic_vector(7 downto 0) := "01110001";
constant SR : std_logic_vector(7 downto 0) := "01110010";
constant SS : std_logic_vector(7 downto 0) := "01110011";
constant ST : std_logic_vector(7 downto 0) := "01110100";
constant SU : std_logic_vector(7 downto 0) := "01110101";
constant SV : std_logic_vector(7 downto 0) := "01110110";
constant SW : std_logic_vector(7 downto 0) := "01110111";
constant SX : std_logic_vector(7 downto 0) := "01111000";
constant SY : std_logic_vector(7 downto 0) := "01111001";
constant SZ : std_logic_vector(7 downto 0) := "01111010";
---THE SYMBOLS
constant SPACE: std_logic_vector(7 downto 0) := "00100000";
constant SLASH: std_logic_vector(7 downto 0) := "00101111";
constant MINUS: std_logic_vector(7 downto 0) := "00101101";
constant EQUAL: std_logic_vector(7 downto 0) := "00111101";
constant PLUS : std_logic_vector(7 downto 0) := "00101011";
constant STAR : std_logic_vector(7 downto 0) := "00101010";
constant DOT : std_logic_vector(7 downto 0) := "00101110";
end LCD_GRAP;
©Copyright Reserved 27
VTU LAB MANUAL
1a.Write VHDL code to display messages on the given LCD accepting Hex key pad input data.
Aim: To Display the message on the LCD panel by accepting HEX key board data as input.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the LCD Display connector of the
VTU card1.
2. Make the connection between FRC4 of the FPGA board to the Key board connector of the
VTU card1.
3. Make the connection between FRC6 of the FPGA board to the Dip switch connector of the
VTU card1.
4. Connect the downloading cable and power supply to the FPGA board
5. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and
select the respective BIT file and click program.
VHDL CODING
Library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
USE WORK.LCD_GRAP.ALL;
entity HEXKEY_lcd is
port (
CLK: in STD_LOGIC; -- 16 MHz clock
RESET: in STD_LOGIC; -- master reset pin
lcd_rw : out std_logic;
lcd_select : out std_logic;
lcd_enable : out std_logic;
ROW: in STD_LOGIC_VECTOR(0 to 3); -- this are the row lines
lcd_data: out STD_LOGIC_VECTOR (7 downto 0); -- gives registered data output
COL: inout STD_LOGIC_VECTOR(0 to 3));
end HEXKEY_lcd;
©Copyright Reserved 28
VTU LAB MANUAL
-- Clear screen.
constant CLR: std_logic_vector(7 downto 0) := "00000001";
-- Display ON, without cursor.
constant DON: std_logic_vector(7 downto 0) := "00001100";
-- Function set for 8-bit data transfer and 2-line display
constant SET: std_logic_vector(7 downto 0) := "00111000";
--frequency divider
begin
R1 <= ROW(3) or ROW(2) or ROW(1) or ROW(0);
case CODE is
-- COL
-- ROW 0 0123
when "00010001" => KEY_VALUE <= ZERO;--key 0
when "00010010" => KEY_VALUE <= ONE;--key 1
when "00010100" => KEY_VALUE <= TWO;--key 2
when "00011000" => KEY_VALUE <= THREE;--key 3
-- ROW 1
when "00100001" => KEY_VALUE <= FOUR;--key 4
when "00100010" => KEY_VALUE <= FIVE;--key 5
when "00100100" => KEY_VALUE <= SIX;--key 6
when "00101000" => KEY_VALUE <= SEVEN;--key 7
-- ROW 2
when "01000001" => KEY_VALUE <= EIGHT;--key 8
when "01000010" => KEY_VALUE <= NINE;--key 9
when "01000100" => KEY_VALUE <= A;--key A
when "01001000" => KEY_VALUE <= B;--key B
-- ROW 3
when "10000001" => KEY_VALUE <= C;--key C
when "10000010" => KEY_VALUE <= D;--key D
when "10000100" => KEY_VALUE <= E;--key E
when "10001000" => KEY_VALUE <= F;--key F
when others => KEY_VALUE <= SPACE; -- just in case
end case;
end process; -- DECODER
---------------------------- END OF FSM1 (KEYPAD SCANNER) -----------------------------------------
©Copyright Reserved 31
VTU LAB MANUAL
IF COUNT=0 THEN
if c1="10001111" then
c1:="11000000";
elsif c1="11001111" then
c1:="10000000";
else
c1:=c1+'1';
end if;
END IF;
lcd_data <= c1 ;
lcd_select<='0';
if count=big_delay then
state<=putchar;
count:=0;
else
count:=count+1;
end if;
case c1 is
©Copyright Reserved 33
VTU LAB MANUAL
when "10000000" => lcd_data<= H ;--SIGLE LINE
when "10000001" => lcd_data<= E ;--SIGLE LINE
when "10000010" => lcd_data<= X ;--SIGLE LINE
when "10000011" => lcd_data<= SPACE ;--SIGLE LINE
when "10000100" => lcd_data<= SPACE ;--SIGLE LINE
when "10000101" => lcd_data<= K ;--SIGLE LINE
when "10000110" => lcd_data<= E ;--SIGLE LINE
when "10000111" => lcd_data<= Y ;--SIGLE LINE
when "10001000" => lcd_data<= B ;
when "10001001" => lcd_data<= O ;
when "10001010" => lcd_data<= A ;
when "10001011" => lcd_data<= R ;
when "10001100" => lcd_data<= D ;
when "10001101" => lcd_data<= SPACE ;
when "10001110" => lcd_data<= SPACE ;
when "10001111" => lcd_data<= SPACE;
lcd_select<='1';
if count=small_delay then
state<=location;
count:=0;
else
count:=count+1;
end if;
end case;
end if;
end process;
end HEXKEY_BEH;
©Copyright Reserved 34
VTU LAB MANUAL
=========================================================================
©Copyright Reserved 35
VTU LAB MANUAL
1b. Write VHDL code to display messages on the given seven segment display accepting Hex key
pad input data.
Aim: To Display the message on the Seven Segment Display by accepting HEX key pad input
Data.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the Seven Segment connector of
the VTU card1.
2. Make the connection between FRC4 of the FPGA board to the Key board connector of the
VTU card1.
3. Make the connection between FRC6 of the FPGA board to the Dip switch connector of the
VTU card1.
4. Connect the downloading cable and power supply to the FPGA board.
5. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and
select the respective BIT file and click program.
VHDL CODING
------------------------------------
--Code for simulating 16 keys using
--keyboard provided on spartan board
------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity key_40 is
Port ( scan_l : out std_logic_vector(3 downto 0);
read_l_in : in std_logic_vector(3 downto 0);
clk : in std_logic;
disp_cnt: out std_logic_vector(3 downto 0);
disp : out std_logic_vector(6 downto 0));
end key_40;
begin
---------------------------
--clock division to 4kHz
--------------------------
process(clk)
begin
if clk='1' and clk'event then
clk_div <= clk_div + '1';
end if;
end process;
---------------------------
clk_4k <= clk_div(11);
---------------------------
-- 2 bit counter
--------------------------
process(clk_4k)
begin
if clk_4k = '1' and clk_4k'event then
cnt_2bit <= cnt_2bit + '1';
end if;
end process;
--------------------------
-- scanning the lines
--------------------------
process(cnt_2bit)
begin
case cnt_2bit is
when "00" => scan_l_sig <= "0001";
when "01" => scan_l_sig <= "0010";
when "10" => scan_l_sig <= "0100";
when "11" => scan_l_sig <= "1000";
when others => null;
end case;
end process;
------------------------------
--read_l <= not read_l_in;
--scan_l <= not scan_l_sig;
read_l <= read_l_in;
scan_l <= scan_l_sig;
disp_cnt <= "1110";
--reading the lines
-------------------------------
©Copyright Reserved 37
VTU LAB MANUAL
process(scan_l_sig,read_l)
begin
case scan_l_sig is
when "0001" => case read_l is
when "0001" => disp1 <= "1111110";
when "0010" => disp1 <= "0110011";
when "0100" => disp1 <= "1111111";
when "1000" => disp1 <= "1001110";
when others=> disp1 <= "0000000";
end case;
©Copyright Reserved 38
VTU LAB MANUAL
-------------------------------------------------------------------------------------------------------------------------------
UCF file(User constraint file)
=========================================================================
©Copyright Reserved 39
VTU LAB MANUAL
2a. Write a VHDL code to accept 8 channel Analog signal, Temperature sensors and display the
data on LCD panel or Seven segment display.
Aim: To accept 8 channel Analog signal, and display the data on LCD panel display.
.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the LCD Display connector of
the VTU card1.
2. Make the connection between FRC10 of the FPGA board to the ADC connector of the
VTU card1.
3. Make the connection between FRC6 of the FPGA board to the Dip switch connector of the
VTU card1.
5. Connect the downloading cable and power supply to the FPGA board.
6. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and
select the respective BIT file and click program.
VHDL CODING
Library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
USE WORK.LCD_GRAP.ALL;
Library UNISIM;
use UNISIM.vcomponents.all;
entity ADC_lcd is
port ( CLK: in STD_LOGIC; -- 4 MHz clock
RESET: in STD_LOGIC; -- master reset pin
intr: in std_logic;
adc_out: in std_logic_vector(7 downto 0);
cs,rd,wr:out std_logic;
lcd_rw : out std_logic;
lcd_select : out std_logic;
lcd_enable : out std_logic;
©Copyright Reserved 40
VTU LAB MANUAL
lcd_data: out STD_LOGIC_VECTOR (7 downto 0)); -- gives registered data output
end ADC_lcd;
-- Clear screen.
constant CLR: std_logic_vector(7 downto 0) := "00000001";
-- Display ON, without cursor.
constant DON: std_logic_vector(7 downto 0) := "00001100";
-- Function set for 8-bit data transfer and 2-line display
constant SET: std_logic_vector(7 downto 0) := "00111000";
--frequency divider
signal counter : std_logic_vector(18 downto 0);
signal clk_div :std_logic;
IBUF_inst : IBUF
-- Edit the following generic to specify the I/O standard for this port.
generic map (
IOSTANDARD => "LVCMOS25")
port map (
O => ntr, -- Buffer output
I => intr -- Buffer input (connect directly to top-level port));
process(clk)
begin
if clk='1' and clk'event then
counter<=counter+'1';
end if;
end process;
clk_div<=counter(7);
cs <='0';
wr <=ntr;
digital_data1 <= adc_out ;
rd <='0';
digital_data<=CONV_INTEGER(digital_data1) ;
process(digital_data)
©Copyright Reserved 41
VTU LAB MANUAL
begin
case (digital_data) is
when 0 to 100 => data1 <= one ; data2 <= nine ;
when 101 to 110 => data1 <= two ; data2 <= zero ;
when 111 to 120 => data1 <= two ; data2 <= one ;
when 121 to 130 => data1 <= two ; data2 <= two ;
when 131 to 140 => data1 <= two ; data2 <= three ;
when 141 to 150 => data1 <= two ; data2 <= four ;
when 151 to 160 => data1 <= two ; data2 <= five ;
when 161 to 170 => data1 <= two ; data2 <= six ;
when 171 to 180 => data1 <= two ; data2 <= seven ;
when 181 to 190 => data1 <= two ; data2 <= eight ;
when 191 to 200 => data1 <= two ; data2 <= nine ;
when 201 to 205 => data1 <= three ; data2 <= zero ;
when 206 to 210 => data1 <= three ; data2 <= one ;
when 211 to 215 => data1 <= three ; data2 <= two ;
when 216 to 220 => data1 <= three ; data2 <= three ;
when 221 to 225 => data1 <= three ; data2 <= four ;
when 226 to 230 => data1 <= three ; data2 <= five ;
when 231 to 235 => data1 <= three ; data2 <= six ;
when 236 to 240 => data1 <= three ; data2 <= seven ;
when 241 to 245 => data1 <= three ; data2 <= eight ;
when 246 to 250 => data1 <= three ; data2 <= nine ;
when others => data1 <= four ; data2 <= zero ;
end case;
end process;
lcd_rw<='0';
process (clk_div,rEsEt)
variable count: integer range 0 to big_delay;
variable c1 : std_logic_vector(7 downto 0);
begin
IF rEsEt = '1' THEN
state<=initial;
count:=0;
lcd_enable<='0';
lcd_select<='0';
c1 := "01111111";
elsIF clk_div'EVENT AND clk_div = '1' THEN
case state is
IF COUNT=0 THEN
if c1="10001111" then
c1:="10000000";
else
©Copyright Reserved 43
VTU LAB MANUAL
c1:=c1+'1';
end if;
END IF;
lcd_data <= c1 ;
lcd_select<='0';
if count=big_delay then
state<=putchar;
count:=0; else
count:=count+1;
end if;
©Copyright Reserved 45
VTU LAB MANUAL
2b. Write a VHDL code to accept 8 channel Analog signal, Temperature sensors and display the
data on LCD panel or Seven segment display.
Aim: To accept Temperature sensors, and display the data on LCD panel display.
.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the LCD Display connector of
the VTU card1.
2. Make the connection between FRC10 of the FPGA board to the ADC connector of the
VTU card1.
3. Make the connection between FRC6 of the FPGA board to the Dip switch connector of the
VTU card1.
5. Connect the downloading cable and power supply to the FPGA board.
6. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and
select the respective BIT file and click program.
VHDL CODING
Library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
USE WORK.LCD_GRAP.ALL;
Library UNISIM;
use UNISIM.vcomponents.all;
entity temp_lcd is
port ( CLK: in STD_LOGIC; -- 4 MHz clock
RESET: in STD_LOGIC; -- master reset pin
intr: in std_logic;
adc_out: in std_logic_vector(7 downto 0);
cs,rd,wr:out std_logic;
lcd_rw : out std_logic;
lcd_select : out std_logic;
lcd_enable : out std_logic;
©Copyright Reserved 46
VTU LAB MANUAL
lcd_data: out STD_LOGIC_VECTOR (7 downto 0)); -- gives registered data output
end temp_lcd;
--frequency divider
signal counter : std_logic_vector(18 downto 0);
signal clk_div :std_logic;
IBUF_inst : IBUF
-- Edit the following generic to specify the I/O standard for this port.
generic map (
IOSTANDARD => "LVCMOS25")
port map (
O => ntr, -- Buffer output
I => intr -- Buffer input (connect directly to top-level port));
process(clk)
begin
if clk='1' and clk'event then
counter<=counter+'1';
end if;
end process;
clk_div<=counter(7);
cs <='0';
wr <=ntr;
digital_data1 <= adc_out ;
rd <='0';
digital_data<=CONV_INTEGER(digital_data1) ;
process(digital_data)
begin
©Copyright Reserved 47
VTU LAB MANUAL
case (digital_data) is
when 0 to 60 => data1 <= zero ; data2 <= nine ;
when 61 to 65 => data1 <= one ; data2 <= zero ;
when 66 to 70 => data1 <= one ; data2 <= one ;
when 71 to 75 => data1 <= one ; data2 <= two ;
when 76 to 80 => data1 <= one ; data2 <= three ;
when 81 to 85 => data1 <= one ; data2 <= four ;
when 86 to 90 => data1 <= one ; data2 <= five ;
when 91 to 95 => data1 <= one; data2 <= six ;
when 96 to 100 => data1 <= one ; data2 <= seven ;
when 101 to 105 => data1 <= one ; data2 <= eight ;
when 106 to 110 => data1 <= one ; data2 <= nine ;
when 111 to 115 => data1 <= two ; data2 <= zero ;
when 116 to 120 => data1 <= two ; data2 <= one ;
when 121 to 125 => data1 <= two ; data2 <= two ;
when 126 to 130 => data1 <= two ; data2 <= three ;
when 131 to 135 => data1 <= two ; data2 <= four ;
when 136 to 140 => data1 <= two ; data2 <= five ;
when 141 to 145 => data1 <= two ; data2 <= six ;
when 146 to 150 => data1 <= two ; data2 <= seven ;
when 151 to 155 => data1 <= two ; data2 <= eight ;
when 156 to 160 => data1 <= two ; data2 <= nine ;
when 161 to 165 => data1 <= three ; data2 <= zero ;
when 166 to 170 => data1 <= three ; data2 <= two ;
when 171 to 175 => data1 <= three ; data2 <= three ;
when 176 to 180 => data1 <= three ; data2 <= four ;
when 181 to 185 => data1 <= three ; data2 <= five ;
when 186 to 190 => data1 <= three ; data2 <= six ;
when 191 to 195 => data1 <= three ; data2 <= seven ;
when 196 to 200 => data1 <= three ; data2 <= eight ;
when 201 to 205 => data1 <= three ; data2 <= nine ;
when 206 to 210 => data1 <= four ; data2 <= zero ;
when 211 to 214 => data1 <= four ; data2 <= one ;
when 215 to 219 => data1 <= four ; data2 <= two ;
when 220 to 224 => data1 <= four ; data2 <= three ;
when 225 to 229 => data1 <= four ; data2 <= four ;
when 230 to 234 => data1 <= four ; data2 <= five;
when 235 to 239 => data1 <= four ; data2 <= six ;
when 240 to 244 => data1 <= four ; data2 <= seven ;
when 245 to 249 => data1 <= four ; data2 <= eight;
when 250 to 255 => data1 <= four; data2 <= nine ;
when others => data1 <= five ; data2 <= zero ;
end case;
end process;
lcd_rw<='0';
process (clk_div,rEsEt)
variable count: integer range 0 to big_delay;
variable c1 : std_logic_vector(7 downto 0);
begin
©Copyright Reserved 48
VTU LAB MANUAL
IF rEsEt = '1' THEN
state<=initial;
count:=0;
lcd_enable<='0';
lcd_select<='0';
c1 := "01111111";
elsIF clk_div'EVENT AND clk_div = '1' THEN
case state is
WHEN initial => -- to set the function
if count=reg_setup then
lcd_enable<='1';
else
lcd_enable<='0';
end if;
lcd_data<=SET;
lcd_select<='0';
if count=small_delay then
state<=display;
count:=0;
else
count:=count+1;
end if;
IF COUNT=0 THEN
if c1="10001111" then
c1:="10000000";
else
c1:=c1+'1';
end if;
END IF;
lcd_data <= c1 ;
lcd_select<='0';
if count=big_delay then
state<=putchar;
count:=0;
else
count:=count+1;
end if;
case c1 is
when "10000000" => lcd_data<= T ;
when "10000001" => lcd_data<= E ;
when "10000010" => lcd_data<= M ;
when "10000011" => lcd_data<= P ;
when "10000100" => lcd_data<= E ;
when "10000101" => lcd_data<= R ;
when "10000110" => lcd_data<= A ;
when "10000111" => lcd_data<= T ;
when "10001000" => lcd_data<= U ;
when "10001001" => lcd_data<= R ;
when "10001010" => lcd_data<= E ;
when "10001011" => lcd_data<= SPACE ;
when "10001100" => lcd_data<= EQUAL ;
when "10001101" => lcd_data<= data1 ;
when "10001110" => lcd_data<= data2 ;
©Copyright Reserved 50
VTU LAB MANUAL
when "10001111" => lcd_data<= C;
when "11000000" => lcd_data<= space ;
when "11000001" => lcd_data<= space ;
when "11000010" => lcd_data<= space;
when "11000011" => lcd_data<= space ;
when "11000100" => lcd_data<= space ;
when "11000101" => lcd_data<= space ;
when "11000110" => lcd_data<= space ;
when "11000111" => lcd_data<= space ;
when "11001000" => lcd_data<= space;
when "11001001" => lcd_data<= space ;
when "11001010" => lcd_data<= space ;
when "11001011" => lcd_data<= space ;
when "11001100" => lcd_data<= space ;
when "11001101" => lcd_data<= space ;
when "11001110" => lcd_data<= space ;
when "11001111" => lcd_data<= space;
WHEN OTHERS => NULL;
end case;
lcd_select<='1';
if count=small_delay then
state<=location;
count:=0;
else
count:=count+1;
end if;
end case;
end if;
end process;
end temp_BEH;
©Copyright Reserved 51
VTU LAB MANUAL
=========================================================================
Device utilization summary:
---------------------------
©Copyright Reserved 52
VTU LAB MANUAL
2. Make the connection between FRC1 of the FPGA board to the Keyboard connector of the
VTU card1.
3. Make the connection between FRC6 of the FPGA board to the Dip switch connector of the
VTU card1.
4. Connect the downloading cable and power supply to the FPGA board.
5. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and
select the respective BIT file and click program.
VHDL CODING
Library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
USE WORK.LCD_GRAP.ALL;
entity elevator is
generic(bits : integer := 8 ); -- number of bits used for duty cycle.
-- Also determines pwm period.
port ( CLK: in STD_LOGIC; -- 4 MHz clock
RESET,EN: in STD_LOGIC; -- master reset pin
lcd_rw : out std_logic;
pwm : out std_logic_VECTOR(1 DOWNTO 0);
lcd_select : out std_logic;
lcd_enable : out std_logic;
ROW: in STD_LOGIC_VECTOR(0 to 3); -- this are the row lines
lcd_data: out STD_LOGIC_VECTOR (7 downto 0); -- gives registered data output
COL: inout STD_LOGIC_VECTOR(0 to 3));
end elevator;
©Copyright Reserved 53
VTU LAB MANUAL
architecture rtl of elevator is
signal counter : std_logic_vector(bits - 1 downto 0):="00000000";
type KEYPAD_STATE_TYPE is (WAIT_R_0, C3, C2, C1, C0, FOUND, SAMPLE, WAIT_R_1);
-- state names
TYPE STATE_TYPE IS (initial,display,clear,location,putchar);
SIGNAL state,next_state: STATE_TYPE;
-- Clear screen.
constant CLR: std_logic_vector(7 downto 0) := "00000001";
-- Display ON, without cursor.
constant DON: std_logic_vector(7 downto 0) := "00001100";
-- Function set for 8-bit data transfer and 2-line display
constant SET: std_logic_vector(7 downto 0) := "00111000";
--frequency divider
signal CS, NS: KEYPAD_STATE_TYPE; -- signals for current and next states
signal duty_cycle,duty_cycle1 : std_logic_vector(bits - 1 downto 0);
signal DIV_REG: STD_LOGIC_VECTOR (22 downto 0); -- clock divide register
signal DCLK,DDCLK: STD_LOGIC; -- this has the divided clock.
signal COL_REG_VALUE: STD_LOGIC_VECTOR (0 to 3);
signal R1,CLK_D,START,STOP: STD_LOGIC; -- row detection signal
signal KEY_VALUE1,FLOOR,KEY_VALUE: integer range 0 to 15;
signal DATA,data1,FLOOR_NUM: STD_LOGIC_VECTOR (7 downto 0);
signal TEMP1,TEMP2,TEMP3,TEMP4: STD_LOGIC_VECTOR (7 downto 0);
signal TEMP5,TEMP6,TEMP7,TEMP8: STD_LOGIC_VECTOR (7 downto 0);
begin
--CLK_OUT <= DCLK;
R1 <= ROW(3) or ROW(2) or ROW(1) or ROW(0);
---------------------------- BEGINING OF FSM1 (KEYPAD SCANNER) ------------------------------------
SYNC_PROC: process (DCLK, RESET, KEY_VALUE) -- This is the synchronous part
begin
if (RESET = '0') then -- you must have a reset for fsm to synthesize properly
CS <= WAIT_R_0;
elsif (DCLK'event and DCLK = '1') then
CS <= NS;
end if; end process;
COMB_PROC: process (CS, R1, COL_REG_VALUE) -- This is the combinational part
begin
case CS is
when WAIT_R_0 => -- waits till a button is pressed
COL <= "1111"; -- keep all columns activated
if R1 = '1' then -- a button was pressed. but which one?
NS <= C3; -- let's find out
else
©Copyright Reserved 54
VTU LAB MANUAL
NS <= WAIT_R_0;
end if;
---------------------------------------------------------------------------------------------------
when C3 => --
COL <= "0001"; -- activate column 3
if R1 = '0' then -- this means button was not in column 3
NS <= C2; -- so check if it was in column 2
Else NS <= FOUND; -- button was in column 3
end if;
---------------------------------------------------------------------------------------------------
when C2 => --
COL <= "0010"; -- activate column 2
if R1 = '0' then -- this means button was not in column 2
NS <= C1; -- so check if it was in column 1
else
NS <= FOUND; -- button was in column 2
end if;
---------------------------------------------------------------------------------------------------
when C1 => --
COL <= "0100"; -- activate column 1
if R1 = '0' then -- this means button was not in column 1
NS <= C0; -- so check if it was in column 0
else
NS <= FOUND; -- button was in column 1
end if;
---------------------------------------------------------------------------------------------------
when C0 => --
COL <= "1000"; -- activate column 0
if R1 = '0' then -- this means button was not in column 0 ??
NS <= WAIT_R_0; -- so the button must have been depressed fast
else
NS <= FOUND; -- button was in column 3
end if;
---------------------------------------------------------------------------------------------------
when FOUND => --
COL <= COL_REG_VALUE;
if R1 = '0' then -- this means button is depressed
NS <= WAIT_R_0; -- so go back to initial state
else
NS <= SAMPLE; -- otherwise write the key value to DATA register
end if;
---------------------------------------------------------------------------------------------------
when SAMPLE => -- this state will generate a signal with one clock period for sampling
COL <= COL_REG_VALUE;
NS <= WAIT_R_1; -- otherwise wait till button is pressed
---------------------------------------------------------------------------------------------------
when WAIT_R_1 => --
COL <= COL_REG_VALUE;
if R1 = '0' then -- this means button was depressed
©Copyright Reserved 55
VTU LAB MANUAL
NS <= WAIT_R_0; -- so go back to initial state
else
NS <= WAIT_R_1; -- otherwise wait till button is pressed
end if;
---------------------------------------------------------------------------------------------------
end case;
end process;
---------------------------------------------------------------------------------------------------
WRITE_DATA: process (DCLK, CS, KEY_VALUE) -- write valid data to register
begin
if DCLK'event and DCLK = '0' then -- on the falling edge
if CS = FOUND then
KEY_VALUE <= KEY_VALUE1;
end if;
end if;
end process; -- WRITE_DATA
---------------------------------------------------------------------------------------------------
COL_REG: process (DCLK, CS, COL) -- this is the column value register
begin
if (DCLK'event and DCLK = '0') then -- register the COL value on the falling edge
if (CS = C3 or CS = C2 or CS = C1 or CS = C0) then -- provided we're in states C3 thru C0 only
COL_REG_VALUE <= COL; -- otherwise the column value is not valid
end if;
end if;
end process; -- COL_REG
---------------------------------------------------------------------------------------------------
DECODER: process(ROW, COL_REG_VALUE) -- decodes binary value of pressed key from row and
column
variable CODE: STD_LOGIC_VECTOR (0 to 7);
begin
CODE := (ROW & COL_REG_VALUE);
case CODE is
-- COL
-- ROW 0 0123
when "00010001" => KEY_VALUE1 <= 0;
when "00010010" => KEY_VALUE1 <= 1;
when "00010100" => KEY_VALUE1 <= 2;
when "00011000" => KEY_VALUE1 <= 3;
-- ROW 1
when "00100001" => KEY_VALUE1 <= 4;
when "00100010" => KEY_VALUE1 <= 5;
when "00100100" => KEY_VALUE1 <= 6;
when "00101000" => KEY_VALUE1 <= 7;
-- ROW 2
when "01000001" => KEY_VALUE1 <= 8;
when "01000010" => KEY_VALUE1 <= 9;
when "01000100" => KEY_VALUE1 <= 10;
when "01001000" => KEY_VALUE1 <= 11;
-- ROW 3
©Copyright Reserved 56
VTU LAB MANUAL
when "10000001" => KEY_VALUE1 <= 12;
when "10000010" => KEY_VALUE1 <= 13;
when "10000100" => KEY_VALUE1 <= 14;
when "10001000" => KEY_VALUE1 <= 15;
when others => KEY_VALUE1 <= 0;
end case;
end process; -- DECODER
---------------------------- END OF FSM1 (KEYPAD SCANNER) -----------------------------------------
-- select the appropriate lines for setting frequency
CLK_DIV: process (CLK, DIV_REG) -- clock divider
begin
if (CLK'event and CLK='1') then
DIV_REG <= DIV_REG + 1;
end if;
end process;
DCLK <= div_reg(8);
DDCLK<=DIV_REG(10);
CLK_D<=DIV_REG(22);
---------------------------- END OF CLOCK DIVIDER -------------------------------------------------
lcd_rw<='0';
process (DDclk,rEsEt)
variable count: integer range 0 to big_delay;
variable c1 : std_logic_vector(7 downto 0);
begin
IF rEsEt = '0' THEN
state<=initial;
count:=0;
lcd_enable<='0';
lcd_select<='0';
c1 := "01111111";
elsIF DDclk'EVENT AND DDclk = '1' THEN
case state is
WHEN initial => -- to set the function
if count=reg_setup then
lcd_enable<='1';
else lcd_enable<='0';
end if;
lcd_data<=SET;
lcd_select<='0';
if count=small_delay then
state<=display;
count:=0;
else count:=count+1;
end if;
IF COUNT=0 THEN
if c1="10001111" then
c1:="11000000";
elsif c1="11001111" then
c1:="10000000";
else c1:=c1+'1';
end if;
END IF;
lcd_select<='1';
if count=small_delay then
state<=location;
count:=0;
else count:=count+1;
end if; end case; end if; end process;
PROCESS(CLK_D,RESET)
VARIABLE COU : STD_LOGIC_VECTOR(1 DOWNTO 0);
VARIABLE START,STOP: STD_LOGIC; -- row detection signal
BEGIN
IF RESET='0' THEN
COU:="00";
TEMP1 <= L ;
©Copyright Reserved 59
VTU LAB MANUAL
TEMP2 <= I ;
TEMP3 <= F ;
TEMP4 <= T ;
TEMP5 <= I ;
TEMP6 <= D ;
TEMP7 <= L ;
TEMP8 <= E ;
FLOOR_NUM <= ZERO ;
ELSIF RISING_EDGE(CLK_D) THEN
CASE KEY_VALUE IS
WHEN 0 => FLOOR_NUM <= ZERO ;
FLOOR <=0;
WHEN 1 => FLOOR_NUM <= ONE ;
FLOOR <=1;
WHEN 2 => FLOOR_NUM <= TWO ;
FLOOR <=2;
WHEN 3 => FLOOR_NUM <= THREE ;
FLOOR <=3;
WHEN 4 =>
TEMP1 <= D ;
TEMP2 <= O ;
TEMP3 <= O ;
TEMP4 <= R ;
TEMP5 <= O ;
TEMP6 <= P ;
TEMP7 <= E ;
TEMP8 <= N ;
WHEN 5 =>
TEMP1 <= D ;
TEMP2 <= O ;
TEMP3 <= O ;
TEMP4 <= R ;
TEMP5 <= C ;
TEMP6 <= L ;
TEMP7 <= O ;
TEMP8 <= S ;
WHEN 6 =>
START:='1';
STOP:='0';
WHEN 7 =>
STOP:='1';
START:='0';
WHEN OTHERS =>
TEMP1 <= I ;
TEMP2 <= D ;
TEMP3 <= L ;
TEMP4 <= E ;
TEMP5 <= K ;
TEMP6 <= E ;
©Copyright Reserved 60
VTU LAB MANUAL
TEMP7 <= Y ;
TEMP8 <= SPACE ;
END CASE;
IF START='1' THEN
IF COU=FLOOR THEN
START := '0';
COU:=COU;
TEMP7 <= "001100" & COU ;
ELSIF COU<=FLOOR THEN
COU:=COU + '1';
TEMP1 <= U ;
TEMP2 <= P ;
TEMP3 <= SPACE ;
TEMP4 <= SPACE ;
TEMP5 <= SPACE ;
TEMP6 <= "01111110" ;
TEMP7 <= "001100" & COU ;
TEMP8 <= SPACE ;
ELSIF COU>=FLOOR THEN
COU:=COU-'1';
TEMP1 <= D ;
TEMP2 <= O ;
TEMP3 <= W ;
TEMP4 <= N ;
TEMP5 <= SPACE ;
TEMP6 <= "01111111" ;
TEMP7 <= "001100" & COU ;
TEMP8 <= SPACE ;
END IF; END IF; END IF;
END PROCESS;
end rtl;
©Copyright Reserved 61
VTU LAB MANUAL
=========================================================================
Device utilization summary:
---------------------------
Selected Device : 2s100tq144-5
©Copyright Reserved 62
VTU LAB MANUAL
2. Make the connection between FRC1 of the FPGA board to the Dip switch connector of the
VTU card2.
3. Connect the downloading cable and power supply to the FPGA board.
4. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and
select the respective BIT file and click program.
5. Make the reset switch on (active low) and analyze the data.
VHDL CODING
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity extlight is
Port ( cntrl1,cntrl2 : in std_logic;
light : out std_logic);
end extlight;
2. Make the connection between FRC7 of the FPGA board to the Keyboard connector of the
VTU card2.
3. Make the connection between FRC1 of the FPGA board to the Dip switch connector of the
VTU card2.
4. Connect the downloading cable and power supply to the FPGA board.
5. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and
select the respective BIT file and click program.
VHDL CODING
Library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.all;
Library UNISIM;
use UNISIM.vcomponents.all;
entity dcmotor is
generic(bits : integer := 8 );-- number of bits used for duty cycle.
-- Also determines pwm period.
port ( CLK: in STD_LOGIC; -- 4 MHz clock
RESET,EN: in STD_LOGIC; -- master reset pin
pwm : out std_logic_VECTOR(1 DOWNTO 0);
rly: out std_logic;
ROW: in STD_LOGIC_VECTOR(0 to 3) ); -- this are the row lines
end dcmotor;
begin
-- select the appropriate lines for setting frequency
CLK_DIV: process (CLK, DIV_REG) -- clock divider
begin
if (CLK'event and CLK='1') then
DIV_REG <= DIV_REG + 1;
end if;
end process;
DDCLK<=DIV_REG(12);
---------------------------- END OF CLOCK DIVIDER -------------------------------------------------
tick <= row(0) and row(1) and row(2) and row(3);
process(tick)
begin
if falling_edge(tick) then
case row is
when "1110" => duty_cycle <= 255 ; --motor speed 1
when "1101" => duty_cycle <= 200 ; --motor speed 2
when "1011" => duty_cycle <= 150 ; --motor speed 3
when "0111" => duty_cycle <= 100 ; --motor speed 4
when others => duty_cycle <= 100;
end case;
end if;
end process;
process(DDCLK, reset)
begin
if reset = '0' then
counter <= (others => '0');
PWM<="01";
elsif (DDCLK'event and DDCLK = '1') then
counter <= counter + 1;
if counter >= duty_cycle then
pwm(1) <= '0';
else
pwm(1) <= '1';
end if; end if;
end process;
-- rly<='1'; --motor direction control- clock wise
rly<='0';--motor direction control- counter clock wise
end dcmotor1;
©Copyright Reserved 65
VTU LAB MANUAL
=========================================================================
Device utilization summary:
---------------------------
Selected Device : 2s100tq144-5
©Copyright Reserved 66
VTU LAB MANUAL
2. Make the connection between FRC7 of the FPGA board to the Keyboard connector of the
VTU card2.
3. Make the connection between FRC1 of the FPGA board to the Dip switch connector of the
VTU card2.
4. Connect the downloading cable and power supply to the FPGA board.
5. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and
select the respective BIT file and click program.
VHDL CODING
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity STEPPER is
Port ( dout : out std_logic_vector(3 downto 0);
clk,reset : in std_logic);
end STEPPER;
begin
process(clk)
begin
if rising_edge (clk) then
clk_div <= clk_div + '1';
©Copyright Reserved 67
VTU LAB MANUAL
end if;
end process;
=========================================================================
©Copyright Reserved 68
VTU LAB MANUAL
6.a. Write a VHDL code to generate Sine waveforms using DAC change the frequency and
amplitude.
Aim: To generate Sine wave using DAC change the frequency and amplitude.
.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the DAC connector of
the VTU card2.
2. Make the connection between FRC1 of the FPGA board to the Dip switch connector of the
VTU card2.
3. Connect the downloading cable and power supply to the FPGA board.
4. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and
select the respective BIT file and click program.
5. Make the reset switch on (active low) and analyze the data.
VHDL CODING
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity digital_sine_wave is
Port ( clk : in std_logic;
rst : in std_logic;
dac_out : out std_logic_vector(0 to 7));
end digital_sine_wave ;
process(temp(3))
©Copyright Reserved 69
VTU LAB MANUAL
begin
if rst='1' then
counter <= "00000000";
elsif rising_edge(temp(3)) then
if counter<255 and en='0' then
counter <= counter + 31 ;
en<='0';
elsif counter=0 then
en<='0';
else
en<='1';
counter <= counter - 31;
end if;
end if;
end process;
dac_out <=counter;
end Behavioral;
©Copyright Reserved 70
VTU LAB MANUAL
6.b. Write a VHDL code to generate Square waveforms using DAC change the frequency and
amplitude.
Aim: To generate Square wave using DAC change the frequency and amplitude.
.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the DAC connector of
the VTU card2.
2. Make the connection between FRC1 of the FPGA board to the Dip switch connector of the
VTU card2.
3. Connect the downloading cable and power supply to the FPGA board.
4. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and
select the respective BIT file and click program.
5. Make the reset switch on (active low) and analyze the data.
VHDL CODING
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity square_wave is
Port ( clk : in std_logic;
rst : in std_logic;
dac_out : out std_logic_vector(0 to 7));
end square_wave;
©Copyright Reserved 71
VTU LAB MANUAL
process(temp(3))
begin
if rst='1' then
counter <= "00000000";
elsif rising_edge(temp(3)) then
if counter<255 and en='0' then
counter <= counter + 1 ;
en<='0';
dac_out <="00000000";
elsif counter=0 then
en<='0';
else
en<='1';
counter <= counter-1;
dac_out <="11111111";
end if;
end if;
end process;
end Behavioral;
©Copyright Reserved 72
VTU LAB MANUAL
6.c. Write a VHDL code to generate Traingular waveforms using DAC change the frequency and
amplitude.
Aim: To generate Triangular wave using DAC change the frequency and amplitude.
.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the DAC connector of
the VTU card2.
2. Make the connection between FRC1 of the FPGA board to the Dip switch connector of the
VTU card2.
3. Connect the downloading cable and power supply to the FPGA board.
4. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and
select the respective BIT file and click program.
5. Make the reset switch on (active low) and analyze the data.
VHDL CODING
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity triangular_wave is
Port ( clk : in std_logic;
rst : in std_logic;
dac_out : out std_logic_vector(0 to 7));
end triangular_wave ;
process(temp(3))
begin
©Copyright Reserved 73
VTU LAB MANUAL
if rst='1' then
counter <= "000000000";
elsif rising_edge(temp(3)) then
=========================================================================
©Copyright Reserved 74
VTU LAB MANUAL
6.d. Write a VHDL code to generate Ramp waveforms using DAC change the frequency and
amplitude.
Aim: To generate Ramp wave using DAC change the frequency and amplitude.
.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the DAC connector of
the VTU card2.
2. Make the connection between FRC1 of the FPGA board to the Dip switch connector of the
VTU card2.
3. Connect the downloading cable and power supply to the FPGA board.
4. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and
select the respective BIT file and click program.
5. Make the reset switch on (active low) and analyze the data.
VHDL CODING
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ramp_wave is
Port ( clk : in std_logic;
rst : in std_logic;
dac_out : out std_logic_vector(0 to 7));
end ramp_wave;
©Copyright Reserved 75
VTU LAB MANUAL
process(temp(3))
begin
if rst='1' then
counter <= "00000000";
elsif rising_edge(temp(3)) then
counter <= counter + 15 ;
end if;
end process;
dac_out <=counter;
end Behavioral;
=========================================================================
©Copyright Reserved 76
VTU LAB MANUAL
6.e. Write a VHDL code to generate Sawtooth waveforms using DAC change the frequency and
amplitude.
Aim: To generate Sawtooth wave using DAC change the frequency and amplitude.
.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the DAC connector of
the VTU card2.
2. Make the connection between FRC1 of the FPGA board to the Dip switch connector of the
VTU card2.
3. Connect the downloading cable and power supply to the FPGA board.
4. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and
select the respective BIT file and click program.
5. Make the reset switch on (active low) and analyze the data.
VHDL CODING
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity swatooth_wave is
Port ( clk : in std_logic;
rst : in std_logic;
dac_out : out std_logic_vector(0 to 7));
end swatooth_wave;
©Copyright Reserved 77
VTU LAB MANUAL
process(temp(3))
begin
if rst='1' then
counter <= "00000000";
elsif rising_edge(temp(3)) then
counter <= counter + 1 ;
end if;
end process;
dac_out <=counter;
end Behavioral;
=========================================================================
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
©Copyright Reserved 78