Aleksandr SidunBinary-to Thermometer Encoder model
This is a behavioral binary-to-thermometer encoder that converts an N-bit binary input into a one-hot thermometer output bus, a key building block in current-steering DAC decoders, pipelined ADC segment selectors, and programmable-gain amplifier stimulus blocks. With binary_bits = N, the model drives 2^N output lines; Start_Bit selects whether decimal 0 maps to the all-zero word (Start_Bit = 0) or to the LSB-high word (Start_Bit = 1), accommodating different DAC unit-element conventions. Output logic levels are set by vdd/vss and the input threshold by threshold. A typical use-case is driving the unit-element switches of a segmented current-steering DAC array from a binary counter output in a mixed-signal simulation, bypassing the need for a transistor-level decoder during early behavioral verification.
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:
- Create a new cell in Library Manager named bin2therm and select cell type Verilog A;
- Copy and paste the code provided;
- Specify binary_bits variable to be the desired binary bits number;
- 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;
- Perform Check and Save;
- A cell symbol will be created;
- Instantiate bin2term cell into your design;
- Perform Check and Save and run the simulation.
Example: binary_bits = 2, Start_Bit = 0
| Binary input | Thermometer code |
|---|---|
| 00 | 000 |
| 01 | 001 |
| 10 | 010 |
| 11 | 100 |
Example: binary_bits = 2, Start_Bit = 1
| Binary input | Thermometer code |
|---|---|
| 00 | 0001 |
| 01 | 0010 |
| 10 | 0100 |
| 11 | 1000 |
Cell name: bin2term
Model type: Verilog-A
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// Source: AnalogHub.ie
7
8`include "constants.vams"
9`include "disciplines.vams"
10`define binary_bits 4 // define number of binary bits here
11
12module bin2therm(in,out);
13input [`binary_bits-1:0] in;
14output [2**`binary_bits-1:0] out;
15
16voltage [`binary_bits-1:0] in;
17voltage [2**`binary_bits-1:0] out;
18
19parameter real vdd = 1; // voltage level of logic 1 (V)
20parameter real vss = 0; // voltage level of logic 0 (V)
21parameter real threshold = 0.5; // logic threshold level (V)
22parameter integer Start_Bit = 0; // defines if thermometer starts from 0 or 1
23
24real dout[2**`binary_bits-1:0]; // internal result variable
25integer code;
26genvar i;
27
28analog begin
29// convert binary input to code
30 code = 0;
31 for (i = 0; i < `binary_bits; i = i + 1) begin
32 @(cross(V(in[i]) - threshold))
33 ;
34 if (V(in[i]) > threshold)
35 code = code + (1 << i);
36 end
37//$display("Code = %d", code);
38
39case (Start_Bit)
40 0: begin // Decimal 0 equals thermometer 0
41 for(i=1;i<2**`binary_bits+1;i=i+1) begin
42 if(code!=i) begin
43 dout[i-1]=vss;
44 end
45 else begin
46 dout[i-1]=vdd;
47 end
48 end
49 end
50
51 1: begin // Decimal 0 equals thermometer 1
52 for(i=0;i<2**`binary_bits;i=i+1) begin
53 if(code!=i) begin
54 dout[i]=vss;
55 end
56 else begin
57 dout[i]=vdd;
58 end
59 end
60 end
61endcase
62
63// Plotting outputs
64for (i=0; i<2**`binary_bits; i=i+1)
65 V(out[i]) <+ transition(dout[i],0,0);
66end
67endmodule