4 bit binary to gray counter converter HDL Verilog Code
Binary To Bcd Conversion Verilog
The hundreds digit 1 is represented in binary by 0001. The tens digit 5 is represented in binary by 0101. The ones digit 9 is represented in binary by 1001. The entire number 159 in BCD is therefore: 01. The hundreds digit 1 is represented in binary by 0001. The tens digit 5 is represented in binary by 0101. The ones digit 9 is represented in binary by 1001. The entire number 159 in BCD is therefore: 01. Each shift effectively doubles the value of the binary number in the four bit shift register which is going to hold the converted BCD digit. Each time a bit is.
About Press Copyright Contact us Creators Advertise Developers Terms Privacy Policy & Safety How YouTube works Test new features Press Copyright Contact us Creators. The above logic is a single digit Binary to BCD converter, contained in the binarytobcddigit.vhd file. The higher level binarytobcd.vhd file instantiates one of these single digit converters for each digit of the BCD output and cascades them together to form a multi-digit Binary to BCD converter.
This page of verilog sourcecode covers 4 Bit Binary to Gray Counter Converter using verilog.
Symbol
Following is the symbol and truth table of 4 bit binary to gray counter converter.
Truth Table
Rst | Clk | En | B3 | B2 | B1 | B0 | G3 | G2 | G1 | G0 |
---|---|---|---|---|---|---|---|---|---|---|
1 | X | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 |
0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 |
0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
0 | 1 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 |
0 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 |
0 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 |
0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 |
0 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
0 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 |
0 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 |
0 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 |
0 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 |
0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 |
0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | 1 |
0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
Verilog code
module b2g(b,g);
input [3:0] b;
output [3:0] g;
xor (g[0],b[0],b[1]),
(g[1],b[1],b[2]),
(g[2],b[2],b[3]);
assign g[3]=b[3];
end module
Simulation result
RF and Wireless tutorials
Share this page
Translate this page
Binary To Bcd Conversion Verilog Code
Consider adding 9+9+1 in decimal, the result is 19, instraight binary this should produce an output 100112, this is aninvalid number in BCD, because in BCD code the group of four bit binary onlyrepresent decimal numbers 0-9. The table bellow shows decimal numbers 0-19 withtheir corresponding binary and BCD codes. The K and C in the table are therespective binary carry and BCD carry bits.- Point where binary sum has output carry K =1 or,
- where Z8 and Z2 are both = 1 or,
- where Z8 and Z4 are both = 1.
Figure 1: Block diagram of BCD adder
Binary To Bcd Verilog
//-------------------------------------------------------------
Binary To Bcd Converter Verilog
16 Bit Binary To Bcd Verilog Code
Figure 2:Simulation showing the initial bits value of A: 0000, B: 0000, Sum S: 0000 andCarry C: 0 for the BCD adder (i.e. 0 + 0 = 0 0).
Figure 3:Simulation showing the bits value at 100ns for A: 1001, B: 1001, Sum S: 1000 and Carry C: 1 for the BCD adder (i.e. 9 +9 = 1 8 ).
Figure 4:Simulation showing the bits value at 300ns for A: 1000, B: 0011, Sum S: 0001 and Carry C: 1 for the BCD adder (i.e. 8+3 = 1 1 ).
Figure 5:Simulation showing the bits value at 300ns for A: 0100, B: 0011, Sum S: 0111 and Carry C: 0 for the BCD adder (i.e. 4+3 = 0 7 ). Reference Mano M. Morris andCiletti D. Michael; “Digital Design With and Introduction to the VerilogHDL – Fifth Edition” Copyright © 2013, 2007, 2002, 1991, 1984 Person Education,Inc., publishing as Prentice Hall, One Lake Street, Upper Saddle River, NewJersey 07458. |