unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, acces32, StdCtrls, math; type TForm1 = class(TForm) Label1: TLabel; addrEDIT: TEdit; beginBTN: TButton; infoLBL: TLabel; procedure FormCreate(Sender: TObject); procedure beginBTNClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end; var Form1: TForm1; BASE : WORD; implementation {$R *.DFM} procedure CtrMode(cntr,mode:byte); var ctrl:byte; begin ctrl := (cntr shl 6) or $30 or (mode shl 1); OutPortB(BASE+$14+3, ctrl); end; procedure LoadCtr(c,val:integer); begin OutPortB(BASE+$14+c, lo(val)); OutPortB(BASE+$14+c, hi(val)); end; procedure TForm1.FormCreate(Sender: TObject); begin addrEDIT.Text := '300'; infoLBL.Caption := 'This program will output three wave forms from the 104-DA12-8.'#13#10'The wave forms will be output on DACS 0 - 2.'#13#10'The wave forms will stop when the user clicks stop or exits the program'#13#10; end; procedure TForm1.beginBTNClick(Sender: TObject); var count : word; BUFFER : array[0..29999] of word; begin if beginBTN.Caption = 'BEGIN' then begin BASE := StrToInt('$' + addrEDIT.Text); beginBTN.Caption := 'STOP'; for count:= 0 to 9999 do begin BUFFER[(count * 3)] := round(sin(intpower(-3.3 + 0.00066 * count, 2)) * 2047.0 + 2048.0); BUFFER[(count * 3)] := BUFFER[(count * 3)] and $0fff; //need to be certain that the control bits are what we want BUFFER[((count * 3) + 1)] := round(cos(intpower(-3.0 + 0.0006 * count, 2)) * 2047.0 + 2048.0); BUFFER[((count * 3) + 1)] := BUFFER[((count * 3) + 1)] and $0fff; BUFFER[((count * 3) + 2)] := round(sin(intpower(-1.9 + 0.00038 * count, 2)) * cos(intpower(-1.9 + 0.00038 * count, 2)) * 2047.0 + 2048.0); BUFFER[((count * 3) + 2)] := BUFFER[((count * 3) + 2)] and $0fff; //let the card know that this is the end of this scan BUFFER[((count * 3) + 2)] := BUFFER[((count * 3) + 2)] or $2000; end; BUFFER[29999] := BUFFER[29999] or $1000; //this is the end of the stream and the card needs to loop OutPortB(BASE + $1a, 0); //we will only be writing to the first 30k addresses //so we get to leave bit 16 of the SRAM addr at 0 for count := 0 to 29999 do begin OutPort(BASE + $18, (count * 2)); //set the address we are going to write to OutPort(BASE + $1c, BUFFER[count]); //write the value for that address end; CtrMode(1, 2); //set counter 1 to mode 2 CtrMode(2, 2); //set counter 2 to mode 2 LoadCtr(1, 5); //load counter 1 to 5 ticks LoadCtr(2, 10); //load counter 2 to 10 ticks OutPortB(BASE + $10, $41); //tell the card to start end else begin OutPortB(BASE + $10, 0); //tell the card to stop beginBTN.Caption := 'BEGIN'; end; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin OutPortB(BASE + $10, 0); //tell the card to stop end; end.