RTL Studio Open IDE

Code Conversion

8-Bit Thermometer to Binary Encoder

Combinational priority encoder converting 8-bit thermometer code to 3-bit binary index with MSB priority.

About this block

Simulate it in the Verilog IDE

Easyverilogsimsyn

8-Bit Thermometer to Binary Encoder is a Verilog reference block in the Code Conversion catalog. Encoders, decoders, priority encoders, and binary/gray converters. Marked Easy: a small block you can read, simulate, and synthesize in one sitting.

This IP core implements an 8-bit thermometer-to-binary encoder. It converts an 8-bit one-hot (thermometer) input code into a 3-bit binary index representing the position of the highest set bit (MSB priority). The module is purely combinational, ensuring low latency, and includes a valid signal to indicate when the input is non-zero. It is fully verified with a comprehensive testbench covering all critical edge cases.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for 8-Bit Thermometer to Binary Encoder.
  2. Read the Verilog module in the editor. The catalog line for this block: Combinational priority encoder converting 8-bit thermometer code to 3-bit binary index with MSB priority.
  3. Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
  4. Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.

RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.

Features

  • Functionality: Converts 8-bit thermometer code to 3-bit binary index.
  • Priority: MSB priority (highest index wins).
  • Latency: Combinational logic for minimal delay.
  • Verification: Includes a testbench with 8 distinct test cases covering all zeros, single bits, multiple bits, and all bits set.
  • Simulation: Verified using Icarus Verilog.

Ports

Port NameDirectionWidthDescription
thermo_inInput88-bit thermometer code input.
bin_outOutput3Binary index of the highest set bit in thermo_in.
validOutput1High (1) when any bit in thermo_in is high. Low (0) if all inputs are zero.

Verification

The testbench tb_thermometer_to_binary_8b.v verifies the following scenarios:

Test CaseDescriptionExpected bin_outExpected validStatus
TC1All zeros input3'b0000PASS
TC2LSB set (index 0)3'b0001PASS
TC3MSB set (index 7)3'b1111PASS
TC4Middle bit set (index 3)3'b0111PASS
TC5Multiple bits set (MSB priority)3'b1101PASS
TC6All bits set3'b1111PASS
TC7Single bit at index 43'b1001PASS
TC8Single bit at index 63'b1101PASS

All 8 test cases passed successfully.

More in Code Conversion

All Code Conversion blocks