Vlsi Manual e&c Dept

Post on 07-Apr-2015

441 views 2 download

transcript

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 1

VLSI LAB Subject Code : 06ECL77 IA Marks : 25 No. of Practical Hrs/Week : 03 Exam Hours : 03 Total no. of Practical Hrs. : 42 Exam Marks : 50

PART - A DIGITAL DESIGN ASIC-DIGITAL DESIGN FLOW

1. Write Verilog Code for the following circuits and their Test Bench for verification, observe the waveform and synthesise the code with technological library with given Constraints*. Do the initial timing verification with gate level simulation.

i. An inverter, ii. A Buffer iii. Transmission Gate iv. Basic/universal gates v. Flip flop -RS, D, JK, MS, T vi. Serial & Parallel adder vii. 4-bit counter [Synchronous and Asynchronous counter] viii. Successive approximation register [SAR] * An appropriate constraint should be given

PART - B

ANALOG DESIGN Analog Design Flow

1. Design an Inverter with given specifications*, completing the design flow mentioned below:

a. Draw the schematic and verify the following i) DC Analysis ii) Transient Analysis b. Draw the Layout and verify the DRC, ERC c. Check for LVS d. Extract RC and back annotate the same and verify the Design e. Verify & Optimize for Time, Power and Area to the given constraint*** 2. Design the following circuits with given specifications*, completing the design flow mentioned below: a. Draw the schematic and verify the following i) DC Analysis ii) AC Analysis iii) Transient Analysis b. Draw the Layout and verify the DRC, ERC c. Check for LVS d. Extract RC and back annotate the same and verify the Design. i) A Single Stage differential amplifier ii) Common source and Common Drain amplifier

Design an op-amp with given specification* using given differential amplifier

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 2

2. Common source and Common Drain amplifier in library** and completing the design flow mentioned below:

a. Draw the schematic and verify the following i) DC Analysis ii) AC Analysis iii) Transient Analysis b. Draw the Layout and verify the DRC, ERC c. Check for LVS d. Extract RC and back annotate the same and verify the Design.

3. Design a 4 bit R-2R based DAC for the given specification and completing the design flow mentioned using given op-amp in the library**.

a. Draw the schematic and verify the following i) DC Analysis ii) AC Analysis iii) Transient Analysis b. Draw the Layout and verify the DRC, ERC c. Check for LVS d. Extract RC and back annotate the same and verify the Design.

4. For the SAR based ADC mentioned in the figure below draw the mixed signal schematic and verify the functionality by completing ASIC Design FLOW.

[Specifications to GDS-II]

* Appropriate specification should be given. ** Applicable Library should be added & information should be given to the Designer.

*** An appropriate constraint should be given

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 3

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 4

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 5

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 6

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 7

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 8

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 9

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 10

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 11

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 12

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 13

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 14

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 15

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 16

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 17

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 18

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 19

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 20

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 21

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 22

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 23

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 24

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 25

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 26

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 27

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 28

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 29

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 30

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 31

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 32

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 33

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 34

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 35

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 36

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 37

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 38

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 39

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 40

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 41

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 42

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 43

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 44

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 45

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 46

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 47

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 48

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 49

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 50

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 51

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 52

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 53

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 54

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 55

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 56

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 57

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 58

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 59

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 60

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 61

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 62

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 63

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 64

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 65

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 66

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 67

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 68

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 69

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 70

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 71

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 72

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 73

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 74

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 75

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 76

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 77

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 78

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 79

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 80

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 81

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 82

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 83

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 84

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 85

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 86

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 87

PROCEDURE TO RUN THE SIMULATION AND SYNTHESIS USING NCSIM AND ENCOUNTER RTL

Example for SERIAL ADDER

Setup the design environment

1. Create cds.lib and make the following enteries Define sadder_lib ./sadder.lib Define designlib ../design.lib

2. Create the following directories Mkdir sadder.lib Mkdir ../design.lib

3. Create hdl.var and make the following entry Define WORK designlib Define VIEW vlog Compilation process

1. ncvlog shift_register.v –messages 2. ncvlog serial_adder.v –mess 3. ncvlog serial_adder_t.v –mess –work sadder_lib 4. Add the following entry to hdl.var:::: Define NCELABOPTS –messages

Elaborate the Design

ncelab serial_adder_t –access +rwc

Simulate the Design

ncsim serial_adder_t –gui

When the Design Browser window pops up

