beautypg.com

Rainbow Electronics DS1852 User Manual

Page 24

background image

DS1852

24 of 25

begin

bestTrim := trim;

if (Bit > 11) then
Begin

trim := trim - lshft(1,trimBit);

end;

end;

end;

(* The upper 4 bits of bestTrim contains the answer for the course adjustment.*)
(* It is the smallest value that allows full scale trim with the lower 12 bits*)

(* zero out the lower 12 bits of bestTrim *)

trim := land(bestTrim,61440(*F000h*)); (*land() is logical AND function*)

(*Use SAR approach to trim resolution on VAD scale bits 11-0*)

for Bit := 11 downto -1 do (* must go 1 bit too far so that zero is
possible solution *)
begin

if (Bit > 0) then
begin

trim := trim + lshft(1,Bit);

end;

writeTrimValue(trim);

waitForNewConversion;

Dec_out := readVoltage;

delta := Dec_out - Dec_in;

if ( abs(delta) <= abs(bestDelta) ) then
begin

bestTrim := trim;
bestDelta := delta;

end;

if ( delta > 0 ) then
begin

if (Bit > 0) then
Begin

trim := trim - lshft(1,trimBit);

end;

end;

end;

(* bestTrim now contains the trim that gives the lowest delta*)

ProgramTrim(bestTrim);

end;