Wednesday 11 February 2015

Decimal to BCD Encoder

Decimal to BCD Encoder:

           A decimal to BCD encoder has 10 input lines D0 to D9 and 4 output lines Y0 to Y3 . Below is the truth table for a decimal to BCD encoder.



From the truth table, the outputs can be expressed by following Boolean Function.
Note: Below boolean functions are formed by ORing all the input lines for which output is 1. For instance Y0 is 1 for D1 , D3 , D5 , D7 & D9 input lines.
Y0 = D1 + D3 + D5 + D7 + D9
Y1 = D2 + D3 + D6 + D7
Y2 = D4 + D5 + D6 + D7
Y3 = D8 + D9
The decimal to BCD encoder can therefore be implemented with OR gates whose inputs are determined directly from truth table as shown in the image below.


Source: http://verticalhorizons.in/decimal-to-bcd-encoder-in-digital-electronics/

Verilog Code for Decimal to BCD Encoder using Behavioural Modeling:

 module decimal_bcd_encoder(
    input [9:0] d,
    output reg [3:0] y
    );
always @ (d)
begin
case(d)
10'b0000000001:y=4'b0000;
10'b0000000010:y=4'b0001;
10'b0000000100:y=4'b0010;
10'b0000001000:y=4'b0011;
10'b0000010000:y=4'b0100;
10'b0000100000:y=4'b0101;
10'b0001000000:y=4'b0110;
10'b0010000000:y=4'b0111;
10'b0100000000:y=4'b1000;
10'b1000000000:y=4'b1001;
default:y=4'b0000;
endcase
end
endmodule

No comments:

Post a Comment