1. Select the SERIAL_ADDER_T instance and click SEND the SELECTED SIGNALS TO THE TARGETED WAVEFORM WINDOW.

2. In the waveform window press RUN. 3. Now you will be able to visualize the waveforms.

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 88

SYNTHESIS 1. Change the work directory to cd rclabs/work 2. Start the tool by entering rc –gui –logfile serial_adder.log 3. An rc:/> shell prompt would appear with a GUI interface. 4. At the shell prompt enter gui_hide 5. Generate a template script-----rc:/>write_template –outfile template.tcl

Setup the environment

In the template.tcl fill the following commands to set the search paths

1. The RTL files are in the ../rtl directory 2. The libraries are in the ../library directory 3. The Tcl scripts are in the ../tcl and in the work directory 4. Add the following script search path in template.tcl

Set_attr hdl_search_path {../rtl}/ Set_attr lib_search_path{../library}/ Set_attr script_searc_path{../tcl} Set_attr information_level 7/

5. At rc:/> include ../tcl/setup.g 6. Read the libraries with library command----rc:/> set_attr library $LIBRARY 7. Specify the cells to avoid by entering –rc:/> set_attr avoid true [find /lib * -libcell

SDFF*] 8. rc:/> read_hdl $FILE_LIST 9. rc:/>elaborate serial_adder 10. rc:/>check_design serial_adder 11. rc:/>include constraints_serial_adder.g 12. rc:/> report timing –lint 13. rc:/> synthesize –to_mapped –eff medium –no_incr 14. rc:/>report area >> serial_adder.report 15. rc:/>write_hdl –m > serial_adder_mapped.netlist 16. rc:/>gui_show

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 89

INVERTER `resetall `timescale 1 ns / 1 ns `view vlog //Define our own Inverter, module inverter ( out , in ); // Declarations of I/O ,Power and Ground Lines output out; input in; supply1 pwr; supply0 gnd; // Instantiate pmos and nmos switches pmos (out,pwr,in); nmos (out,gnd,in); endmodule `noview `resetall `timescale 1 ns / 1 ns `view vlog // Testbench for Inverter Module module inv_test; wire out ; reg in ; `uselib view = vlog // Instantiate inverter Module inverter i1 ( out, in ) ; `nouselib

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 90

// Display task display ; begin $display ( "time=%0d" , $time , " ns" , " Input=" , in , " Output=", out ) ; end endtask // Apply Stimulus initial begin in = 1'b0 ; #10 ; display ; in = 1'b1 ; #10 ; display ; in = 1'bx ; #10 ; display ; in = 1'bz ; #10 ; display ; end endmodule `noview BUFFER `resetall `timescale 1 ns / 1 ns `view vlog //Define our own Inverter, module inverter ( Y, A ); // Declarations of I/O ,Power and Ground Lines output Y; input A; supply1 pwr; supply0 gnd;

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 91

// Instantiate pmos and nmos switches pmos (Y,pwr,A); nmos (Y,gnd,A); endmodule // Define our own Buffer module buffer ( out, in ); // Declarations of I/O Lines output out; input in; // Wire Declaration wire a; // Instantiate Inverter module inverter i1 (a,in); inverter i2 (out,a); endmodule `noview // Testbench for Buffer Module `resetall `timescale 1 ns / 1 ns `view vlog module buf_test; wire out ; reg in ; `uselib view = vlog // Instantiate Buffer Module buffer b1 ( out, in ) ; `nouselib

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 92

// Display task display ; begin $display ( "time=%0d" , $time , " ns" , " Input=" , in , " Output=", out ) ; end endtask // Apply Stimulus initial begin in = 1'b0 ; #10 ; display ; in = 1'b1 ; #10 ; display ; in = 1'bx ; #10 ; display ; in = 1'bz ; #10 ; display ; end endmodule `noview TRANSMISSION GATE `resetall `timescale 1 ns / 1 ns `view vlog //Define our own Transmission Gate, module trangate ( out , in , cntrl1, cntrl2 ); // Declarations of I/O and Control Lines output out; input in; input cntrl1,cntrl2;

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 93

// Instantiate pmos and nmos switches pmos (out,in,cntrl1); nmos (out,in,cntrl2); endmodule `noview `resetall `timescale 1 ns / 1 ns `view vlog // Testbench for Inverter Module module trangate_test; wire out ; reg in ; reg cntrl1,cntrl2; `uselib view = vlog // Instantiate trangate Module trangate t1 ( out, in, cntrl1, cntrl2 ) ; `nouselib // Display task display ; begin $display ( "time=%0d" , $time , " ns" , " Input=" , in , " Output=", out , " Control1=",cntrl1 , " Control2=",cntrl2 ) ; end endtask

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 94

