Switch level modeling - chapter 10 – 
padmanabhan book 
P Devi Pradeep 
 Designers familiar with logic gates and their configurations at the circuit 
level may choose to do their designs using MOS transistors. 
 Verilog has the provision to do the design description at the switch level 
using such MOS transistors, which is the theme of the present chapter. 
 Switch level modeling forms the basic level of modeling digital circuits 
 The switches are available as an primitives in Verilog; they are central to 
design description at this level. 
 Basic gates can be defined in terms of such switches. 
By repeated and successive instantiation of such switches, more involved 
circuits can be modeled – on the same lines as was done with the gate level 
primitives in Chapters 4 and 5.
BASIC TRANSISTOR SWITCHES:
Basic Switch Primitives: 
 Different switch primitives are available in Verilog. Consider an nmos 
switch. A typical instantiation has the form 
nmos (out, in, control); 
pmos (out, in, control);
Observations: 
 When in the on state, the switch makes its output available at the same 
strength as the input. 
 There is only one exception to it: When the input is of strength supply, 
the output is of strength strong. It is true of supply1 as well as supply0. 
 When instantiating an nmos or a pmos switch, a name can be assigned 
to the switch. But the name is not essential. (The same is true of the other 
primitives discussed in the following sections as well.) 
 The nmos and pmos switches function as unidirectional switches.
Resistive Switches: 
 nmos and pmos represent switches of low impedance in the on-state. rnmos 
and rpmos represent the resistive counterparts of these respectively. 
 Typical instantiations have the form 
rnmos (output1, input1, control1); 
rpmos (output2, input2, control2); 
 With rnmos if the control1 input is at 1 (high) state, the switch is ON and 
functions as a definite resistance. It connects input1 to output1 through a 
resistance. When control1 is at the 0 (low) state, the switch is OFF and 
leaves output1 floating. The set of output values for all combinations of 
input1 andcontrol1 values remain identical to those of the nmos switch 
given in Table . 
 The rpmos switch is ON when control2 is at 0 (low) state. It inserts a 
