CBL_BinaryToTherm

CBL_BinaryToTherm : A combinational logic converting a binary code to a thermometer code

This model describes a combinational logic converting an N-bit binary code to a (2^N-1)-bit thermometer code. For example, the model converts a 3-bit binary-coded input to a 7-bit thermometer-coded output following the patterns below.

3'b000  -->  7'b0000000
3'b001  -->  7'b0000001
3'b010  -->  7'b0000011
3'b011  -->  7'b0000111
3'b100  -->  7'b0001111
3'b101  -->  7'b0011111
3'b110  -->  7'b0111111
3'b111  -->  7'b1111111

module CBL_BinaryToTherm #(
    parameter width = 4                 // bit width of the binary-coded input
)(
    input [width-1:0] in,               // binary-coded input
    output reg [(1<<width)-2:0] out     // thermometer-coded output
);

int i;

always @(in) begin
    for (i=0; i<(1<<width)-1; i=i+1) begin
        out[i] = (in > i) ? 1 : 0;
    end
end

endmodule

Input/Output Terminals

Name I/O Type Description
in [width-1:0] input wire binary-coded input
out [(1<<width)-2:0] output reg thermometer-coded output

Parameters

Name Type Default Description
width integer 4 bit width of the binary-coded input

List of Testbenches

tb_check : A testbench for checking the basic functionality of a combinational logic

tb_check : A testbench for checking the basic functionality of a combinational logic

This testbench checks the basic functionality of a combinational logic by enumerating all the possible input values and listing its corresponding outputs.

module tb_check ();
parameter in_width = 4;
parameter out_width = (1 << in_width) - 1;

reg [in_width-1:0] in;
wire [out_width-1:0] out;

CBL_BinaryToTherm #(.width(in_width)) DUT (.in, .out);

initial begin
    in = 0;

    repeat ((1 << in_width) - 1) begin
        #(1ns);
        in = in + 1;
    end
end

always @(out) begin
    $display("IN: %b --> OUT: %b", in, out);
end

endmodule