// Apply Stimulus initial begin in = 1'b0 ; cntrl1 = 1'b0 ; cntrl2 = 1'b1 ; #10 ; display ; in = 1'b0 ; cntrl1 = 1'b1 ; cntrl2 = 1'b0 ; #10 ; display ; in = 1'b1 ; cntrl1 = 1'b0 ; cntrl2 = 1'b1 ; #10 ; display ; in = 1'b1 ; cntrl1 = 1'b1 ; cntrl2 = 1'b0 ; #10 ; display ; end endmodule `noview BASIC GATES: AND, OR, NAND, NOR, XOR, XNOR FLIPFLOPS module d_ff(q,clk,n_rst,din); output q; input clk,din,n_rst; reg q; always @(posedge clk or negedge n_rst) begin if(!n_rst) q <= 1'b0; else q <= din; end endmodule module d_ff_test; reg clk, din, n_rst; wire q, d1, clk1; d_ff df1 (q, clk, n_rst, din); assign d1=din; assign clk1=clk; initial clk = 1'b0; always #10 clk = ~clk; initial begin din = 1'b0;

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 95

n_rst = 1'b1; #20 n_rst = 1'b0; #10 din = 1'b1; #20 n_rst = 1'b1; #18 din = 1'b0; #1 din = 1'b1; #20 din = 1'b0; #10 ; end always #5 $display ($time," clk=%b din=%b q=%b", clk, din, q); initial #100 $finish; specify $setup(d1, posedge clk1, 2); $hold(posedge clk1, d1, 2); $width(negedge d1, 2); endspecify endmodule module jk_ff(q,qbar,clk,rst,j,k); input clk,rst,j,k; output q,qbar; reg q,tq; always @(posedge clk or negedge rst) begin if (!rst) begin q <= 1'b0; tq <= 1'b0; end else begin if (j == 1'b1 && k == 1'b0) q <= j; else if (j == 1'b0 && k == 1'b1) q <= 1'b0; else if (j == 1'b1 && k == 1'b1) begin tq <= ~tq; q <= tq; end end end assign q_bar = ~q;

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 96

endmodule module jk_ff_test; reg clk,rst,j,k; wire q,qbar; wire clk1,j1,k1; jk_ff inst(q,qbar,clk,rst,j,k); assign clk1=clk; assign j1=j; assign k1=k; initial clk = 1'b0; always #10 clk = ~clk; initial begin j = 1'b0; k = 1'b0; rst = 1'b0; #30 rst = 1'b1; #60 j = 1'b0; k = 1'b1; #29 j = 1'b1; k = 1'b0; #1 j = 1'b0; k = 1'b1; #20 j = 1'b1; k = 1'b1; #40 j = 1'b1; k = 1'b0; #5 j = 1'b0; #20 j = 1'b1; #50 rst = 1'b0; #10 ; end always #5 $display($time," clk=%b j=%b k=%b ",clk,j,k); initial #300 $finish; specify $setup(j1, posedge clk1, 2); $setup(k1, posedge clk1, 2); $hold(posedge clk1, j1, 2); $hold(posedge clk1, k1, 2); endspecify endmodule module ms_jkff(q,q_bar,clk,j,k); output q,q_bar; input clk,j,k; reg tq,q,q_bar; always @(clk) begin if (!clk) begin

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 97

if (j==1'b0 && k==1'b1) tq <= 1'b0; else if (j==1'b1 && k==1'b0) tq <= 1'b1; else if (j==1'b1 && k==1'b1) tq <= ~tq; end if (clk) begin q <= tq; q_bar <= ~tq; end end endmodule module tb_ms_jkff; reg clk,j,k; wire q,q_bar; wire clk2,j2,k2; ms_jkff inst(q,q_bar,clk,j,k); assign clk2=clk; assign j2=j; assign k2=k; initial clk = 1'b0; always #10 clk = ~clk; initial begin j = 1'b0; k = 1'b0; #60 j = 1'b0; k = 1'b1 #40 j = 1'b1; k = 1'b0; #20 j = 1'b1; k = 1'b1; #40 j = 1'b1; k = 1'b0; #5 j = 1'b0; #20 j = 1'b1; #10 ; end always #5 $display($time," clk=%b j=%b k=%b ",clk,j,k); initial #200 $finish; specify $setup(j2, posedge clk2, 2); $setup(k2, posedge clk2, 2); $hold(posedge clk2, j2, 2);

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 98