definite resistance between the input and the output signals but retains the 
signal value. The output values for different input values remain identical to 
those in Table for the pmos switch.
Switch level modeling
Example 10.1 home work 
module swt_aa (o1,o2,a1,a2,b1,b2,c1,c2); 
output o1,o2; 
input a1,a2,b1,b2,c1,c2; 
wire o2; 
tri1 o1; 
bufif1 ctt1(o1,a1,c1), ctt2(o1,a2,c2); 
bufif1 (weak1, weak0) ctp1(o2,b1,c1),ctp2(o2,b2,c2); 
pullup pp(o2); 
endmodule
CMOS inverter: 
module inv (in, out ); 
output out; 
input in; 
supply0 a; 
supply1 b; 
nmos (out, a, in ); 
pmos (out, b, in); 
endmodule
module npnor_2(out, in1, in2 ); 
output out; 
input in1, in2; 
supply1 a; 
supply0 c; 
wire b; 
pmos(b, a, in2), (out, b, in1); 
nmos (out, c, in1), (out, c, in2) ; 
endmodule 
* Here do some another examples like orgate nandgate and andgates….
NMOS Inverter with Pull up Load: 
module NMOSinv(out,in); 
output out; 
Input in; 
supply0 a; 
pullup (out); 
nmos(out,a,in); 
endmodule 
module tst_nm_in(); 
reg in;wire out; 
NMOSinv nmv(out,in); 
initial 
in =1'b1; 
always 
#3 in =~in; 
initial $monitor($time , " in = %b, output 
= %b ",in,out); 
initial #30 $stop; 
endmodule
An NMOS Three Input NOR Gate: 
module nor3NMOS(in1,in2,in3,b); 
output b; 
input in1,in2,in3; 
supply0 a; wire b; 
nmos(b,a,in1),(b,a,in2),(b,a,in3); 
pullup(b); 
endmodule
CMOS SWITCH: 
x N_control turns ON the NMOS transistor and keeps it ON when it is in the 1 
state. 
x P_control turns ON the PMOS transistor and keeps it ON when it is in the 0 
state. 
The CMOS switch is instantiated as shown below. 
cmos csw (out, in, N_control, P_control ); 
Significance of the different terms is as follows: 
x cmos:The keyword for the switch instantiation 
x csw: Name assigned to the switch in the 
instantiation 
x out: Name assigned to the output variable in the 
instantiation 
x in: Name assigned to the input variable in the 
instantiation 
x N_control: Name assigned to the control variable of 
the NMOS transistor in the instantiation 
x P_control: Name assigned to the control variable of 
the PMOS transistor in the instantiation
Example 10.6 CMOS Switch – 1 
module CMOSsw(out,in,n_ctr,p_ctr); 
output out; 
input in,n_ctr,p_ctr; 
nmos gn(out,in,n_ctr); 
pmos gp(out,in,p_ctr); 
endmodule 
module tst_CMOSsw(); 
reg in,n_ctr,p_ctr; wire out; 
CMOSsw cmsw(out,in,n_ctr,p_ctr); 
initial begin 
in=1'b0;n_ctr=1'b1;p_ctr=~n_ctr; end 
always #5 in =~in; 
always begin #3 n_ctr=~n_ctr; #0p_ctr 
=~n_ctr; end 
initial $monitor($time , "in = %b , n_ctr = 
%b , p_ctr = %b , output = %b 
",in,n_ctr,p_ctr,out); 
initial #39 $ 
# 0in = 0 , n_ctr = 1 , p_ctr = 0 , output = 0 
# 3in = 0 , n_ctr = 0 , p_ctr = 1 , output = z 
# 5in = 1 , n_ctr = 0 , p_ctr = 1 , output = z 
# 6in = 1 , n_ctr = 1 , p_ctr = 0 , output = 1 
# 9in = 1 , n_ctr = 0 , p_ctr = 1 , output = z 
# 10in = 0 , n_ctr = 0 , p_ctr = 1 , output = z 
# 12in = 0 , n_ctr = 1 , p_ctr = 0 ,output = 0
Example 10.7 CMOS Switch – 2: module 
CMOSsw1(out,in,con); 
output out; 
input in,con; 
wire p_ctr; 
not gn(p_ctr,con); 
cmos gc(out,in,con,p-ctr); 
endmodule 
module tst_CMOSsw1(); 
reg in,con; wire out; 
CMOSsw1 cmsw(out,in,con); 
initial begin in=1'b0;con=1'b1; end 
always #5 in =~in; 
always #3 con=~con; 
initial $monitor($time , "in = %b , con = 
%b , output = %b " ,in,con,out); 
initial #40 $stop; 
endmodule
Example 10.8: A RAM Cell 
 Figure shows a basic ram cell with facilities for writing data, storing 
data, 
and reading data. 
 When switch sw2 is on, qb – the output of inverter g1 – forms the input 
to the inverter g2 and vice versa. The g1-g2 combination functions as a 
latch and freezes the last state entry before sw2 turns on. 
 When wsb (write/store) is high, switch sw1 is ON, and switch sw2 OFF. 
With sw1 on, input Din is connected to the input of gate g1 and remains so 
connected. 
When wsb goes low, din is isolated, since sw1 is OFF. But sw2 is ON and 
the data remains latched in the latch formed by g1-g2. In other words the 
data Din is stored in the RAM cell formed by g1-g2. 
 When RD (Read) goes active (=1), the latched state is available as output 
Do. Reading is normally done when the latch is in the stored state.
module csw(out,in,n_ctr); 
output out; input in,n_ctr; wire p_ctr; 
assign p_ctr =~n_ctr; 
cmos csw(out,in,n_ctr,p_ctr); 
endmodule 
module ram_cell(do,din,wsb,rd); 
output do; 
input din,wsb,rd; 
wire sb; 
wire q,qq; 
tri do; 
csw sw1(q,din,wsb),sw2(q,qq,sb),sw3(do,q,rd); 
not n1(sb,wsb),n2(qb,q),n3(qq,qb); 
endmodule
An Alternate RAM Cell Realization 
module ram1(do,din,wr,rd); 
output do; 
input din,wr,rd; 
wire qb,q; tri do; 
scw 
sww(q,din,wr),swr(do,q,rd); 
not(pull1,pull0)n1(qb,q),n2(q,q); 
endmodule 
module scw(out,in,n_ctr); 
output out; 
input in,n_ctr; 
wire p_ctr; 
assign p_ctr =~n_ctr; 
cmos sw(out,in,n_ctr,p_ctr); 
endmodule
A Dynamic Shift Register: 
The shift register can be modified to suit a variety of needs: 
---------Dynamic logic incorporating NAND / NOR gates. 
---- Dynamic RAM with row and column select lines and refresh functions. 
----- A shift register to function as a right- or a left-shift-type shift register; a 
direction select bit can be used to alter the shift direction.
module shreg1(dout,din,phi1); 
output dout; 
input din,phi1; 
wire phi2; 
trireg[3:0] x,y; 
trireg dout; 
assign phi2=~phi1; 
cmos switch0(x[0],din,phi1,phi2), 
switch1(x[1],y[0],phi2,phi1), 
switch2(x[2],y[1],phi1,phi2), 
switch3(x[3],y[2],phi2,phi1), 
switch4(dout,y[3],phi1,phi2); 
cell cc0(y[0],x[0]), cc1(y[1],x[1]), cc2(y[2],x[2]), cc3(y[3],x[3]); 
endmodule 
module cell(op,ip); 
output op; 
input ip; 
supply1 pwr; 
supply0 gnd; 
nmos(op,gnd,ip); 
pmos(op,pwr,ip); 
endmodule
BI-DIRECTIONAL GATES: 
 The gates discussed so far (nmos, pmos, rnmos, rpmos, rcmos) are all 
unidirectional gates. 
 When turned ON, the gate establishes a connection and makes the signal 
at the input side available at the output side. 
 Verilog has a set of primitives for bi-directional switches as well. They 
connect the nets on either side when ON and isolate them when OFF. 
 The signal flow can be in either direction. 
 None of the continuous-type assignments at higher levels dealt with so far 
has a functionality equivalent to the bi-directional gates. 
There are six types of bidirectional gates. 
tran , rtran , tranif1, and rtranif1 tranif0 and 
rtranif0
tran and rtran: 
 The tran gate is a bi-directional gate of two ports. When instantiated, it 
connects the two ports directly. 
 Thus the instantiation tran (s1, s2); 
 connects the signal lines s1 and s2. Either line can be input, inout or 
output. 
rtran is the resistive counterpart of tran. 
tranif1 and rtranif1: 
 tranif1 is a bi-directional switch turned ON/OFF through a control line. It is in 
the ON-state when the control signal is at 1 (high) state. When the control line is 
at state 0 (low), the switch is in the OFF state. 
 A typical instantiation has the form tranif1 (s1, s2, c ); 
 Here c is the control line. If c=1, s1 and s2 are connected and signal 
transmission can be in either direction 
 rtranif1 is the resistive counterpart of tranif1.
tranif0 and rtranif0: 
 tranif0 and rtranif0 are again bi-directional switches. 
 The switch is OFF if the control line is in the 1 (high) state, and it is ON 
when the control line is in the 0 (low) state. 
 A typical instantiation has the form tranif0 (s1, s2, c); 
With the above instantiation, if c = 0, s1 and s2 are connected and signal 
transmission can be in either direction. 
 If c = 1, the switch is OFF and s1 and s2 are isolated from each other. 
rtranif0 is the resistive counterpart of tranif0.
Observations: 
With the bi-directional switches the signal on either side can be of input, 
output, or inout type. They can be nets or appearing as ports in the module. But 
the type declaration on the two sides has to be consistent. 
 In the above instantiation s1 can be an input port in a module. In that case, s2 
has to be a net forming an input to another instantiated module or circuit block. 
s2 can be of output or inout type also. But it cannot be another input port. 
ƒ s1 and s2 – both cannot be output ports. 
ƒ s1 and s2 – both can be inout ports. 
 With tran, tranif1, and tranif0 bi-directional switches if the input signal has 
strength supply1 (supply0), the output side signal has strength 
strong1 (strong0). 
 For all other strength values of the input signal, the strength value of the 
output side signal retains the strength of the input side signal. 
With rtran, rtranif1 and rtranif0 switches the output side signal strength is 
less than that of the input side signal.
Example 10.11 bus switching home work
Example 10.12 Another RAM Cell 
module ram_cell1(do,di,wr,rd,a_d); 
output do; 
input di,wr,rd,a_d; 
wire ddd,q,qb,wrb,rdb; 
not(rdb,rd),(wrb,wr); 
not(pull1,pull0)(q,qb),(qb,q); 
tranif1 g3(ddd,q,a_d); 
cmosg4(ddd,di,wr,wrb); 
cmos g5(do,ddd,rd,rdb); 
endmodule 
 When wr = 1, cmos gate g4 turns ON; the data at the input port di (with 
strength strong0 / strong1) are connected to q through ddd. It forces the 
latch to its state – since q has strength pull0 / pull1 only – di prevails 
here. This constitutes the write operation. 
 When rd = 1, cmos gate g5 turns ON. The net ddd is connected to the 
output net do. The data stored in the latch are made available at the output 
port do. This constitutes the read operation.
TIME DELAYS WITH SWITCH PRIMITIVES 
 The instantiation nmos g1 (out, in, ctrl ); 
Def: has no delay associated with it. 
The instantiation nmos (delay1) g2 (out, in, ctrl ); 
Def : has delay1 as the delay for the output to rise, fall, and turn OFF. 
 The instantiation nmos (delay_r, delay_f) g3 (out, in, ctrl ); 
Def : has delay_r as the rise-time for the output. delay_f is the fall-time for 
the output. The turn-off time is zero. 
 The instantiation nmos (delay_r, delay_f, delay_o) g4 (out, in, ctrl ); 
Def:has delay_r as the rise-time for the output. delay_f is the fall-time for the 
output delay_o is the time to turn OFF 
when the control signal ctrl goes from 0 to 1. Delays can be assigned to 
the other uni-directional gates (rcmos, pmos, rpmos, cmos, and 
rcmos) in a similar manner. 
Bi-directional switches do not delay transmission – their rise- and 
fall- times are zero. They can have only turn-on and turn-off delays 
associated with them. tran has no delay associated with it.
Contd.. 
 The instantiation tranif1 (delay_r, delay_f) g5 (out, in, ctrl ); 
Def: represents an instantiation of the controlled bi-directional switch. When 
control changes from 0 to 1, the switch turns on with a delay of delay_r. When 
control changes from 1 to 0, the switch turns off with a delay of delay_f. 
 The instantiation transif1 (delay0) g2 (out, in, ctrl ); 
Def: represents an instantiation with delay0 as the delay for the switch to 
turn on when control changes from 0 to 1, with the same delay for it to turn off 
when control changes from 1 to 0. When a delay value is not specified in an 
instantiation, the turn-on and turn-off are considered to be ideal that is, 
instantaneous. Delay values similar to the above illustrations can be associated 
with rtranif1, tranif0, and rtranif0 as well.
INSTANTIATIONS WITH STRENGTHS AND DELAYS 
 In the most general form of instantiation, strength values and delay values can 
be combined. 
 For example, the instantiation 
nmos (strong1, strong0) (delay_r, delay_f, delay_o ) gg (s1, s2, ctrl) ; 
 Means the following: 
x It has strength strong0 when in the low state and strength strong1when 
in the high state. 
x When output changes state from low to high, it has a delay time of 
delay_r. 
x When the output changes state from high to low, it has a delay time of 
delay_f. 
x When output turns-off it has a turn-off delay time of delay _o. 
rnmos, pmos, and rpmos switches too can be instantiated in the general 
form in the same manner. The general instantiation for the bi-directional 
gates too can be done similarly. 
10.7 STRENGTH CONTENTION WITH TRIREG NETS- Home work
There are many ways to generate clock in Verilog; you could use one of 
the following methods:

More Related Content

PDF
Smart traffic light controller using verilog
PPTX
PPTX
Encoders and decoders
PDF
A report on 2 to 1 mux using tg
PPTX
Microcontroller 8051 and its interfacing
PPTX
Architecture of 8051
PPTX
Fpga architectures and applications
PPT
8051 block diagram
Smart traffic light controller using verilog
Encoders and decoders
A report on 2 to 1 mux using tg
Microcontroller 8051 and its interfacing
Architecture of 8051
Fpga architectures and applications
8051 block diagram

What's hot (20)

PPTX
Verilog presentation final
PPTX
8051 Microcontroller ppt
DOC
PIC MICROCONTROLLERS -CLASS NOTES
PDF
Actel fpga
PPTX
Intel 8051 Programming in C
PPTX
MOS as Diode, Switch and Active Resistor
PPTX
Verilog Tutorial - Verilog HDL Tutorial with Examples
PPTX
Verilog operators.pptx
PDF
Overview of digital design with Verilog HDL
PPT
8051 Addressing Modes
PPT
VHDL-PRESENTATION.ppt
PPTX
Comparison between the FPGA vs CPLD
PPTX
Verilog
PDF
Instruction formats-in-8086
PPTX
faults in digital systems
PDF
Complex Programmable Logic Devices(CPLD) & Field Programmable Logic Devices (...
PPT
Schmitt trigger circuit
PPT
Architecture of 8086 Microprocessor
PPTX
TMS320C6X Architecture
Verilog presentation final
8051 Microcontroller ppt
PIC MICROCONTROLLERS -CLASS NOTES
Actel fpga
Intel 8051 Programming in C
MOS as Diode, Switch and Active Resistor
Verilog Tutorial - Verilog HDL Tutorial with Examples
Verilog operators.pptx
Overview of digital design with Verilog HDL
8051 Addressing Modes
VHDL-PRESENTATION.ppt
Comparison between the FPGA vs CPLD
Verilog
Instruction formats-in-8086
faults in digital systems
Complex Programmable Logic Devices(CPLD) & Field Programmable Logic Devices (...
Schmitt trigger circuit
Architecture of 8086 Microprocessor
TMS320C6X Architecture
Ad

Viewers also liked (19)

PDF
Delays in verilog
PPTX
Behavioral modelling in VHDL
DOCX
Half adder layout design
DOCX
Overview of verilog
PDF
Verilog tutorial
PPT
Crash course in verilog
PPT
L5 Adders
PPT
Verilog tutorial
PPTX
Basics of Vhdl
PDF
Bit Serial multiplier using Verilog
PPTX
Array multiplier
PPT
Behavioral modeling
PPTX
Verilog HDL
PPT
Mahatma gandhi ppt
PPTX
Wi fi technology ppt mine
PPT
Ppt mahatma gandhi
PPTX
Wi-Fi Technology
PPTX
Speed measurement, tachometer
PDF
W-LAN (Wireless Local Area Network)
Delays in verilog
Behavioral modelling in VHDL
Half adder layout design
Overview of verilog
Verilog tutorial
Crash course in verilog
L5 Adders
Verilog tutorial
Basics of Vhdl
Bit Serial multiplier using Verilog
Array multiplier
Behavioral modeling
Verilog HDL
Mahatma gandhi ppt
Wi fi technology ppt mine
Ppt mahatma gandhi
Wi-Fi Technology
Speed measurement, tachometer
W-LAN (Wireless Local Area Network)
Ad

Similar to Switch level modeling (20)

PDF
Lecture 2 verilog
PPTX
Domine specification section on VLSI.pptx
PPTX
Chapter 6: Sequential Logic
PDF
5. Latches and flip-flop do it fasrt f.pdf
PDF
sequential logic circuits- Latch & Flip Flop.pdf
PPTX
GROUP 4 DIGITAL elect S-R FLIP FLOP.pptx
PPTX
Ch18 "Case Study 3: DC-DC Power Converter"
DOCX
Introduction to Sequential DevicesChapter 66.1 M.docx
PPTX
2105_4_Logic of Latchessssssssssssss.pptx
PPTX
unit 5.pptx
PDF
Chapter 6 - Modelling and Control of Converters.pdf
PPT
PPT FINAL (1)-1 (1).ppt
PPTX
Sequential Circuits Digital Electronics.pptx
PPTX
Digital_Electronics_Module_4_Sequential_Circuits v0.6.pptx
PPT
8051 MMD Chapter 1.ppt
PPT
flip flop 13.ppt
PPT
Unit 3 - Styles of Modeling-1 for resource management techniques
PPTX
Flipflop
Lecture 2 verilog
Domine specification section on VLSI.pptx
Chapter 6: Sequential Logic
5. Latches and flip-flop do it fasrt f.pdf
sequential logic circuits- Latch & Flip Flop.pdf
GROUP 4 DIGITAL elect S-R FLIP FLOP.pptx
Ch18 "Case Study 3: DC-DC Power Converter"
Introduction to Sequential DevicesChapter 66.1 M.docx
2105_4_Logic of Latchessssssssssssss.pptx
unit 5.pptx
Chapter 6 - Modelling and Control of Converters.pdf
PPT FINAL (1)-1 (1).ppt
Sequential Circuits Digital Electronics.pptx
Digital_Electronics_Module_4_Sequential_Circuits v0.6.pptx
8051 MMD Chapter 1.ppt
flip flop 13.ppt
Unit 3 - Styles of Modeling-1 for resource management techniques
Flipflop

Recently uploaded (20)

PPTX
CONTRACTS IN CONSTRUCTION PROJECTS: TYPES
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PPTX
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
PPTX
Petroleum Refining & Petrochemicals.pptx
PDF
AIGA 012_04 Cleaning of equipment for oxygen service_reformat Jan 12.pdf
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PDF
electrical machines course file-anna university
PDF
[jvmmeetup] next-gen integration with apache camel and quarkus.pdf
PDF
LOW POWER CLASS AB SI POWER AMPLIFIER FOR WIRELESS MEDICAL SENSOR NETWORK
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PPTX
Amdahl’s law is explained in the above power point presentations
PDF
MLpara ingenieira CIVIL, meca Y AMBIENTAL
PPTX
Micro1New.ppt.pptx the mai themes of micfrobiology
PDF
Project_Mgmt_Institute_-Marc Marc Marc .pdf
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
PPTX
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
PDF
Design of Material Handling Equipment Lecture Note
PDF
Cryptography and Network Security-Module-I.pdf
PDF
Principles of operation, construction, theory, advantages and disadvantages, ...
CONTRACTS IN CONSTRUCTION PROJECTS: TYPES
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
A Brief Introduction to IoT- Smart Objects: The "Things" in IoT
Petroleum Refining & Petrochemicals.pptx
AIGA 012_04 Cleaning of equipment for oxygen service_reformat Jan 12.pdf
August -2025_Top10 Read_Articles_ijait.pdf
electrical machines course file-anna university
[jvmmeetup] next-gen integration with apache camel and quarkus.pdf
LOW POWER CLASS AB SI POWER AMPLIFIER FOR WIRELESS MEDICAL SENSOR NETWORK
Management Information system : MIS-e-Business Systems.pptx
distributed database system" (DDBS) is often used to refer to both the distri...
Amdahl’s law is explained in the above power point presentations
MLpara ingenieira CIVIL, meca Y AMBIENTAL
Micro1New.ppt.pptx the mai themes of micfrobiology
Project_Mgmt_Institute_-Marc Marc Marc .pdf
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
Design of Material Handling Equipment Lecture Note
Cryptography and Network Security-Module-I.pdf
Principles of operation, construction, theory, advantages and disadvantages, ...

Switch level modeling

  • 1. Switch level modeling - chapter 10 – padmanabhan book P Devi Pradeep  Designers familiar with logic gates and their configurations at the circuit level may choose to do their designs using MOS transistors.  Verilog has the provision to do the design description at the switch level using such MOS transistors, which is the theme of the present chapter.  Switch level modeling forms the basic level of modeling digital circuits  The switches are available as an primitives in Verilog; they are central to design description at this level.  Basic gates can be defined in terms of such switches. By repeated and successive instantiation of such switches, more involved circuits can be modeled – on the same lines as was done with the gate level primitives in Chapters 4 and 5.
  • 3. Basic Switch Primitives:  Different switch primitives are available in Verilog. Consider an nmos switch. A typical instantiation has the form nmos (out, in, control); pmos (out, in, control);
  • 4. Observations:  When in the on state, the switch makes its output available at the same strength as the input.  There is only one exception to it: When the input is of strength supply, the output is of strength strong. It is true of supply1 as well as supply0.  When instantiating an nmos or a pmos switch, a name can be assigned to the switch. But the name is not essential. (The same is true of the other primitives discussed in the following sections as well.)  The nmos and pmos switches function as unidirectional switches.
  • 5. Resistive Switches:  nmos and pmos represent switches of low impedance in the on-state. rnmos and rpmos represent the resistive counterparts of these respectively.  Typical instantiations have the form rnmos (output1, input1, control1); rpmos (output2, input2, control2);  With rnmos if the control1 input is at 1 (high) state, the switch is ON and functions as a definite resistance. It connects input1 to output1 through a resistance. When control1 is at the 0 (low) state, the switch is OFF and leaves output1 floating. The set of output values for all combinations of input1 andcontrol1 values remain identical to those of the nmos switch given in Table .  The rpmos switch is ON when control2 is at 0 (low) state. It inserts a definite resistance between the input and the output signals but retains the signal value. The output values for different input values remain identical to those in Table for the pmos switch.
  • 7. Example 10.1 home work module swt_aa (o1,o2,a1,a2,b1,b2,c1,c2); output o1,o2; input a1,a2,b1,b2,c1,c2; wire o2; tri1 o1; bufif1 ctt1(o1,a1,c1), ctt2(o1,a2,c2); bufif1 (weak1, weak0) ctp1(o2,b1,c1),ctp2(o2,b2,c2); pullup pp(o2); endmodule
  • 8. CMOS inverter: module inv (in, out ); output out; input in; supply0 a; supply1 b; nmos (out, a, in ); pmos (out, b, in); endmodule
  • 9. module npnor_2(out, in1, in2 ); output out; input in1, in2; supply1 a; supply0 c; wire b; pmos(b, a, in2), (out, b, in1); nmos (out, c, in1), (out, c, in2) ; endmodule * Here do some another examples like orgate nandgate and andgates….
  • 10. NMOS Inverter with Pull up Load: module NMOSinv(out,in); output out; Input in; supply0 a; pullup (out); nmos(out,a,in); endmodule module tst_nm_in(); reg in;wire out; NMOSinv nmv(out,in); initial in =1'b1; always #3 in =~in; initial $monitor($time , " in = %b, output = %b ",in,out); initial #30 $stop; endmodule
  • 11. An NMOS Three Input NOR Gate: module nor3NMOS(in1,in2,in3,b); output b; input in1,in2,in3; supply0 a; wire b; nmos(b,a,in1),(b,a,in2),(b,a,in3); pullup(b); endmodule
  • 12. CMOS SWITCH: x N_control turns ON the NMOS transistor and keeps it ON when it is in the 1 state. x P_control turns ON the PMOS transistor and keeps it ON when it is in the 0 state. The CMOS switch is instantiated as shown below. cmos csw (out, in, N_control, P_control ); Significance of the different terms is as follows: x cmos:The keyword for the switch instantiation x csw: Name assigned to the switch in the instantiation x out: Name assigned to the output variable in the instantiation x in: Name assigned to the input variable in the instantiation x N_control: Name assigned to the control variable of the NMOS transistor in the instantiation x P_control: Name assigned to the control variable of the PMOS transistor in the instantiation
  • 13. Example 10.6 CMOS Switch – 1 module CMOSsw(out,in,n_ctr,p_ctr); output out; input in,n_ctr,p_ctr; nmos gn(out,in,n_ctr); pmos gp(out,in,p_ctr); endmodule module tst_CMOSsw(); reg in,n_ctr,p_ctr; wire out; CMOSsw cmsw(out,in,n_ctr,p_ctr); initial begin in=1'b0;n_ctr=1'b1;p_ctr=~n_ctr; end always #5 in =~in; always begin #3 n_ctr=~n_ctr; #0p_ctr =~n_ctr; end initial $monitor($time , "in = %b , n_ctr = %b , p_ctr = %b , output = %b ",in,n_ctr,p_ctr,out); initial #39 $ # 0in = 0 , n_ctr = 1 , p_ctr = 0 , output = 0 # 3in = 0 , n_ctr = 0 , p_ctr = 1 , output = z # 5in = 1 , n_ctr = 0 , p_ctr = 1 , output = z # 6in = 1 , n_ctr = 1 , p_ctr = 0 , output = 1 # 9in = 1 , n_ctr = 0 , p_ctr = 1 , output = z # 10in = 0 , n_ctr = 0 , p_ctr = 1 , output = z # 12in = 0 , n_ctr = 1 , p_ctr = 0 ,output = 0
  • 14. Example 10.7 CMOS Switch – 2: module CMOSsw1(out,in,con); output out; input in,con; wire p_ctr; not gn(p_ctr,con); cmos gc(out,in,con,p-ctr); endmodule module tst_CMOSsw1(); reg in,con; wire out; CMOSsw1 cmsw(out,in,con); initial begin in=1'b0;con=1'b1; end always #5 in =~in; always #3 con=~con; initial $monitor($time , "in = %b , con = %b , output = %b " ,in,con,out); initial #40 $stop; endmodule
  • 15. Example 10.8: A RAM Cell  Figure shows a basic ram cell with facilities for writing data, storing data, and reading data.  When switch sw2 is on, qb – the output of inverter g1 – forms the input to the inverter g2 and vice versa. The g1-g2 combination functions as a latch and freezes the last state entry before sw2 turns on.  When wsb (write/store) is high, switch sw1 is ON, and switch sw2 OFF. With sw1 on, input Din is connected to the input of gate g1 and remains so connected. When wsb goes low, din is isolated, since sw1 is OFF. But sw2 is ON and the data remains latched in the latch formed by g1-g2. In other words the data Din is stored in the RAM cell formed by g1-g2.  When RD (Read) goes active (=1), the latched state is available as output Do. Reading is normally done when the latch is in the stored state.
  • 16. module csw(out,in,n_ctr); output out; input in,n_ctr; wire p_ctr; assign p_ctr =~n_ctr; cmos csw(out,in,n_ctr,p_ctr); endmodule module ram_cell(do,din,wsb,rd); output do; input din,wsb,rd; wire sb; wire q,qq; tri do; csw sw1(q,din,wsb),sw2(q,qq,sb),sw3(do,q,rd); not n1(sb,wsb),n2(qb,q),n3(qq,qb); endmodule
  • 17. An Alternate RAM Cell Realization module ram1(do,din,wr,rd); output do; input din,wr,rd; wire qb,q; tri do; scw sww(q,din,wr),swr(do,q,rd); not(pull1,pull0)n1(qb,q),n2(q,q); endmodule module scw(out,in,n_ctr); output out; input in,n_ctr; wire p_ctr; assign p_ctr =~n_ctr; cmos sw(out,in,n_ctr,p_ctr); endmodule
  • 18. A Dynamic Shift Register: The shift register can be modified to suit a variety of needs: ---------Dynamic logic incorporating NAND / NOR gates. ---- Dynamic RAM with row and column select lines and refresh functions. ----- A shift register to function as a right- or a left-shift-type shift register; a direction select bit can be used to alter the shift direction.
  • 19. module shreg1(dout,din,phi1); output dout; input din,phi1; wire phi2; trireg[3:0] x,y; trireg dout; assign phi2=~phi1; cmos switch0(x[0],din,phi1,phi2), switch1(x[1],y[0],phi2,phi1), switch2(x[2],y[1],phi1,phi2), switch3(x[3],y[2],phi2,phi1), switch4(dout,y[3],phi1,phi2); cell cc0(y[0],x[0]), cc1(y[1],x[1]), cc2(y[2],x[2]), cc3(y[3],x[3]); endmodule module cell(op,ip); output op; input ip; supply1 pwr; supply0 gnd; nmos(op,gnd,ip); pmos(op,pwr,ip); endmodule
  • 20. BI-DIRECTIONAL GATES:  The gates discussed so far (nmos, pmos, rnmos, rpmos, rcmos) are all unidirectional gates.  When turned ON, the gate establishes a connection and makes the signal at the input side available at the output side.  Verilog has a set of primitives for bi-directional switches as well. They connect the nets on either side when ON and isolate them when OFF.  The signal flow can be in either direction.  None of the continuous-type assignments at higher levels dealt with so far has a functionality equivalent to the bi-directional gates. There are six types of bidirectional gates. tran , rtran , tranif1, and rtranif1 tranif0 and rtranif0
  • 21. tran and rtran:  The tran gate is a bi-directional gate of two ports. When instantiated, it connects the two ports directly.  Thus the instantiation tran (s1, s2);  connects the signal lines s1 and s2. Either line can be input, inout or output. rtran is the resistive counterpart of tran. tranif1 and rtranif1:  tranif1 is a bi-directional switch turned ON/OFF through a control line. It is in the ON-state when the control signal is at 1 (high) state. When the control line is at state 0 (low), the switch is in the OFF state.  A typical instantiation has the form tranif1 (s1, s2, c );  Here c is the control line. If c=1, s1 and s2 are connected and signal transmission can be in either direction  rtranif1 is the resistive counterpart of tranif1.
  • 22. tranif0 and rtranif0:  tranif0 and rtranif0 are again bi-directional switches.  The switch is OFF if the control line is in the 1 (high) state, and it is ON when the control line is in the 0 (low) state.  A typical instantiation has the form tranif0 (s1, s2, c); With the above instantiation, if c = 0, s1 and s2 are connected and signal transmission can be in either direction.  If c = 1, the switch is OFF and s1 and s2 are isolated from each other. rtranif0 is the resistive counterpart of tranif0.
  • 23. Observations: With the bi-directional switches the signal on either side can be of input, output, or inout type. They can be nets or appearing as ports in the module. But the type declaration on the two sides has to be consistent.  In the above instantiation s1 can be an input port in a module. In that case, s2 has to be a net forming an input to another instantiated module or circuit block. s2 can be of output or inout type also. But it cannot be another input port. ƒ s1 and s2 – both cannot be output ports. ƒ s1 and s2 – both can be inout ports.  With tran, tranif1, and tranif0 bi-directional switches if the input signal has strength supply1 (supply0), the output side signal has strength strong1 (strong0).  For all other strength values of the input signal, the strength value of the output side signal retains the strength of the input side signal. With rtran, rtranif1 and rtranif0 switches the output side signal strength is less than that of the input side signal.
  • 24. Example 10.11 bus switching home work
  • 25. Example 10.12 Another RAM Cell module ram_cell1(do,di,wr,rd,a_d); output do; input di,wr,rd,a_d; wire ddd,q,qb,wrb,rdb; not(rdb,rd),(wrb,wr); not(pull1,pull0)(q,qb),(qb,q); tranif1 g3(ddd,q,a_d); cmosg4(ddd,di,wr,wrb); cmos g5(do,ddd,rd,rdb); endmodule  When wr = 1, cmos gate g4 turns ON; the data at the input port di (with strength strong0 / strong1) are connected to q through ddd. It forces the latch to its state – since q has strength pull0 / pull1 only – di prevails here. This constitutes the write operation.  When rd = 1, cmos gate g5 turns ON. The net ddd is connected to the output net do. The data stored in the latch are made available at the output port do. This constitutes the read operation.
  • 26. TIME DELAYS WITH SWITCH PRIMITIVES  The instantiation nmos g1 (out, in, ctrl ); Def: has no delay associated with it. The instantiation nmos (delay1) g2 (out, in, ctrl ); Def : has delay1 as the delay for the output to rise, fall, and turn OFF.  The instantiation nmos (delay_r, delay_f) g3 (out, in, ctrl ); Def : has delay_r as the rise-time for the output. delay_f is the fall-time for the output. The turn-off time is zero.  The instantiation nmos (delay_r, delay_f, delay_o) g4 (out, in, ctrl ); Def:has delay_r as the rise-time for the output. delay_f is the fall-time for the output delay_o is the time to turn OFF when the control signal ctrl goes from 0 to 1. Delays can be assigned to the other uni-directional gates (rcmos, pmos, rpmos, cmos, and rcmos) in a similar manner. Bi-directional switches do not delay transmission – their rise- and fall- times are zero. They can have only turn-on and turn-off delays associated with them. tran has no delay associated with it.
  • 27. Contd..  The instantiation tranif1 (delay_r, delay_f) g5 (out, in, ctrl ); Def: represents an instantiation of the controlled bi-directional switch. When control changes from 0 to 1, the switch turns on with a delay of delay_r. When control changes from 1 to 0, the switch turns off with a delay of delay_f.  The instantiation transif1 (delay0) g2 (out, in, ctrl ); Def: represents an instantiation with delay0 as the delay for the switch to turn on when control changes from 0 to 1, with the same delay for it to turn off when control changes from 1 to 0. When a delay value is not specified in an instantiation, the turn-on and turn-off are considered to be ideal that is, instantaneous. Delay values similar to the above illustrations can be associated with rtranif1, tranif0, and rtranif0 as well.
  • 28. INSTANTIATIONS WITH STRENGTHS AND DELAYS  In the most general form of instantiation, strength values and delay values can be combined.  For example, the instantiation nmos (strong1, strong0) (delay_r, delay_f, delay_o ) gg (s1, s2, ctrl) ;  Means the following: x It has strength strong0 when in the low state and strength strong1when in the high state. x When output changes state from low to high, it has a delay time of delay_r. x When the output changes state from high to low, it has a delay time of delay_f. x When output turns-off it has a turn-off delay time of delay _o. rnmos, pmos, and rpmos switches too can be instantiated in the general form in the same manner. The general instantiation for the bi-directional gates too can be done similarly. 10.7 STRENGTH CONTENTION WITH TRIREG NETS- Home work
  • 29. There are many ways to generate clock in Verilog; you could use one of the following methods: