`include "constants.vams"
`include "disciplines.vams"
module TG(VDD,GND,GAIN,OFFSET,TRIM,THRESHOLD);
input GAIN,VDD,GND,OFFSET,THRESHOLD;
output [15:0] TRIM;
electrical GAIN,VDD,GND,OFFSET,THRESHOLD;
electrical[15:0] TRIM;
electrical gnd;
ground gnd;
real gain_1;
real offset_1;
real total;
real final;
real flag;
real threshold_1;
integer i;
integer number;
real dummy1,dummy2,dummy3,dummy4,dummy5,dummy6;
analog begin
@ (initial_step) begin
flag=0;
dummy1=0;dummy2=0;dummy3=0;dummy4=0;dummy5=0;dummy 6=0;
end
gain_1=V(GAIN);
offset_1=V(OFFSET);
threshold_1=V(THRESHOLD);
total=gain_1+offset_1;
if(total<0)
begin
total=total*(-1);
flag=1;
end
if(total<=0.255)
begin
final=total*1000;
number=final;
$display("final = %f" , final);
end
else
begin
final=total*100;
$display("final = %f" , final);
end
generate i (0,8,1)
begin
if((number%2)==0)
begin
V(TRIM[i])<+0;
$display(" not entered");
$display("value of final %d",number);
number=(number)/2;
end
else
begin
V(TRIM[i])<+V(VDD);
$display(" entered");
$display("value of final %d",number);
number=(number-1)/2;
end
//if(flag==1)
//V(TRIM[8])<+1.8;
end
if(flag==1)
V(TRIM[8])<+V(VDD);
$display(" threshold_1 = %f",threshold_1);
case(threshold_1)
3.3:begin V(TRIM[14])<+V(GND); V(TRIM[13])<+V(GND);V(TRIM[12])<+V(GND);V(TRIM[11])<+V(GND);V(TRIM[10])<+V(GND);V(TRIM[9])<+V(GND);
dummy1=V(GND); dummy2=V(GND);dummy3=V(GND);dummy4=V(GND);dummy5=V (GND);dummy6=V(GND);end
2.5:begin V(TRIM[14])<+V(GND); V(TRIM[13])<+V(GND);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(GND);V(TRIM[10])<+V(GND);V(TRIM[9])<+V(GND);
dummy1=V(GND); dummy2=V(GND);dummy3=V(VDD);dummy4=V(GND);dummy5=V (GND);dummy6=V(GND);end
2:begin V(TRIM[14])<+V(GND); V(TRIM[13])<+V(VDD);V(TRIM[12])<+V(GND);V(TRIM[11])<+V(GND);V(TRIM[10])<+V(GND);V(TRIM[9])<+V(GND);
dummy1=V(GND); dummy2=V(VDD);dummy3=V(GND);dummy4=V(GND);dummy5=V (GND);dummy6=V(GND);end
1.8:begin V(TRIM[14])<+V(GND); V(TRIM[13])<+V(VDD);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(GND);V(TRIM[10])<+V(GND);V(TRIM[9])<+V(GND);
dummy1=V(GND); dummy2 =V(VDD);dummy3=V(VDD);dummy4=V(GND);dummy5=V(GND); dummy6=V(GND);end
1.5:begin V(TRIM[14])<+V(VDD); V(TRIM[13])<+V(GND);V(TRIM[12])<+V(GND);V(TRIM[11])<+V(GND);V(TRIM[10])<+V(GND);V(TRIM[9])<+V(GND);
dummy1=V(VDD); dummy2=V(GND);dummy3=V(GND);dummy4=V(GND);dummy5=V (GND);dummy6=V(GND);end
1.4:begin V(TRIM[14])<+V(VDD); V(TRIM[13])<+V(GND);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(GND);V(TRIM[10])<+V(GND);V(TRIM[9])<+V(GND);
dummy1=V(VDD); dummy2=V(GND);dummy3=V(VDD);dummy4=V(GND);dummy5=V (GND);dummy6=V(GND);end
1.3:begin V(TRIM[14])<+V(VDD); V(TRIM[13])<+V(GND);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(GND);V(TRIM[10])<+V(GND);V(TRIM[9])<+V(VDD);
dummy1=V(VDD); dummy2=V(GND);dummy3=V(VDD);dummy4=V(GND);dummy5=V (GND);dummy6=V(VDD);end
1.2:begin V(TRIM[14])<+V(VDD); V(TRIM[13])<+V(GND);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(GND);V(TRIM[10])<+V(VDD);V(TRIM[9])<+V(GND);
dummy1=V(VDD); dummy2=V(GND);dummy3=V(VDD);dummy4=V(GND);dummy5=V (VDD);dummy6=V(GND);end
1.1:begin V(TRIM[14])<+V(VDD); V(TRIM[13])<+V(GND);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(GND);V(TRIM[10])<+V(VDD);V(TRIM[9])<+V(VDD);
dummy1=V(VDD); dummy2=V(GND);dummy3=V(VDD);dummy4=V(GND);dummy5=V (VDD);dummy6=V(VDD);end
1:begin V(TRIM[14])<+V(VDD); V(TRIM[13])<+V(GND);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(VDD);V(TRIM[10])<+V(GND);V(TRIM[9])<+V(GND);
dummy1=V(VDD); dummy2=V(GND);dummy3=V(VDD);dummy4=V(VDD);dummy5=V (GND);dummy6=V(GND);end
0.9:begin V(TRIM[14])<+V(VDD); V(TRIM[13])<+V(GND);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(VDD);V(TRIM[10])<+V(GND);V(TRIM[9])<+V(VDD);
dummy1=V(VDD); dummy2=V(GND);dummy3=V(VDD);dummy4=V(VDD);dummy5=V (GND);dummy6=V(VDD);end
0.8:begin V(TRIM[14])<+V(VDD); V(TRIM[13])<+V(GND);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(VDD);V(TRIM[10])<+V(VDD);V(TRIM[9])<+V(GND);
dummy1=V(VDD); dummy2=V(GND);dummy3=V(VDD);dummy4=V(VDD);dummy5=V (VDD);dummy6=V(GND);$display(" entered zero.eightvolt");end
0.7:begin V(TRIM[14])<+V(VDD); V(TRIM[13])<+V(GND);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(VDD);V(TRIM[10])<+V(VDD);V(TRIM[9])<+V(VDD);
dummy1=V(VDD); dummy2=V(GND);dummy3=V(VDD);dummy4=V(VDD);dummy5=V (VDD);dummy6=V(VDD); $display(" entered zero.sevenvolt %f",threshold_1);end
0.6:begin V(TRIM[14])<+V(VDD); V(TRIM[13])<+V(VDD);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(GND);V(TRIM[10])<+V(GND);V(TRIM[9])<+V(GND);
dummy1=V(VDD); dummy2=V(VDD);dummy3=V(VDD);dummy4=V(GND);dummy5=V (GND);dummy6=V(GND);end
0.5:begin V(TRIM[14])<+V(VDD); V(TRIM[13])<+V(VDD);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(GND);V(TRIM[10])<+V(GND);V(TRIM[9])<+V(VDD);
dummy1=V(VDD); dummy2=V(VDD);dummy3=V(VDD);dummy4=V(GND);dummy5=V (GND);dummy6=V(VDD);end
0.4:begin V(TRIM[14])<+V(VDD); V(TRIM[13])<+V(VDD);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(GND);V(TRIM[10])<+V(VDD);V(TRIM[9])<+V(GND);
dummy1=V(VDD); dummy2=V(VDD);dummy3=V(VDD);dummy4=V(GND);dummy5=V (VDD);dummy6=V(GND);end
default : begin
/*V(TRIM[14])<+V(VDD);
V(TRIM[13])<+V(VDD);
V(TRIM[12])<+V(VDD);
V(TRIM[11])<+V(VDD);
V(TRIM[10])<+V(VDD);
V(TRIM[9])<+V(VDD);*/
$display(" Intermediate values %f",threshold_1);
V(TRIM[14])<+dummy1;
V(TRIM[13])<+dummy2;
V(TRIM[12])<+dummy3;
V(TRIM[11])<+dummy4;
V(TRIM[10])<+dummy5;
V(TRIM[9])<+dummy6;
end
endcase
/*if (threshold_1>0.6999999 && threshold_1<0.70000001)
begin
V(TRIM[14])<+V(VDD); V(TRIM[13])<+V(GND);V(TRIM[12])<+V(VDD);V(TRIM[11])<+V(VDD);V(TRIM[10])<+V(VDD);V(TRIM[9])<+V(VDD);
//V(TRIM[14])<+V(VDD)*0.5-V(VDD)*0.5; V(TRIM[13])<+V(GND);V(TRIM[12])<+V(VDD)*0.5-V(VDD)*0.5;V(TRIM[11])<+V(VDD)*0.5-V(VDD)*0.5;V(TRIM[10])<+V(VDD)*(2/3);V(TRIM[9])<+V(VDD);
//V(TRIM[14])<+V(TRIM[14])-V(VDD); V(TRIM[13])<+V(GND);V(TRIM[12])<+V(TRIM[12])-V(VDD);V(TRIM[11])<+V(TRIM[11])-V(VDD);V(TRIM[10])<+V(TRIM[10])-V(VDD);V(TRIM[9])<+V(TRIM[9])-V(VDD);
$display(" entered if loop %f",threshold_1);
end*/
end
endmodule