100daysof RTL: Part-1 (Verilog)
100daysof RTL: Part-1 (Verilog)
100daysof RTL: Part-1 (Verilog)
RTL
Part-1(Verilog)
Ummidi Chandrika
WELCOME TO MY 100DAYSOFRTL
HERE IS THE LIST OF DAY WISE RTL CODES:
DAY 1 : CLOCK DIVIDER
DAY 2 : JOHNSON COUNTER
DAY 3: RING COUNTER
DAY 4: 5 INPUT MAJORITY CIRCUIT
DAY 5: PARITY GENERATOR
DAY 6: BINARY TO ONE HOT ENCODER
DAY 7: 4-BIT BCD SYNCHRONOUS COUNTER
DAY 8: 4-BIT CARRY LOOKAHEAD ADDER
DAY 9: N-BIT COMPARATOR
DAY 10: SERIAL IN SERIAL OUT SHIFT REGISTER
DAY 11: SERIAL IN PARALLEL OUT SHIFT REGISTER
DAY 12: PARALLEL IN PARALLEL OUT REGISTER
DAY 13: PARALLEL IN SERIAL OUT REGISTER
DAY 14: BIDIRECTION SHIFT REGISTER
DAY 15: PRBS SEQUENCE GENERATOR
DAY 16: 8-BIT SUBTRACTOR
DAY 17: 8-BIT ADDER/SUBTRACTOR
DAY 18: 4-BIT MULTIPLIER
DAY 19: FIXED POINT DIVISION
DAY 20: MASTER SLAVE JK FLIP FLOP
DAY 21: POSITIVE EDGE DETECTOR
DAY 22: BCD ADDER
DAY 23: 4-BIT CARRY SELECT ADDER
DAY 24: MOORE FSM 1010 SEQUENCE DETECTOR
DAY 25: N:1 MUX
DAY 26: BCD TIMECOUNT
DAY 27: 3-1 MUX
DAY 28: BCD TO SEVEN SEGMENT DISPLAY
DAY 29: D LATCH USING 2:1 MUX
DAY 30: 8-BIT BARREL SHIFTER
DAY 31: 1-BIT COMPARATOR USING 4X1 MUX
DAY 32: LOGICAL, ALGEBRAIC, AND ROTATE
SHIFT OPERATIONS
DAY 33: ALU
DAY 34: 4-BIT ASYNCHRONOUS DOWN
COUNTER
DAY 35: MOD-N UPDOWN COUNTER
DAY 36: UNIVERSAL BINARY COUNTER
DAY 37: UNIVERSAL SHIFT REGISTER
DAY 38: CN( CHANGE-NO CHANGE FLIPFLOP)
USING 2:1 MUX
DAY 39: FREQUENCY DIVIDER BY ODD
NUMBERS
DAY 40: GREATEST COMMON DIVISOR USING
BEHAVIOURAL MODELLING
DAY 41: GREATEST COMMON DIVISOR VIA FSM
DAY 42: SINGLE PORT RAM
DAY 43: DUAL PORT RAM
DAY 44: CLOCK BUFFER
DAY 45: SYNCHRONOUS FIFO
DAY 46: PRIORITY ENCODER
DAY 47: SEVEN SEGMENT DISPLAY USING ROM
DAY 48: SERIAL ADDER
DAY 49: FIXED PRIORITY ARBITER
DAY 50: ROUND ROBIN ARBITER
Ummidi Chandrika
Part-1 (Verilog)
1
Ummidi Chandrika
2
Ummidi Chandrika
RTL Code:
3
Ummidi Chandrika
RTL Code:
4
Ummidi Chandrika
RTL Code:
5
Ummidi Chandrika
determined count with an applied clock signal. When the count reaches the
predetermined count value, it resets all the flip-flops and starts to count again from 0.
This type of counter is designed by using 4 JK flip flops and counts from 0 to 9, and the
result is represented in digital form. After reaching the count of 9 (1001), it resets and
starts again.
RTL Code:
6
Ummidi Chandrika
carry logic over fixed groups of bits of the adder is reduced to two-level logic.
7
Ummidi Chandrika
8
Ummidi Chandrika
RTL Code:
9
Ummidi Chandrika
one bit of data. Unlike PIPO shift registers, which offer parallel input and output, a
PISO shift register accepts data in parallel and outputs it sequentially, or serially. It is
parallel data storage register. To store 'n' bit; number of clock pulse required is equal to
1.
• To provide serial data as output, number of clock pulse needed are equal to '(n-1)'.
right or left, depending on the mode selected.Dir control line is made either low or high
10
Ummidi Chandrika
RTL Code:
11
Ummidi Chandrika
RTL Code:
The advantage of 2’s complement over 1’s complement is that if any carry remains after
addition then there is no any need to add that carry in the end results.whereas in the
case of 1’s comement whenever carry remains after addition then it means that the
result is positive and the final result will be obtained by adding 1 in the result.
12
Ummidi Chandrika
RTL Code:
13
Ummidi Chandrika
from the partial remainder. This determines the relative magnitudes of the divisor and
partial remainder. If the carry-out = 0, then the partial remainder is restored to its
previous value by adding the divisor to the partial remainder. If the carry-out = 1, then
there is no restore operation. The partial remainder (high-order half of the dividend)
and the low-order half of the dividend are then shifted left one bit position and the
14
Ummidi Chandrika
RTL Code:
15
Ummidi Chandrika
changes from 0 to 1. The idea behind a Positive Edge Detector is to delay original clock
signal by one clock cycle, take its inverse and perform a logical AND with the original
signal.
16
Ummidi Chandrika
The BCD-Adder is used in the computers and the calculators that perform arithmetic
operation directly in the decimal number system. The BCD-Adder accepts the binary-
coded form of decimal numbers. The output will vary from 0 to 18 if we are not
considering the carry from the previous sum. But if we are considering the carry, then
the maximum value of output will be 19 (i.e. 9+9+1 = 19). When we are simply adding
17
Ummidi Chandrika
A and B, then we get the binary sum. Here, to get the output in BCD form, we will use
BCD Adder.
RTL Code:
18
Ummidi Chandrika
binary numbers and outputs their N-bit binary sum and a 1-bit carry.The idea behind a
N-bit carry select adder is to avoid propagating the the carry from bit to bit in sequence.
If we have two adders in parallel: one with a carry input of 0, the other with a carry
input of 1, then we could use the actual carry input generated to select between the
outputs of the two parallel adders. This means all adders could be performing their
calculations in parallel. Having two adders for each result bit is quite wasteful so we
could configure the N-bit adder to use 2*N/M-1 M-bit ripple carry adders in parallel.
Note that the adder for the least significant bits will always have a carry input of 0 so no
19
Ummidi Chandrika
20
Ummidi Chandrika
21
Ummidi Chandrika
data that can be sent over the network within certain amount of time and bandwidth.
RTL Code:
Day 26: Write RTL code for a BCD counter that displays time in a 24hr
format as shown here HH:MM:SS with the following specification
details:
I. Input Clock Frequency is 1Hz
II. Inputs: clock (posedge ), reset(Active high synchronous)
III. Outputs: ms_hr<3:0>, ls_hr<3:0>, ms_min<3:0>, ls_min<3:0>,
ms_sec<3:0>, ls_sec<3:0>
22
Ummidi Chandrika
23
Ummidi Chandrika
compatible can be done easily in Verilog. There are many applications that can require
24
Ummidi Chandrika
25
Ummidi Chandrika
input that specifies the number of bit positions that it shifts by. A barrel shifter is
positions for different values of k .A barrel shifter is able to complete the shift in a single
clock cycle, giving it a great advantage over a simple shifter which can shift n bits in n
clock cycles. It is used in conjunction with a processor's arithmetic logic unit (ALU) or
26
Ummidi Chandrika
27
Ummidi Chandrika
RTL Code:
28
Ummidi Chandrika
RTL Code:
29
Ummidi Chandrika
1- Subtraction
2-Multiplication
3-And operation
4-Or operation
5-Not operation
6-Xor operation
7-Xnor operation
RTL Code:
30
Ummidi Chandrika
31
Ummidi Chandrika
32
Ummidi Chandrika
RTL Code:
33
Ummidi Chandrika
RTL Code:
34
Ummidi Chandrika
Day 38: CN- Flipflop (Change -No Change Flip Flop) using DFF and 2:1 Mux
In C-N (Change – No change) flip-flop, there won’t be any change in output as long as
N is 0, irrespective of C. If N=1, then if C=0 output will change to 0 else if C=1 output
will be the compliment of previous output. Design C-N flip-flop using D flip flop and
minimum number of 2 x 1 multiplexer. The characteristic table and design of the above
35
Ummidi Chandrika
RTL Code:
Day 39: Frequency Divider by any Odd Number (Here I Used N=5)
Frequency or clock dividers are among the most common circuits used in digital
systems. Things get a little more complicated when we try to divide the frequency by an
odd number, since we can't simply divide the number of input clock cycles by 2. If we
observe the timing diagram describing a frequency divider by 5 in below figure , it give
the output with 50% Duty Cycle.
36
Ummidi Chandrika
RTL Code:
37
Ummidi Chandrika
Let's overcome the limitation of this Non-Synthesizeable circuit in the next code.
RTL Code:
38
Ummidi Chandrika
Day 41: Greatest Common Divisor via Data Path and Controller
In previous code of Greatest Common Divisor using Behavioral Modelling , the main
drawback is Non-Synthesizeable circuit , hence we implemented it using via Data Path
and Controller circuit so that the circuit can be synthesized.
The design of the GCD calculator should be divided into 2 parts - a controller and a
datapath. The controller is an FSM which issues commands to the datapath based on the
current state and the external inputs. This can be a behavioral description. The datapath
contains a netlist of functional units like multiplexers, registers, subtractors and a
comparator. The Datapath does the actual GCD computation.
39
Ummidi Chandrika
40
Ummidi Chandrika
RTL Code:
41
Ummidi Chandrika
On the positive edge of the clock, when the write operation takes place, if port enable 1
is high , the the data is written into port 1 and if port 0 enable is high, data written into
port 0.But the read operation happens asynchronously without waiting for clock.
RTL Code:
42
Ummidi Chandrika
43
Ummidi Chandrika
buffer first comes out of it first.FIFOs are used in designs to safely pass multi-bit data
words from one clock domain to another, or to control the flow of data between source
and destination sides sitting in the same clock domain. If read and write clock domains
are governed by the same clock signal, FIFO is said to be synchronous FIFO
Why is synchronous FIFO needed?
Synchronous FIFOs are the ideal choice for high-performance systems due to high
operating speed. Synchronous FIFOs also offer many other advantages that improve
system performance and reduce complexity. These include status flags: synchronous
flags, half-full, programmable almost-empty and almost-full flags.
RTL Code:
44
Ummidi Chandrika
The priority encoder is a circuit that executes the priority function. The logic of the
priority encoder is such that two or more inputs appear at an equal time, the input
having the largest priority will take precedence. The truth table of a 8*3 priority
encoder is given below.
45
Ummidi Chandrika
RTL Code:
46
Ummidi Chandrika
RTL Code:
47
Ummidi Chandrika
RTL Code:
48
Ummidi Chandrika
49
Ummidi Chandrika
RTL Code:
50
Ummidi Chandrika
51