Hi all,
I am working on a data acquisition project which will send and receive data from and external device. The external device is a DAC. Any way I have been working on this program for a while now and I believe that I have everything in place but the program is not able to repeat a certain number of time, and it also freezes after its run. I was advised to look at the variable type used in the variable, but I am unable to find anything wrong. Here is the code the ULSTAT is an operation to obtain data from the DAC
I am working on a data acquisition project which will send and receive data from and external device. The external device is a DAC. Any way I have been working on this program for a while now and I believe that I have everything in place but the program is not able to repeat a certain number of time, and it also freezes after its run. I was advised to look at the variable type used in the variable, but I am unable to find anything wrong. Here is the code the ULSTAT is an operation to obtain data from the DAC
Code:
procedure TfrmAIn1.CVRunClick(Sender: TObject);
var initial, final, step, vout,sr, vertex :Single;
i, j, nop, scan_rate_time, r, nor :Integer;
DADataValue :Word;
DAEngUnits :Single;
begin
r :=0;
Series1.Clear;
Series2.Clear;
RChart1.ClearGraf;
nor:= StrToInt(NumIO1.Text); //number of repeats
repeat
begin
chan:=1; //channel data in
//DAChan:=0;
//set to connected to D/a
ULStat := cbAOut (BoardNum, DAChan, DARange, 0);
If ULStat <> 0 then exit;
//If RampOutCheckBox1.Checked = True then
initial:= StrToFloat(IPNumIO1.Text);
vertex:=StrToFloat(VPNumIO1.Text);
Step:= StrToFloat(StepNumIO1.Text);
Final:= StrToFloat(FPNumIO1.Text); //pot in mV
nor:= StrToInt(NumIO1.Text); //number of repeats
i:=0;
sr:= StrToFloat(SRNumIO1.Text); //scan rate in fp
scan_rate_time:= round(step*1000/sr); //delay time for ms
repeat
Wait(scan_rate_time); //in ms
vout:=Initial+i*Step; //voltage out from DAC
DAEngUnits:= vout/1000; //converted to volt
//data output,stepping up
ULStat := cbFromEngUnits(BoardNum, DARange, DAEngUnits, DADataValue);
If ULStat <> 0 then exit;
ULStat := cbAOut (BoardNum, DAChan, DARange, DADataValue);
If ULStat <> 0 then exit;
//collect data on ADC 1
ULStat := cbAIn(BoardNum, Chan, Range, DataValue);
If ULStat <> 0 then exit;
ULStat := cbToEngUnits (BoardNum, Range, DataValue, EngUnits);
If ULStat <> 0 then exit;
x[i]:= i*scan_rate_time; // just put index or i*100/1000 as time in s
y[i]:= EngUnits*1000; // signal in mV
NumLab2.Value:=x[i];
Series1.AddXY(x[i],y[i],'',clTeeColor); //Plot Data TeeChart
i:=i+1;
until vout>=vertex; // try this > sign
//continue collecting data , dont restart, reverse voltage
j:=1;
repeat
Wait(Scan_rate_time);
vout:=Vertex-j*Step;
DAEngUnits:= vout/1000; //converted to volt
//out data, stepping down
ULStat := cbFromEngUnits(BoardNum, DARange, DAEngUnits, DADataValue);
If ULStat <> 0 then exit;
ULStat := cbAOut (BoardNum, DAChan, DARange, DADataValue);
If ULStat <> 0 then exit;
//collect data
i:=i+1;
ULStat := cbAIn(BoardNum, Chan, Range, DataValue);
If ULStat <> 0 then exit;
ULStat := cbToEngUnits (BoardNum, Range, DataValue, EngUnits);
If ULStat <> 0 then exit;
x[i]:= i*scan_rate_time; // index - this can be converted later
y[i]:= EngUnits*1000; // signal in mV
NumLab2.Value:=x[i];
Series1.AddXY(x[i],y[i],'',clTeeColor); //Plot Data TeeChart
j:=j+1;
until vout<=Final; //try this < sign
//PLOT data while collecting
i:= nop; //total number of points collected
for i:=1 to nop do
begin
//Start RPLOT Routine
RChart1.MoveTo(x[i],y[i]);
with Rchart1 do
begin
AutoRange(4);
//DataColor:=clAqua;
MarkAt(x[i],y[i],13); //+--1,7,10,13small+,27,28(rounds)-shape of mark
Drawto(x[i],y[i]);
ShowGraf;
end;
end;
ULStat := cbAOut (BoardNum, DAChan, DARange, 0);
If ULStat <> 0 then exit;
exit;
end;
r := r+1;
until r >= nor;
end;