//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include #include "acces32.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { addrEDIT->Text = "300"; outputting = false; infoLBL->Caption = "This program will output three wave forms from the 104-DA12-8.\n\rThe wave forms will be output on DACS 0 - 2.\n\rThe wave forms will stop when the user clicks stop or exits the program\n\r"; } //--------------------------------------------------------------------------- void CtrMode(unsigned short addr, char cntr, char mode) { int ctrl; ctrl = (cntr << 6) | 0x30 | (mode << 1); OutPortB(addr+3,ctrl); } void CtrLoad(unsigned short addr ,int c,int val) { OutPortB(addr+c,val & 0x00FF); OutPortB(addr+c,(val>>8) & 0x00FF); } void __fastcall TForm1::beginBTNClick(TObject *Sender) { unsigned short BUFFER[30000]; int count; if (!outputting) { beginBTN->Caption = "STOP"; outputting = true; BASE = StrToInt("0x" + addrEDIT->Text); /***************************************************** ** This for loop will fill the buffer with the following ** three wave forms and rescale them to have the same period: ** 1) sin(x^2) from x = -3.3 to 3.3 ** 2) cos(x^2) from x = -3.0 to 3.0 ** 3) sin(x^2) * cos (x^2) from x = -1.9 to 1.9 *****************************************************/ for (count = 0; count < 10000; count++) { BUFFER[(count * 3)] = int(sin(pow(-3.3 + (.00066 * count), 2)) * 2047.0 + 2048.0); BUFFER[(count * 3)] &= 0x0fff; //need to be certain that the control bits are what we want BUFFER[((count * 3) + 1)] = int(cos(pow(-3.0 + (.0006 * count), 2)) * 2047.0 + 2048.0); BUFFER[((count * 3) + 1)] &= 0x0fff; BUFFER[((count * 3) + 2)] = int(sin(pow(-1.9 + (.00038 * count), 2)) * cos(pow(-1.9 + (.00038 * count), 2)) * 2047.0 + 2048.0); BUFFER[((count * 3) + 2)] &= 0x0fff; //let the card know that this is the end of this scan BUFFER[((count * 3) + 2)] |= 0x2000; } BUFFER[29999] |= 0x1000; //this is the end of the stream and the card needs to loop OutPortB(BASE + 0x1a, 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; count < 30000; count++) { OutPort(BASE + 0x18, (count * 2)); //set the address we are going to write to OutPort(BASE + 0x1c, BUFFER[count]); //write the value for that address } CtrMode(BASE + 0x14, 1, 2); //set counter 1 to mode 2 CtrMode(BASE + 0x14, 2, 2); //set counter 2 to mode 2 CtrLoad(BASE + 0x14, 1, 5); //load counter 1 to 5 ticks CtrLoad(BASE + 0x14, 2, 10); //load counter 2 to 10 ticks OutPortB(BASE + 0x11, 0x00); //tell the card to start OutPortB(BASE + 0x10, 0x41); } else { beginBTN->Caption = "START"; outputting = false; OutPortB(BASE + 0x10, 0); //tell the card to stop } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { OutPortB(BASE + 0x10, 0); //tell the card to stop } //---------------------------------------------------------------------------