RTL Studio Open IDE

Code Conversion

Thermometer-to-Binary Encoder — L1 Upgrade

A pipelined module that converts a 16-bit thermometer code into a 4-bit binary index.

About this block

Simulate it in the Verilog IDE

Mediumverilogsimsyn

Thermometer-to-Binary Encoder — L1 Upgrade is a Verilog reference block in the Code Conversion catalog. Encoders, decoders, priority encoders, and binary/gray converters. Marked Medium: more state or a wider datapath, still one workspace in the IDE.

This IP core converts a 16-bit thermometer code into a 4-bit binary value. It utilizes a one-stage pipelined architecture to register inputs and outputs, ensuring low latency and predictable timing suitable for Level 1 (L1) upgrade scenarios.

The design identifies the most significant bit (MSB) set in the input vector and outputs its index as a 4-bit binary number. This approach minimizes critical path delay by separating the sampling logic from the combinational decoding logic.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for Thermometer-to-Binary Encoder — L1 Upgrade.
  2. Read the Verilog module in the editor. The catalog line for this block: A pipelined module that converts a 16-bit thermometer code into a 4-bit binary index.
  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

  • Input: 16-bit thermometer code (data_in[15:0]).
  • Output: 4-bit binary index (data_out[3:0]).
  • Pipelining: One-stage pipeline with input and output registers.
  • Control: Asynchronous active-low reset (rst_n) and valid flag (valid_in/valid_out).
  • Logic: Combinational MSB detection logic between pipeline stages.
  • Latency: 1 clock cycle (combinational logic is registered).

Ports

Port NameDirectionWidthDescription
clkInput1Clock input
rst_nInput1Active-low asynchronous reset
valid_inInput1Input valid signal
data_inInput[15:0]Thermometer code input
valid_outOutput1Output valid signal
data_outOutput[3:0]Binary encoded output

Architecture

The design follows a classic two-stage pipeline:

  1. Input Register Stage: Captures data_in and valid_in on the rising edge of clk. This isolates the external interface from the combinational logic, improving timing closure.
  2. Combinational Logic: Performs a priority-encoded search for the Most Significant Bit (MSB) set in the registered input. The logic uses a cascaded ternary operator structure to determine the binary index.
  3. Output Register Stage: Registers the computed binary result and the valid flag, providing a stable output for downstream logic.

Verification

The verification environment includes a testbench (tb_thermometer_bin_pipeline.v) that covers seven specific test cases to ensure functional correctness.

### Test Cases

Test CaseInput ConditionExpected OutputResult
TC1All zerosdata=0, valid=1PASS
TC2Bit 0 setdata=0, valid=1PASS
TC3Bit 15 setdata=15, valid=1PASS
TC4Bit 7 setdata=7, valid=1PASS
TC5All bits setdata=15, valid=1PASS
TC6Valid lowvalid=0PASS
TC7Reset asserteddata=0, valid=0PASS

### Simulation Results

Upon running the simulation, the log panel should display:

  • TC1 PASS valid_out=1, data_out=0
  • TC2 PASS valid_out=1, data_out=0
  • TC3 PASS valid_out=1, data_out=15
  • TC4 PASS valid_out=1, data_out=7
  • TC5 PASS valid_out=1, data_out=15
  • TC6 PASS valid_out=0
  • TC7 PASS valid_out=0, data_out=0 during reset
  • Simulation ends with INFO: PASS.

More in Code Conversion

All Code Conversion blocks