Submit Search
Verilog Coding examples of Digital Circuits
0 likes
19 views
Jason J Pulikkottil
Verilog Coding examples of Digital Circuits
Engineering
Read more
1 of 32
Download now
Download to read offline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
More Related Content
More from Jason J Pulikkottil
(20)
PDF
Floorplanning Power Planning and Placement
Jason J Pulikkottil
PDF
Digital Electronics Questions and Answers
Jason J Pulikkottil
PDF
Different Types Of Cells, Types of Standard Cells
Jason J Pulikkottil
PDF
DFT Rules, set of rules with illustration
Jason J Pulikkottil
PDF
Clock Definitions Static Timing Analysis for VLSI Engineers
Jason J Pulikkottil
PDF
Basic Synthesis Flow and Commands, Logic Synthesis
Jason J Pulikkottil
PDF
ASIC Design Types, Logical Libraries, Optimization
Jason J Pulikkottil
PDF
Floorplanning and Powerplanning - Definitions and Notes
Jason J Pulikkottil
PDF
Physical Design Flow - Standard Cells and Special Cells
Jason J Pulikkottil
PDF
Physical Design - Import Design Flow Floorplan
Jason J Pulikkottil
PDF
Physical Design-Floor Planning Goals And Placement
Jason J Pulikkottil
PDF
Short Notes on Verilog and SystemVerilog
Jason J Pulikkottil
PDF
VLSI Design Partitioning - Very Large Scale Integration - Practical Problems
Jason J Pulikkottil
PDF
VLSI Design Flow - Very Large Scale Integration
Jason J Pulikkottil
PDF
Switched Reluctance Motor - Principle Of Operation
Jason J Pulikkottil
PDF
Variable Frequency Induction Motor Drives
Jason J Pulikkottil
PDF
Speed Control Of Synchronous Motor - Synchronous Reluctance Motor
Jason J Pulikkottil
PDF
Solar PV Systems For Household Applications
Jason J Pulikkottil
PDF
Satellite Communication - Satellite Technology
Jason J Pulikkottil
PDF
Reluctance Motor - Principle Of Operation
Jason J Pulikkottil
Floorplanning Power Planning and Placement
Jason J Pulikkottil
Digital Electronics Questions and Answers
Jason J Pulikkottil
Different Types Of Cells, Types of Standard Cells
Jason J Pulikkottil
DFT Rules, set of rules with illustration
Jason J Pulikkottil
Clock Definitions Static Timing Analysis for VLSI Engineers
Jason J Pulikkottil
Basic Synthesis Flow and Commands, Logic Synthesis
Jason J Pulikkottil
ASIC Design Types, Logical Libraries, Optimization
Jason J Pulikkottil
Floorplanning and Powerplanning - Definitions and Notes
Jason J Pulikkottil
Physical Design Flow - Standard Cells and Special Cells
Jason J Pulikkottil
Physical Design - Import Design Flow Floorplan
Jason J Pulikkottil
Physical Design-Floor Planning Goals And Placement
Jason J Pulikkottil
Short Notes on Verilog and SystemVerilog
Jason J Pulikkottil
VLSI Design Partitioning - Very Large Scale Integration - Practical Problems
Jason J Pulikkottil
VLSI Design Flow - Very Large Scale Integration
Jason J Pulikkottil
Switched Reluctance Motor - Principle Of Operation
Jason J Pulikkottil
Variable Frequency Induction Motor Drives
Jason J Pulikkottil
Speed Control Of Synchronous Motor - Synchronous Reluctance Motor
Jason J Pulikkottil
Solar PV Systems For Household Applications
Jason J Pulikkottil
Satellite Communication - Satellite Technology
Jason J Pulikkottil
Reluctance Motor - Principle Of Operation
Jason J Pulikkottil
Verilog Coding examples of Digital Circuits
1.
H A L F A D D E R mo d u l e h a ( A , B , S u m, C a r r y ) ; i n p u t A , B ; o u t p u t S u m, C a r r y ; a s s i g nS u m= A ^ B ; a s s i g nC a r r y = A & B ; e n d mo d u l e
2.
F U L L A D D E R mo d u l e h a ( A , B , C , S u m, C a r r y ) ; i n p u t A , B , C ; o u t p u t S u m, C a r r y ; a s s i g nS u m= A ^ B ^ C ; a s s i g nC a r r y = ( A & B ) | ( B & C ) | ( C & A ) ; e n d mo d u l e
3.
H A L F S U B T R A C T O R mo d u l e h a ( A , B , D i f f e r e n c e , B o r r o w ) ; i n p u t A , B ; o u t p u t D i f f e r e n c e , B o r r o w ; a s s i g nD i f f e r e n c e = A ^ B ; a s s i g nB o r r o w =~ A & B ; e n d mo d u l e
4.
F U L L S U B T R A C T O R mo d u l e h a ( A , B , C , D i f f e r e n c e , B o r r o w ) ;
5.
i n p u t A , B , C ; o u t p u t D i f f e r e n c e , B o r r o w ; a s s i g nD i f f e r e n c e = A ^ B ^ C ; a s s i g nB o r r o w =( ~ A & B ) | ( B & C ) | ( C & ~ A ) ; e n d mo d u l e 4 : 1MU L T I P L E X E R
6.
mo d u l e m3 1 ( o u t , i n 0 , i n 1 , i n 2 , i n 3 , s 0 , s 1 ) ; o u t p u t o u t ; / / o u t p u t p o r t i n p u t i n 0 , i n 1 , i n 2 , i n 3 ; / / I n p u t p o r t s i n p u t s 0 , s 1 ; / / I n p u t p o r t s : s e l e c t l i n e s w i r e i n v 0 , i n v 1 ; / / I n v e r t e r O u t p u t s w i r e a 0 , a 1 , a 2 , a 3 ; / / A N Dg a t e o u t p u t s n o t n o t _ 0 ( i n v 0 , s 0 ) ; n o t n o t _ 1 ( i n v 1 , s 1 ) ; a n da n d _ 0 ( a 0 , i n 0 , i n v 0 , i n v 1 ) ; a n da n d _ 1 ( a 1 , i n 1 , i n v 0 , s 1 ) ; a n da n d _ 2 ( a 2 , i n 2 , s 0 , i n v 1 ) ; a n da n d _ 3 ( a 3 , i n 3 , s 0 , s 1 ) ; o r o r _ 0 ( o u t , a 0 , a 1 , a 2 , a 3 ) ; e n d mo d u l e
7.
D E MU L T I P L E X E R
8.
mo d u l e p r o( o u t p u t r e g[ 3 : 0 ] Y , i n p u t [ 1 : 0 ] A , i n p u t d i n ) ; a l w a y s @( Y , A ) b e g i n c a s e ( A ) 2 ' b 0 0: b e g i nY [ 0 ] =d i n ; Y [ 3 : 1 ] =0 ; e n d 2 ' b 0 1: b e g i nY [ 1 ] =d i n ; Y [ 0 ] =0 ;e n d 2 ' b 1 0: b e g i nY [ 2 ] =d i n ; Y [ 1 : 0 ] =0 ; e n d 2 ' b 1 1: b e g i nY [ 3 ] =d i n ; Y [ 2 : 0 ] =0 ; e n d e n d c a s e e n d
9.
e n d mo d u l e E N C O D E R
10.
mo d u l e p r i o r i t y e n c ( e n , i , y ) ; i n p u t e n ; i n p u t [ 3 : 0 ] i ; o u t p u t [ 1 : 0 ] y ; a s s i g ny [ 1 ] = i [ 2 ] | i [ 3 ] & e n ; a s s i g ny [ 0 ] = i [ 1 ] | i [ 3 ] & e n ; e n d mo d u l e
11.
D E C O D E R mo d u l e d e c o d e ( e n , s , y ) ; i n p u t e n ; i n p u t [ 1 : 0 ] s ; o u t p u t [ 3 : 0 ] y ;
12.
a s s i g ny [ 0 ] = ( ~ s [ 1 ] ) & ( ~ s [ 0 ] ) & e n ; a s s i g ny [ 1 ] = ( ~ s [ 1 ] ) & ( s [ 0 ] ) & e n ; a s s i g ny [ 2 ] = ( s [ 1 ] ) & ( ~ s [ 0 ] ) & e n ; a s s i g ny [ 3 ] = ( s [ 1 ] ) & ( s [ 0 ] ) & e n ; e n d mo d u l e 2b i t MA G N I T U D EC O MP A R A T O R
13.
mo d u l e p r o ( p , q , r , a , b ) ; i n p u t [ 1 : 0 ] a ; i n p u t [ 1 : 0 ] b ; o u t p u t r e gp , q , r ; a l w a y s @( a o r b ) b e g i n i f ( a = = = b ) { p , q , r } = 1 ' b 0 0 1 ; e l s e i f ( a > b ){ p , q , r } = 3 ' b 1 0 0 ; e l s e i f ( a < b ){ p , q , r } = 3 ' b 0 1 0 ; e n d e n d mo d u l e
14.
S RF L I PF L O P mo d u l e p r o ( s , r , c l k , c l e a r , q , q b a r ) ; i n p u t s , r , c l k , c l e a r ; o u t p u t r e gq , q b a r ; a l w a y s @( p o s e d g e c l k ) b e g i n i f ( c l e a r ) b e g i n q = 0 ; q b a r = 1 ; e n d e l s e b e g i n
15.
i f ( s ! = r ) b e g i n q = s ; q b a r = r ; e n d e l s e i f ( s = = 1 & & r = = 1 ) b e g i n q = 1 ' b z ; q b a r = 1 ' b z ; e n d e n d e n d e n d mo d u l e
17.
D F F mo d u l e p r o ( d , c l k , c l e a r , q , q b a r ) ; i n p u t d , c l k , c l e a r ; o u t p u t r e gq , q b a r ; a l w a y s @( p o s e d g e c l k ) b e g i n i f ( c l e a r = = 1 ) b e g i n
18.
q = 0 ; q b a r = 1 ; e n d e l s e b e g i n q = d ; q b a r = ! d ; e n d e n d e n d mo d u l e
19.
J KF L I PF L O P mo d u l e p r o ( i n p u t j , k , c l k , o u t p u t r e g q , o u t p u t q _ b ) ; a s s i g nq _ b = ~ q ; a l w a y s @( p o s e d g e c l k )
20.
c a s e ( { j , k } ) 2 ' b 0 0 : q < = q ; 2 ' b 0 1 : q < = 1 ' b 0 ; 2 ' b 1 0 : q < = 1 ' b 1 ; 2 ' b 1 1 : q < = ! q ; e n d c a s e e n d mo d u l e S Y N C H R O N O U SC O U N T E R mo d u l ec o u n t e r ( c l k , r s t , c o u n t ) ; i n p u t c l k , r s t ; o u t p u t r e g [ 2 : 0 ] c o u n t ;
21.
a l w a y s @( p o s e d g e c l k ) b e g i n i f ( r s t = = 1 ) b e g i n c o u n t = 0 ; e n d e l s e b e g i n c o u n t = c o u n t + 1 ; e n d e n d e n d mo d u l e
22.
T F F mo d u l e p r o ( t , c l k , c l e a r , q , q b a r ) ; i n p u t t , c l k , c l e a r ; o u t p u t r e gq , q b a r ;
23.
a l w a y s @( p o s e d g e c l k ) b e g i n i f ( c l e a r = = 1 ) b e g i n q = 0 ; q b a r = 1 ; e n d e l s e i f ( t = = 1 ) b e g i n q = ~ q b a r ; e n d e l s e b e g i n q = q ; e n d q b a r = ~ q ; e n d e n d mo d u l e
24.
R I P P L EC O U N T E R mo d u l e e x p o ( c l k , c o u n t ) ;
25.
i n p u t c l k ; o u t p u t [ 3 : 0 ] c o u n t ; r e g [ 3 : 0 ] c o u n t ; w i r e c l k ; i n i t i a l c o u n t = 4 ' b 0 0 0 0 ; a l w a y s @( n e g e d g e c l k ) c o u n t [ 0 ] < = ~ c o u n t [ 0 ] ; a l w a y s @( n e g e d g e c o u n t [ 0 ] ) c o u n t [ 1 ] < = ~ c o u n t [ 1 ] ; a l w a y s @( n e g e d g e c o u n t [ 1 ] ) c o u n t [ 2 ] < = ~ c o u n t [ 2 ] ; a l w a y s @( n e g e d g e c o u n t [ 2 ] ) c o u n t [ 3 ] < = ~ c o u n t [ 3 ] ; e n d mo d u l e
26.
S I S OS h i f t r e g i s t e r mo d u l e e x p o( i n p u t c l k , c l e a r , s i , o u t p u t r e g [ 3 : 0 ] s o ) ; r e g[ 3 : 0 ] t mp ;
27.
a l w a y s @( p o s e d g e c l k ) b e g i n i f ( c l e a r ) b e g i n t mp < = 4 ' b 0 0 0 0 ; e n d e l s e b e g i n t mp < = t mp < < 1 ; t mp [ 0 ] < = s i ; s o = t mp [ 3 ] ; e n d e n d e n d mo d u l e
28.
S I P O mo d u l e p r o p t ( c l k , c l e a r , s i , p o ) ; i n p u t c l k , s i , c l e a r ; o u t p u t [ 3 : 0 ] p o ; r e g[ 3 : 0 ] t mp ;
29.
r e g[ 3 : 0 ] p o ; a l w a y s @( p o s e d g e c l k ) b e g i n i f ( c l e a r ) t mp < = 4 ' b 0 0 0 0 ; e l s e t mp < = t mp < < 1 ; t mp [ 0 ] < = s i ; p o = t mp ; e n d e n d mo d u l e
30.
P I P O mo d u l e p r o p y ( c l k , d , q ) ; i n p u t c l k ; i n p u t [ 3 : 0 ] d ; o u t p u t r e g[ 3 : 0 ] q ; a l w a y s @( p o s e d g e c l k ) b e g i n q [ 3 ] = d [ 3 ] ; q [ 2 ] = d [ 2 ] ;
31.
q [ 1 ] = d [ 1 ] ; q [ 0 ] = d [ 0 ] ; e n d e n d mo d u l e S E Q U E N C ED E T E C T O R
Download