Mtech Vlsi Lab Manual
Mtech Vlsi Lab Manual
LAB MANUAL
List of Experiments
2
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
INDEX
3
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
Exp. No. 1
AIM:
Implementation of 8 bit ALU in FPGA/CPLD.
Algorithm:
1. Start.
2. Declare the input and output ports.
3. Perform the calculations and assign the result to output port.
4. Create the test bench waveform.
5. Simulate and verify the output.
6. Stop.
7. Implement of FPGA kit.
Verilog Module:
module alu8(z,read,data,s);
output reg [7:0]z;
input[7:0]data;
input read;
input[1:0]s;
reg[7:0]y[1:0];
integer i;
always@(data or s)
begin
y[read]=data;
case(s)
2'b00:z=y[0]&y[1];
2'b01:z=y[0]|y[1];
2'b10:z=y[0]^y[1];
2'b11:z=y[0]-y[1];
endcase
end
endmodule
4
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
Output waveform
RTL SCHEMATIC
5
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
6
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
7
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
Exp. No. 2
AIM:
Implementation of 4 bit sliced processor in FPGA/CPLD.
Algorithm:
1.Start.
2.Declare the input and output ports.
3.Perform the calculations and assign the result to output port.
4.Create the test bench waveform.
5.Simulate and verify the output.
6.Stop.
7.Implement of FPGA kit.
VHDL Module
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity slicealu is
Port ( aa : in STD_LOGIC_VECTOR (7 downto 0);
ab : in STD_LOGIC_VECTOR (7 downto 0);
c : in STD_LOGIC;
operation : in STD_LOGIC_VECTOR (1 downto 0);
ssum : out STD_LOGIC_VECTOR (15 downto 0));
end slicealu;
architecture arcf_slicealu of slicealu is
component slice1alu is
Port ( aa : in STD_LOGIC_VECTOR (3 downto 0);
ab : in STD_LOGIC_VECTOR (3 downto 0);
c : in STD_LOGIC;
operation : in STD_LOGIC_VECTOR (1 downto 0);
ssum : out STD_LOGIC_VECTOR (7 downto 0));
end component;
component slice2alu is
8
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity slice1alu is
9
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
sum(4):=cout;
return sum;
end;
OUTPUT WAVEFORM
10
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
RTL SCHEMATIC
11
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
Exp. No. 3
AIM:
Implementation of elevator controller using embedded microcontroller.
Tools used: Basic Microcontroller kit, Interface Elevator kit VBMB 022
Steps:
Program:
12
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
13
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
14
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
4165 30 8D FD Jnb 8D,4165 0FFFF-(16 bit timer value)+1; monitor timer flag 0
4168 C2 8C Clr 8C 1 stop the timer0
416A C2 8D Clr tf0 8D 1 clear the flag0
416C 22 ret 1 stop the timer0
15
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
Exp. No. 4
AIM:
Implementation of alarm clock controller using embedded microcontroller.
Steps:
1. Open MPLAB IDE on your system.
2. Select device. PIC 16f877A.
3. Select CCS C compiler. Select language tool suite.(CCS C Compiler (ccsc.exe))
4. Create project using project wizard. Chose project>project wizard.
5. Give project name and directory.
6. Create new file and save as (file name.c)
7. Add file to project by right clicking source file.
8. Then Go for compilation. (project>compile F10)
9. Check the output window and simulation. If any error will be there, it will show in
output window.
10. Got to debugger>settings. See the output will come.
11. Open PIC ISP.
12. Select COM port and download file name.hex.GO for download. (While
downloading switch should be in programming mode.)
13. Download successful.
14. After that switch position is changed to exec mode and then reset the CPU code.
Code will be executed.
#include <16F877A.H>
#use delay(clock=20000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)
#use I2C(MASTER,sda=PIN_C4,scl=PIN_C3)
unsigned int time[]={0x30,0x55,0x12};
unsigned int readtime[0x03];
unsigned long int hour,second,minute;
16
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
int i,j;
void set_rtc_time()
{
for (i=2;i<=4;i++)
{
i2c_start();
i2c_write(0xa0 | 0x00);
i2c_write(i);
i2c_write(time[(i-2)]);
i2c_stop();
}
}
void get_rtc_time()
{
for (i=2;i<=4;i++)
{
i2c_start();
i2c_write(0xa0);
i2c_write(i);
i2c_start();
i2c_write(0xa0 | 0x01);
readtime[(i-2)]=i2c_read(0);
i2c_stop();
}
}
void alarm_set()
{
output_b(0xff);
if(minute==0x57)
{
if((second>=0x10)&&(second<=0x14))
{
printf("\n");
printf("ALARM SET!!!");
}
}
void main()
{
set_rtc_time();
17
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
while(1)
{
get_rtc_time();
hour = readtime[2];
minute= readtime[1];
second=readtime[0];
printf(" Time : %x : %x : %x \n\r",readtime[2],readtime[1],readtime[0]);
alarm_set();
}
}
OUTPUT
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
Time : 12 : 57 : 09
18
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
Time : 12 : 57 : 09
Time : 12 : 57 : 10
19
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
Exp. No. 5
AIM:
Implementation of model train controller using embedded microcontroller.
Steps:
1. Connect Model train kit to PIC.
2. PIC connected to PC.
3. Open MPLAB IDE on your system.
4. Select device. PIC 16f877A.
5. Select CCS C compiler. Select language tool suite. (CCS C Compiler (ccsc.exe))
6. Create project using project wizard. Chose project>project wizard.
7. Give project name and directory.
8. Create new file and save as (file name.c)
9. Add file to project by right clicking source file.
10. Then Go for compilation. (Project>compile F10)
11. Check the output window and simulation. If any error will be there, it will show in
output window.
12. Go to debugger>settings. See the output will come.
13. Open PIC ISP.
14. Select COM port and download file name.hex.GO for download. (While
downloading switch should be in programming mode.)
15. Download successful.
16. After that switch position is changed to exec mode and then reset the CPU code.
Code will be executed.
Program:
This program get the data from the sw1 (up for on, down for off) & sw2 (up for forward,
down for Reverse) and rotate the train. Also get the data from the sensor and put the
signals.
#include <16F877.H>
#include <stdio.h>
#use delay(clock=20000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)
#use I2C(MASTER,sda=PIN_C4,scl=PIN_C3)
20
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
void crossingon();
void crossingoff();
void init();
void initbuf();
void sensor();
void sensor1();
void station1forward();
void station2forward();
void station1reverse();
void station2reverse();
void sw();
void sw1();
void reverse();
void forward();
void main()
{
init();
initbuf();
while(1)
{
start1:
for(j=0x00;j<0x09;j++)
{
i1=0x05;
for(i=0x00;i<0x09;i++)
{
start:
if(i<=0x04)
{
i2c_start();
i2c_write(sel[j]); //write the
address for the device selection.
21
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
if(i>=0x05)
{
i2c_start();
i2c_write(sel[j]);
i2c_write(k+1);
i2c_write(ls0[i-0x04]);
i2c_stop();
i2c_start();
i2c_write(sel[j+1]);
i2c_write(k);
i2c_write(ls0[i1-0x04]);
i1++;
printf("Rotate one movement here\n");
}
i2c_stop();
stoptrain1:
sw(); //read the data from
the buffer.
// if((c != 0x0)) //check for sw1 & sw2 is
high.
// goto stoptrain1;
sensor();
if(senout == 0x00)
goto stop1;
22
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
senout++;
if(senout < 0x06)
delay_ms(200);
else if(senout == 0x06) //check the
station1.
{
delay_ms(0x2000); //wait some
delay in station1.
initbuf();
output_d(0x10); //glow
the yellow led for station1 in forward.
output_low(PIN_E2);
output_high(PIN_E2);
delay_ms(1000);
initbuf();
output_d(0x08); //glow
the green led for station1 in forward.
output_low(PIN_E2);
output_high(PIN_E2);
delay_ms(100);
}
if((senout > 0x06) && (senout <=0x0a))
delay_ms(200);
stop1:
if(senout1 == 0x00)
goto stop2;
senout1++;
if(senout1 < 0x06)
delay_ms(200);
else if(senout1 == 0x06) //check the
station2.
{
delay_ms(0x2000); //wait some
delay in station2.
initbuf();
output_d(0x04); //glow
the yellow led for station2 in forward.
output_low(PIN_E1);
output_high(PIN_E1);
delay_ms(1000);
23
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
initbuf();
output_d(0x02); //glow
the green led for station2 in forward.
output_low(PIN_E1);
output_high(PIN_E1);
delay_ms(100);
}
if((senout1 > 0x06) && (senout1 <=0x0a))
delay_ms(200);
stop2:
if(i != 0x08)
delay_ms(200);
/* if(buzzon == 0x01)
{
output_low(PIN_E0);
delay_ms(10);
output_high(PIN_E0);
delay_ms(10);
}*/
}
}
}
}
void init()
{
for(i=0;i<0x08;i++)
{
i2c_start();
i2c_write(sel[i]);
i2c_write(0x15);
i2c_write(0x00);
i2c_write(0x00);
i2c_stop();
printf("Clear the display here\n");
}
}
void sensor()
{
output_low(PIN_B4);
a=input_d(); //get the data from the buffer.
output_high(PIN_B4);
b = a;
24
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
b = b & 0x02;
if(b == 0x02) //sensor3 is set to low(enable) for close the
level crossing.
{
do{
output_low(PIN_B4);
a=input_d(); //get the data from the buffer.
output_high(PIN_B4);
c = a;
c = (c & 0x80);
}while(c != 0x0);
crossingon();
}
b = a;
b = b & 0x04;
if(b == 0x04) //sensor4 is set to low(enable) for open the
level crossing.
crossingoff();
b = a;
b = b & 0x08;
if(b == 0x08) //sensor5 is set to low(enable).
station2forward();
b = a;
b = b & 0x20;
if(b == 0x20) //sensor1 is set to low(enable).
station1forward();
}
void crossingon()
{
output_d(0xF0);
output_low(PIN_E1);
output_high(PIN_E1);
output_d(0xFF);
output_low(PIN_E0);
output_high(PIN_E0);
output_d(0x00);
output_low(PIN_E2);
output_high(PIN_E2);
25
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
buzzon = 0x01;
}
void crossingoff()
{
initbuf();
buzzon = 0x0;
}
void station1forward()
{
initbuf();
senout=0x01;
}
void station2forward()
{
initbuf();
output_d(0x08); //glow the red led for statio2 in
forward.
output_low(PIN_E1);
output_high(PIN_E1);
senout1 = 0x01;
}
void sw()
{
output_low(PIN_B4);
a=input_d(); //get the data from the buffer.
output_high(PIN_B4);
b=a;
b= b & 0x40; //check for switch1.
26
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
c=a;
c= (c & 0x80); //check for switch2.
if(b == 0x40)
reverse();
}
void reverse()
{
senout2 = 0x00, senout3 = 0x00;
init();
initbuf();
buzzon = 0x0;
while(1)
{
start3:
for(j=0x00;j<0x09;j++)
{
i1=0x05;
for(i=0x00;i<0x09;i++)
{
start4:
if(i<=0x04)
{
i2c_start();
i2c_write(sel1[j]); //write the
address for the device selection.
i2c_write(0x06); //write the
register address.
i2c_write(ls1[i]); //write the data
for lso register.
i2c_start();
i2c_write(sel1[j]); //write the
address for the device selection.
i2c_write(0x05); //write
the register address.
i2c_write(ls1[i1]); //write the data
for ls1 register.
i1++;
printf("Rotate one movement here\n");
}
if(j==0x08) //start the next
rotation in the train.
goto start3;
27
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
stoptrain2:
sw1(); //read the data from
the buffer.
// if(c != 0x0) //check for sw1 & sw2 is
high.
// goto stoptrain2;
if(i>=0x05)
{
i2c_start();
i2c_write(sel1[j]);
i2c_write(0x05);
i2c_write(ls1[i-0x04]);
i2c_stop();
i2c_start();
i2c_write(sel1[j+1]);
i2c_write(0x06);
i2c_write(ls1[i1-0x04]);
i1++;
printf("Rotate one movement here\n");
}
stoptrain3:
sw1(); //read the data from
the buffer.
// if((c != 0x0)) //check for sw1 & sw2 is
high.
// goto stoptrain3;
sensor1();
if(senout2 == 0x00)
goto stop3;
senout2++;
if(senout2 < 0x06)
delay_ms(200);
else if(senout2 == 0x06) //check the station2 in
reverse dircetion.
{
delay_ms(0x2000); //wait some
delay in station2 in reverse dirction.
initbuf();
output_d(0x80); //glow
the yellow led for station2 in reverse.
output_low(PIN_E2);
28
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
output_high(PIN_E2);
delay_ms(1000);
initbuf();
output_d(0x40); //glow
the green led for station2 in reverse.
output_low(PIN_E2);
output_high(PIN_E2);
delay_ms(100);
}
if((senout2 > 0x06) && (senout2 <=0x0a))
delay_ms(200);
stop3:
if(senout3 == 0x00)
goto stop4;
senout3++;
if(senout3 < 0x06)
delay_ms(200);
else if(senout3 == 0x06) //check the
station1.
{
delay_ms(0x2000); //wait some
delay in station1.
initbuf();
output_d(0x02); //glow
the yellow led for station1 in reverse.
output_low(PIN_E2);
output_high(PIN_E2);
delay_ms(1000);
initbuf();
output_d(0x01); //glow
the green led for station1 in reverse.
output_low(PIN_E2);
output_high(PIN_E2);
delay_ms(100);
}
if((senout3 > 0x06) && (senout3 <=0x0a))
delay_ms(200);
stop4:
if(i != 0x08)
29
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
delay_ms(200);
/* if(buzzon == 0x01)
{
output_low(PIN_E0);
delay_ms(10);
output_high(PIN_E0);
delay_ms(10);
}*/
}
}
}
}
void sensor1()
{
output_low(PIN_B4);
a=input_d(); //get the data from the buffer.
output_high(PIN_B4);
b = a;
b = b & 0x10;
if(b == 0x10) //sensor6 is set to low(enable).
station2reverse();
b = a;
b = b & 0x04;
if(b == 0x04) //sensor3 is set to low(enable) for close the
level crossing.
{
do{
output_low(PIN_B4);
a=input_d(); //get the data from the buffer.
output_high(PIN_B4);
c = a;
c = (c & 0x80);
}while(c != 0x0);
crossingon();
}
b = a;
b = b & 0x02;
if(b == 0x02) //sensor4 is set to low(enable) for open the
level crossing.
crossingoff();
30
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
b = a;
b = b & 0x01;
if(b == 0x01) //sensor2 is set to low(enable).
station1reverse();
}
void station1reverse()
{
initbuf();
output_d(0x04); //glow the red led for station1 in
forward.
output_low(PIN_E2);
output_high(PIN_E2);
senout3=0x01;
}
void station2reverse()
{
initbuf();
output_d(0x01); //glow the red led for statio2 in
forward.
output_low(PIN_E1);
output_high(PIN_E1);
senout2=0x01;
}
void sw1()
{
output_low(PIN_B4);
a=input_d(); //get the data from the buffer.
output_high(PIN_B4);
b=a;
b= b & 0x40; //check for switch1.
c=a;
c= c & 0x80; //check for switch2.
}
31
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
void initbuf()
{
output_d(0x00); //noy glow the station2 signal.
output_low(PIN_E1);
output_high(PIN_E1);
32
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
Exp. 6
Algorithm:
1. Start.
2. Declare the input and output ports.
3. Perform the calculations and assign the result to output port.
4. Create the test bench waveform.
5. Simulate and verify the output.
6. Stop.
Verilog Module
module pll(u1,u2,ID_clock,reset);
input u1,ID_clock,reset;
output u2;
parameter M=32;
parameter K=8;
parameter N=16;
parameter PHASE_DETECTOR_SELECT=1;//1 for xor,2 for JK FF
parameter M2=5;//log base 2 of M
parameter K2=3;//log base 2 of K
parameter N2=4;//log base 2 of N
wire reset,XOR_out,JK_out,DN_UP,K_clock,u2,u2_prime;
reg[(K2-1):0]Kup,Kdn;
reg carry_new,Borrow,Toggle_FF,carry_pulse,Borrow_pulse,advanced,delayed;
reg ID_out,ID_out_2,ID_out_4,ID_out_8,ID_out_16;
reg Borrow_new,toggle_FF,Carry_pulse,Carry_new,Carry;
assign K_clock=ID_clock;
jk jk1 (Q,J,K);
assign XOR_out=u1^u2_prime;
assign DN_UP=PHASE_DETECTOR_SELECT?XOR_out:JK_out;
//*******KCOUNTER*******//
33
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
begin
Kup<=0;
Kdn<=0;
Carry<=0;
Borrow<=0;
end
else
begin
if(DN_UP)Kdn<=Kdn+1;
else
begin
if(DN_UP)Kdn<=Kdn+1;
Carry<=Kup[K2-1];
Borrow<=Kdn[K2-1];
end
end
end
///**ID COUNTER****///
always@(posedge ID_clock)
begin
if(!Carry)
begin
Carry_new<=1;
Carry_pulse<=0;
end
else if(Carry_pulse)
begin
Carry_pulse<=0;
Carry_new<=0;
end
else if(Carry && Carry_new)
begin
Carry_pulse<=1;
Carry_new<=0;
end
else
begin
Carry_pulse<=0;
Carry_new<=0;
end
end
//always@(posedge Borrow or posedge ID_clock)
always@(posedge ID_clock)
34
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
begin
if(!Borrow)
begin
Borrow_new<=1;
Borrow_pulse<=0;
end
else if(Borrow_pulse)
begin
Borrow_pulse<=0;
Borrow_new<=0;
end
else if(Borrow && Borrow_new)
begin
Borrow_pulse<=1;
Borrow_new<=0;
end
else
begin
Borrow_pulse<=0;
Borrow_new<=0;
end
end
always@(posedge ID_clock or negedge reset)
begin
if(!reset)
begin
Toggle_FF<=0;
delayed<=1;
advanced<=1;
end
else
begin
if(Carry_pulse)
begin
advanced<=1;
Toggle_FF<=!Toggle_FF;
end
else if(Borrow_pulse)
begin
delayed<=1;
Toggle_FF<=!Toggle_FF;
end
else if(Toggle_FF==0)
begin
if(!advanced)Toggle_FF<=!toggle_FF;
else if(advanced)
35
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
begin
Toggle_FF<=Toggle_FF;
advanced<=0;
end
end
else
begin
if(!delayed)Toggle_FF<=!Toggle_FF;
else if(delayed)
begin
Toggle_FF<=Toggle_FF;
delayed<=0;
end
end
end
end
//always@(ID_clock)
always@(ID_clock or Toggle_FF)
begin
if(Toggle_FF)ID_out<=0;
else
begin
if(ID_clock)ID_out<=0;
else ID_out<=1;
end
end
assign u2=ID_out;
///***N COUNTER***///
always@(negedge ID_out or negedge reset)
begin
if(!reset)ID_out_2<=0;
else ID_out_2<=!ID_out_2;
end
always@(negedge ID_out_2 or negedge reset)
begin
if(!reset)ID_out_4<=0;
else ID_out_4<=!ID_out_4;
end
always@(negedge ID_out_4 or negedge reset)
begin
if(!reset)ID_out_8<=0;
else ID_out_8<=!ID_out_8;
end
always@(negedge ID_out_8 or negedge reset)
36
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
begin
if(!reset)ID_out_16<=0;
else ID_out_16<=!ID_out_16;
end
assign u2_prime=ID_out_8;
endmodule
/////////////////////////
module jk(Q,J,K);
input J,K;
output Q;
reg Q;
always@(posedge J)
begin
if(K==1)
Q<=!Q;
else Q<=1;
end
always@(posedge K)
begin
if(J==1)
Q<=!Q;
else
Q<=0;
end
endmodule
OUTPUT WAVEFORM
37
SMK FOMRA INSTITUTE OF TECHNOLOGY, KELAMBAKKAM
RTL SCHEMATIC:
38