$hold(posedge clk2, k2, 2); endspecify endmodule module SR_ff(q,qbar,s,r,clk); output q,qbar; input clk,s,r; reg tq; always @(posedge clk or tq) begin if (s == 1'b0 && r == 1'b0) tq <= tq; else if (s == 1'b0 && r == 1'b1) tq <= 1'b0; else if (s == 1'b1 && r == 1'b0) tq <= 1'b1; else if (s == 1'b1 && r == 1'b1) tq <= 1'bx; end assign q = tq; assign qbar = ~tq; endmodule module SR_ff_test; reg clk,s,r; wire q,qbar; wire s1,r1,clk1; SR_ff sr1(q,qbar,s,r,clk); assign s1=s; assign r1=r; assign clk1=clk; initial clk = 1'b0; always #10 clk = ~clk; initial begin s = 1'b0; r = 1'b0; #30 s = 1'b1; #29 s = 1'b0; #1 r = 1'b1; #30 s = 1'b1; #30 r = 1'b0; #20 s = 1'b0; #19 s = 1'b1;

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 99

#200 s = 1'b1; r = 1'b1; #50 s = 1'b0; r = 1'b0; #50 s = 1'b1; r = 1'b0; #10 ; end always #5 $display($time," clk=%b s=%b r=%b ",clk,s,r); initial #500 $finish; specify $setup(s1, posedge clk1, 2); $setup(r1, posedge clk1, 2); $hold(posedge clk1, s1, 2); $hold(posedge clk1, r1, 2); endspecify endmodule module t_ff(q,qbar,clk,tin,rst); output q,qbar; input clk,tin,rst; reg tq; always @(posedge clk or negedge rst) begin if(!rst) tq <= 1'b0; else begin if (tin) tq <= ~tq; end end assign q = tq; assign qbar = ~q; endmodule module t_ff_test; reg clk,tin,rst; wire q,qbar; t_ff t1(q,qbar,clk,tin,rst); initial clk = 1'b0; always #10 clk = ~clk; initial begin

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 100

rst = 1'b0; tin = 1'b0; #30 rst = 1'b1; #10 tin = 1'b1; #205 tin = 1'b0; #300 tin = 1'b1; #175 tin = 1'b0; #280 rst = 1'b0; #20 rst = 1'b1; #280 tin = 1'b1; #10 ; end initial #2000 $finish; endmodule SERIAL ADDER module serial_adder ( A,B, reset, clock, sum); input [7:0] A,B; input reset,clock; output [7:0] sum; reg [3:0] count; reg s,y,Y; wire [7:0] qa,qb,sum; wire run; parameter G=0,H=1; shiftrne shift_A (A,reset,1'b1,1'b0,clock,qa); shiftrne shift_B (B,reset,1'b1,1'b0,clock,qb); shiftrne shift_sum (8'b0,reset,run,s,clock,sum); //adder fsm //output and next state combinational circuit always @(qa or qb or y) case (y) G: begin s = qa[0]^qb[0]; if (qa[0] & qb[0]) Y = H; else Y = G; end H: begin

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 101

s = qa[0] ~^qb[0]; if (~qa[0] & ~qb[0]) Y =G; else Y = H; end default : Y = G; endcase //sequential block always @(posedge clock) if (reset) y <= G; else y <= Y; //control the shifting process always @(posedge clock) if (reset) count = 8; else if (run) count = count - 1; assign run=|count; endmodule module shiftrne ( R,L,E,w,clock,q); parameter n=8; input [n-1:0] R; input L,E,w,clock; output [n-1:0] q; reg [n-1:0] q; integer k; always @(posedge clock) if (L) q <= R; else if (E) begin for (k=n-1;k>0;k=k-1) q[k-1] <= q[k]; q[n-1] <= w; end endmodule

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 102

module serial_adder_t ; reg [7:0] A,B; reg reset,clock; wire [7:0] sum ; initial clock = 1'b0; always #5 clock =~clock; serial_adder s1 (A,B,reset,clock,sum); initial begin reset = 1'b0;A = 8'b10101010; B = 8'b11111111; #20 reset = 1'b1; #20 reset = 1'b0; #150 reset = 1'b1; A = 8'b11110000 ; B = 8'b11110011; #20 reset = 1'b0; #200 $finish; end initial $monitor ($time, " SUM = %d ", sum); endmodule PARELLEL ADDER

