SPI_Test/tb/chip_top/thermo15_binary4.v

30 lines
886 B
Verilog

module thermo15_binary4(
input [14:0] thermo_code
,output reg [3 :0] binary_code
);
wire [3:0]sum;
assign sum=thermo_code[0]+thermo_code[1]+thermo_code[2]+thermo_code[3]+thermo_code[4]+thermo_code[5]+thermo_code[6]+thermo_code[7]+thermo_code[8]+thermo_code[9]+thermo_code[10]+thermo_code[11]+thermo_code[12]+thermo_code[13]+thermo_code[14];
always @(*) begin
case(sum)
4'd0 : binary_code<=4'b0000;
4'd1 : binary_code<=4'b0001;
4'd2 : binary_code<=4'b0010;
4'd3 : binary_code<=4'b0011;
4'd4 : binary_code<=4'b0100;
4'd5 : binary_code<=4'b0101;
4'd6 : binary_code<=4'b0110;
4'd7 : binary_code<=4'b0111;
4'd8 : binary_code<=4'b1000;
4'd9 : binary_code<=4'b1001;
4'd10: binary_code<=4'b1010;
4'd11: binary_code<=4'b1011;
4'd12: binary_code<=4'b1100;
4'd13: binary_code<=4'b1101;
4'd14: binary_code<=4'b1110;
4'd15: binary_code<=4'b1111;
endcase
end
endmodule