/* ----------------------------------------------------------- */ /* DEMO 6 : AD Calibration */ /* Compiler: Borland C++ 3.1, Mode Large */ /* *** AD Calibration for PCI-1002 card *** */ /* Singled-end way input channes .... */ /* Step 1: Apply +10V to channel 0. */ /* Step 2: Apply +0V to channel 1. */ /* Step 3: Apply -10V to channel 2. */ /* Step 4: Adjust VR1 until channel 0 = fff or ffe */ /* Step 5: Adjust VR2 until channel 1 = 800 or 801 */ /* Step 6: Adjust VR3 until channel 2 = 000 or 001 */ /* Step 7: Repeat Step 4 & Step 5 & Step 6 until all Ok. */ /* ----------------------------------------------------------- */ #include "P1002.H" static int wSysConfig=0; WORD wBaseAddr,wIrq; //======================================================= WORD P1002_Delay(WORD wDownCount) { WORD h,l; int count; wDownCount &= 0x7fff; if (wDownCount<1) wDownCount=1; /* Clock in=4M --> count 4000 = 1 ms ,count 1 = 0.25 us */ l=wDownCount&0xff; wDownCount=wDownCount / 256; h=wDownCount&0xff; outp(wBaseAddr+3*4,0xB0); /* CR of 8254,mode_0, counter_2 */ outp(wBaseAddr+2*4,l); /* counter_2 low byte first */ outp(wBaseAddr+2*4,h); /* counter_2 high byte ,0x07D0=2000 */ outp(wBaseAddr+3*4,0x80); /* latch counter_2 */ l=inp(wBaseAddr+2*4); /* delay starting two clks */ h=inp(wBaseAddr+2*4); for (count=32767;count>0;count--) { outp(wBaseAddr+12,0x80); /* latch counter_2 */ l=inp(wBaseAddr+8); h=inp(wBaseAddr+8); if (h>=0x80) return NoError; } return TimeOut; } //-------------------------------------------------- void SetupTimer(WORD wChannel, WORD wCoef) { WORD cmd; wChannel=wChannel&0x03; cmd=0x34+(wChannel<<6); outpw(wBaseAddr+3*4, cmd); outp(wBaseAddr+wChannel*4, (UCHAR)(wCoef&0xff)); outp(wBaseAddr+wChannel*4, (UCHAR)(wCoef>>8)); } //=================================================== WORD P1002_wAdsPacer(WORD wAdVal[], WORD wNum, WORD wSamplingDiv) { WORD wVal,wTime,wZERO,i; float fMAX; switch (wSysConfig) { case 0 : wZERO=2048; break; case 1 : wZERO=2048; break; case 2 : wZERO=2048; break; case 3 : wZERO=2048; break; case 0x10 : wZERO=2048; break; case 0x11 : wZERO=2048; break; case 0x12 : wZERO=2048; break; case 0x13 : wZERO=2048; break; } SetupTimer(0,wSamplingDiv); // sampling rate=2M/wSamplingDiv outp(wBaseAddr+0x18,0x0); for(i=0; i65530) return(TimeOut); } wTime=0; for (;;) { if ( inp(wBaseAddr+0x10)&0x01 ) break; // wait until not busy ! wTime++; if (wTime>65530) return(TimeOut); } wAdVal[i]=inpw(wBaseAddr+0x30)&0x0fff; } SetupTimer(0,1); return(0); } //=================================================== WORD P1002_SetChannelConfig(WORD wAdChannel, WORD wConfig) { WORD wDELAY; outp(wBaseAddr+0x10,(UCHAR)wAdChannel); outp(wBaseAddr+0x14,(UCHAR)wConfig); wSysConfig=wConfig; switch (wSysConfig) { case 0 : wDELAY=23; break; case 1 : wDELAY=23; break; case 2 : wDELAY=23; break; case 3 : wDELAY=23; break; case 0x10 : wDELAY=23; break; case 0x11 : wDELAY=28; break; case 0x12 : wDELAY=140; break; case 0x13 : wDELAY=1300; break; } P1002_Delay(wDELAY*4); return NoError; } //=================================================== int main() { int i,j; WORD wBoards,wRetVal,wPLX; char c; WORD wAdData1[200]; WORD wAdData2[200]; WORD wAdData3[200]; DWORD wAd1=0,wAd2=00,wAd3=0; clrscr(); P1002_DriverInit(&wBoards); printf("\n(1) Threr are %d PCI-1002 Cards in this PC",wBoards); if ( wBoards==0 ) { putch(0x07); putch(0x07); putch(0x07); printf("(1) There are no PCI-1002 card in this PC !!!\n"); exit(0); } printf("\n(2) Show the Configuration Space of all PCI-1002:"); for(i=0; i