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:
- 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.
Cell name: bin2term Model type: Verilog-A
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 |
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 // 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; // voltage level of logic 1 (V) 21parameter real vss = 0; // voltage level of logic 0 (V) 22parameter real threshold = 0.5; // logic threshold level (V) 23parameter integer Start_Bit = 0; // defines if thermometer starts from 0 or 1 24 25real dout[2**`binary_bits-1:0]; // 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 // Decimal 0 equals thermometer 0 42 for(i=1;i<2**`binary_bits+1;i=i+1) begin 43 if(code!=i) begin 44 dout[i-1]=vss; 45 end 46 else begin 47 dout[i-1]=vdd; 48 end 49 end 50 end 51 52 1: begin // Decimal 0 equals thermometer 1 53 for(i=0;i<2**`binary_bits;i=i+1) begin 54 if(code!=i) begin 55 dout[i]=vss; 56 end 57 else begin 58 dout[i]=vdd; 59 end 60 end 61 end 62endcase 63 64// Plotting outputs 65for (i=0; i<2**`binary_bits; i=i+1) 66 V(out[i]) <+ transition(dout[i],0,0); 67end 68endmodule