Binary-to Thermometer Encoder model

This page contains Verilog-A model of the binary-to-thermometer encoder. This block can be used for behavioral simulation of the pipelined ADCs, programmable gains/BW etc. This model will automatically select number of outputs based on selected number of input binary bits.


Usage:

  1. Create a new cell in Library Manager named bin2therm and select cell type Verilog A;
  2. Copy and paste the code provided;
  3. Specify binary_bits variable to be the desired binary bits number;
  4. Specify Start_Bit to be 0 if you want thermometer code to start from 0 or 1 if you want thermometer code to start from 1;
  5. Perform Check and Save;
  6. A cell symbol will be created;
  7. Instantiate bin2term cell into your design;
  8. Perform Check and Save and run the simulation.

Example: binary_bits = 2, Start_Bit = 0

Binary inputThermometer code
00000
01001
10010
11100

Example: binary_bits = 2, Start_Bit = 1

Binary inputThermometer code
000001
010010
100100
111000

Cell name: bin2term

Model type: Verilog-A

Download from Github

1// Binary to Thermometer decoder 2// Implements two options: 3// Start_Bit = 0: Decimal 0 equals thermometer 0 4// Start_Bit = 1: Decimal 0 equals thermometer 1 5// Change binary_bits variable for your needs! 6// Author: A. Sidun 7// Source: AnalogHub.ie 8 9\`include "constants.vams" 10\`include "disciplines.vams" 11\`define binary_bits 4\t\t\t\t\t\t\t// define number of binary bits here 12 13module bin2therm(in,out); 14input [\`binary_bits-1:0] in; 15output [2**\`binary_bits-1:0] out; 16 17voltage [\`binary_bits-1:0] in; 18voltage [2**\`binary_bits-1:0] out; 19 20parameter real vdd = 1;\t\t\t\t\t// voltage level of logic 1 (V) 21parameter real vss = 0;\t\t\t\t\t// voltage level of logic 0 (V) 22parameter real threshold = 0.5;\t\t\t// logic threshold level (V) 23parameter integer Start_Bit = 0; \t// defines if thermometer starts from 0 or 1 24 25real dout[2**\`binary_bits-1:0];\t\t\t// internal result variable 26integer code; 27genvar i; 28 29analog begin 30// convert binary input to code 31 code = 0; 32 for (i = 0; i < \`binary_bits; i = i + 1) begin 33 @(cross(V(in[i]) - threshold)) 34 ; 35 if (V(in[i]) > threshold) 36 code = code + (1 << i); 37 end 38//$display("Code = %d", code); 39 40case (Start_Bit) 41 0: begin\t// Decimal 0 equals thermometer 0 42\t\tfor(i=1;i<2**\`binary_bits+1;i=i+1) begin 43 \t\tif(code!=i) begin 44 \t\tdout[i-1]=vss; 45 \t\tend 46 \t\telse begin 47 \t\tdout[i-1]=vdd; 48 \t\tend 49\t\tend 50\tend 51 52 1: begin\t// Decimal 0 equals thermometer 1 53\t\tfor(i=0;i<2**\`binary_bits;i=i+1) begin 54 \t\tif(code!=i) begin 55 \t\tdout[i]=vss; 56 \t\tend 57 \t\telse begin 58 \t\tdout[i]=vdd; 59 \t\tend 60\t\tend 61\tend 62endcase 63 64// Plotting outputs 65for (i=0; i<2**\`binary_bits; i=i+1) 66\t V(out[i]) <+ transition(dout[i],0,0); 67end 68endmodule