/* -------------------------------------------- */ /* DEMO 5 : AdsPacer trigger */ /* Compiler: Borland C++ 3.1, Mode Large */ /* -------------------------------------------- */ #include "P1002.H" static int wSysConfig=0; float fAdData[200]; WORD wAdData[200]; 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_AdsPacer(float fAdVal[], WORD wNum, WORD wSamplingDiv) { WORD wVal,wTime,wZERO,i; float fMAX; if (wGetAddress==0) { if (GetAddress()!=0) return(FindBoardError); } switch (wSysConfig) { case 0 : wZERO=2048; fMAX=(float)10.0; break; case 1 : wZERO=2048; fMAX=(float)5.0; break; case 2 : wZERO=2048; fMAX=(float)2.5; break; case 3 : wZERO=2048; fMAX=(float)1.25; break; case 0x10 : wZERO=2048; fMAX=(float)10.0; break; case 0x11 : wZERO=2048; fMAX=(float)1.0; break; case 0x12 : wZERO=2048; fMAX=(float)0.1; break; case 0x13 : wZERO=2048; fMAX=(float)0.01; break; } SetupTimer(0,wSamplingDiv); // sampling rate=4M/wSamplingDiv outp(wBaseAddr+0x00,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); } fAdVal[i]=(((float)(inpw(wBaseAddr+0x30)&0x0fff)-wZERO)/2048.0)*fMAX; } 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; } //======================================================== void main() { int i,j; WORD wBoards,wRetVal,wPLX; char c; 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 %5.3f V",fAdData[i]); } P1002_DriverClose(); }