module adder4 ( carryin,x,y,sum,carryout); input carryin; input [3:0] x,y; output [3:0] sum; output carryout; fulladd stage0 (carryin,x[0],y[0],sum[0],c1); fulladd stage1 (c1,x[1],y[1],sum[1],c2); fulladd stage2 (c2,x[2],y[2],sum[2],c3); fulladd stage3 (c3,x[3],y[3],sum[3],carryout); endmodule module fulladd (cin,x,y,s,cout); input cin,x,y; output s,cout; assign s = x^y^cin; assign cout =( x & y) | (x & cin) |( y & cin); endmodule module adder4_t ; reg [3:0] x,y; reg carryin; wire [3:0] sum; wire carryout;

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 103

adder4 a1 ( carryin,x,y,sum,carryout); initial begin $monitor($time,"SUM=%d",sum); x = 4'b0000; y= 4'b0000;carryin = 1'b0; #20 x =4'b1111; y = 4'b1010; #40 x =4'b1011; y =4'b0110; #40 x =4'b1111; y=4'b1111; #50 $finish; end endmodule ASYNCOUNTER

`view rtl module ripple_counter (clock, toggle, reset, count); input clock, toggle, reset; output [3:0] count; reg [3:0] count; wire c0, c1, c2; assign c0 = count[0], c1 = count[1], c2 = count[2]; always @ (posedge reset or posedge clock) if (reset == 1'b1) count[0] <= 1'b0; else if (toggle == 1'b1) count[0] <= ~count[0]; always @ (posedge reset or negedge c0) if (reset == 1'b1) count[1] <= 1'b0; else if (toggle == 1'b1) count[1] <= ~count[1]; always @ (posedge reset or negedge c1) if (reset == 1'b1) count[2] <= 1'b0; else if (toggle == 1'b1) count[2] <= ~count[2]; always @ (posedge reset or negedge c2) if (reset == 1'b1) count[3] <= 1'b0; else if (toggle == 1'b1) count[3] <= ~count[3]; endmodule `noview module ripple_counter_t ; reg clock,toggle,reset; wire [3:0] count ; ripple_counter r1 (clock,toggle,reset,count); initial clock = 1'b0; always #5 clock = ~clock; initial

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 104

begin reset = 1'b0;toggle = 1'b0; #10 reset = 1'b1; toggle = 1'b1; #10 reset = 1'b0; #190 reset = 1'b1; #20 reset = 1'b0; #100 reset = 1'b1; #40 reset = 1'b0; #250 $finish; end initial $monitor ($time, " output q = %d", count); endmodule SYNCOUNTER

module counter_behav ( count,reset,clk); input wire reset, clk; output reg [3:0] count; always @(posedge clk) if (reset) count <= 4'b0000; else count <= count + 4'b0001; endmodule module mycounter_t ; wire [3:0] count; reg reset,clk; initial clk = 1'b0; always #5 clk = ~clk; counter_behav m1 ( count,reset,clk); initial begin reset = 1'b0 ; #15 reset =1'b1; #30 reset =1'b0; #300 $finish; end initial $monitor ($time, "Output count = %d ",count ); endmodule

Department of Electronics and Communication DSCE, Bangalore – 560 078.

VLSI Lab Manual Page 105

SAR module shiftrne ( R,L,E,w,clock,q); parameter n=8; input [n-1:0] R; input L,E,w,clock; output [n-1:0] q; reg [n-1:0] q; integer k; always @(posedge clock) if (L) q <= R; else if (E) begin for (k=n-1;k>0;k=k-1) q[k-1] <= q[k]; q[n-1] <= w; end endmodule module sar_t; reg [7:0] r; reg l; reg e; reg w; reg clk; wire [7:0] q; shiftrne sf(.R(r),.L(l),.E(e),.w(w),.clock(clk),.q(q)); initial begin clk = 1'b0; l = 1'b1; w = 1'b0; e = 1'b0; #5 r = 8'b1111_0000; #10 l = 1'b0; e = 1'b1; w = 1'b0; #10 w = 1'b0; #10 w = 1'b0; #10 w = 1'b0; #10 w = 1'b1; #10 w = 1'b1; #10 w = 1'b1; #10 w = 1'b1; #10 $finish; end always #5 clk = ~clk; end module