/* This demo is used as a quick start for user to check basic information and AI accuracy If your I-8014W performs bad result, please take screen shot for this demo and mail to serivce@icpdas.com */ #include #include #include "8000A.h" #include "8014W.h" #include #include "8026W.h" int s26=5; int s14=7; void main() { unsigned long looncnt=1; float TestV[10],acc; float hpAO; short GainValue,gVal; short OffsetValue,oVal; int ch=0,g=0,gain=0,i=0,j=0,ret=0; unsigned int hexV=0; InitLib(); i8014W_Init(s14); // 將 AO gain / offset 叫出來 loop: g=2; for(ch=0;ch<2;ch++) { AOTest: i8026W_Init(s26); // 將 AO gain / offset 叫出來 switch(g) { case 0: // //+/-10V TestV[0]=10; TestV[1]= -10; TestV[2]= 7.5; TestV[3]= -7.5; TestV[4]= 5.5; TestV[5]= -5.5; TestV[6]= 3.5; TestV[7]= -3.5; TestV[8]= 1.5; TestV[9]= -1.5; acc = 0.040; //TestV={10,-10,7.5,-7.5,5.5,-5.5,3.5,-3.5,1.5,-1.5}; break; case 1: // // +/-5V 0.1% FSR +/- 1LSB = 10*1000/1000 +/- 10000/4096 = +/- 0.012V = +/- 12mV TestV[0]= 5.0; TestV[1]= -5.0; TestV[2]= 3.5; TestV[3]= -3.5; TestV[4]= 2.5; TestV[5]= -2.5; TestV[6]= 1.5; TestV[7]= -1.5; TestV[8]= 0.5; TestV[9]= -0.5; acc = 0.020; break; case 2: // 0~10V // 0.1% FSR +/- 1LSB = 10*1000/1000 +/- 10000/4096 = +/- 0.012V = +/- 12mV TestV[0]=10; TestV[1]= 9; TestV[2]= 8; TestV[3]= 7; TestV[4]= 6; TestV[5]= 5; TestV[6]= 4; TestV[7]= 3; TestV[8]= 2; TestV[9]= 1; acc = 0.020; //TestV={1. 25,-1.25,1.0,-1.0,0.75,-0.75,0.25,-0.25,0.12,-0.12}; break; case 3: // 0~ 5V // 0.1% FSR +/- 1LSB = 5*1000/1000 +/- 5000/4096 = +/- 0.006V = +/- 6mV TestV[0]= 5; TestV[1]=4.5; TestV[2]=4.0; TestV[3]=3.5; TestV[4]=3.0; TestV[5]=2.5; TestV[6]=2.0; TestV[7]=1.5; TestV[8]=1.0; TestV[9]=0.5; acc = 0.010; //TestV={2. 45,-2.45,2.00,-2.00,1.55,-1.55,0.98,-0.98,0.25,-0.25}; break; case 4: //0~20mA  // 0.1% FSR +/- 1LSB = 20*1000/1000 +/- 10000/4096 = +/- 0.024 mA TestV[0]= 20.0; TestV[1]= 18.0; TestV[2]= 16; TestV[3]= 14; TestV[4]= 12; TestV[5]= 10; TestV[6]= 8; TestV[7]= 6; TestV[8]= 4; TestV[9]= 2; acc = 0.040; //TestV={5.0,-5.0,3.5,-3.5,2.5,-2.5,1.5,-1.5,0.5,-0.5}; break; } for(i=0;i<10;i++) { for(j=1;j<2;j++) { //Print ("s14=%d,ch=%d , g=%d ",s14,ch,g); i8026W_ReadAO_GainOffset(s26,ch,g, & gVal, & oVal); i8026W_WriteAO(s26,ch,g,TestV[i]); Delay (100); ret=i8014W_ReadAI(s14,ch,0,&hpAO); if(fabs(TestV[i]-hpAO) <= acc) { Print(" %d s26=%d,ch=%d , g=%d ,Gain %04X, Offset %04X AO[%+07.4f],hp[%+07.4f],del[%+6.4f] %6.4f ---OK \r",j,s26,ch,g,gVal,oVal,TestV[i],hpAO,TestV[i]-hpAO, acc ); //Print("%d s26=%d,ch=%d , g=%d ,Gain %04X, Offset %04X AO[%+07.4f][%04X],hp[%+07.4f],del[%+6.4f] %6.4f ---OK \r",j,s26,ch,g,gVal,oVal,TestV[i],hexV,hpAO,TestV[i]-hpAO, acc ); } else { Print("\n\r %d s26=%d,ch=%d , g=%d ,Gain %04X, Offset %04X ,AO[%+07.4f],hp[%+07.4f],del[%+6.4f] %6.4f Error \n\r",j,s26,ch,g,gVal,oVal,TestV[i],hpAO,TestV[i]-hpAO, acc ); //Print("\n\r%d s26=%d,ch=%d , g=%d ,Gain %04X, Offset %04X ,AO[%+07.4f][%04X],hp[%+07.4f],del[%+6.4f] %6.4f Error \n\r",j,s26,ch,g,gVal,oVal,TestV[i],hexV,hpAO,TestV[i]-hpAO, acc ); //AOerror=1; Getch(); break; } } } //g++; if (g>=4) goto loop; else goto AOTest; } }