/* The I-8014W contains two types of Magic Scan . One is type 1: standard (each sample clock only samples a single. ) and Type 2: virtual Sample and hold (each sample clock will to sample all scan channels that have been set. ) Both of two types can set as polling Mode,Internal Hardware trigger Mode and External Hardware trigger Mode For Magic scan, we can set the FIFO level to trigger the slot Interrupt service and read the FIFO during Interrupt service. This Demo will show you how to use Magic Scan with Interrupt service ,step by step Step1: ret=i8014W_Init(slot); , this function will check hardware ID, if retrun code ret is -1 means this slot may empty or wrong I/O (not I-8014W) ,return 0 this slot is I-8014W Step2: i8014W_ConfigMagicScan( slot, chArr, gainArr, scanChCount, sampleRate, scanMode, triggerSource, triggerState , & realsampleRate); for Configure Magic Scan Parameters and return real sample rate that used by I-8014 module Step3: i8014W_InstallMagicScanISR(slotIndex,ISRFUN,triggerLevel); to define the trigger level and Interrupt service Step4: i8014W_StartMagicScan(int slot); to start Magic Scan function (If i8014W_ConfigMagicScan use external trigger signal mode , module will not start to save data . It will start to scan data when the signal is active) Step5: Send a external trigger signal for I-8014 module to Start magic scan (external trigger signal Mode only) Step6: i8014W_ReadFIFO(int slot, short rawData[], short readCount,short* dataCountFromFIFO); to read data from FIFO during Interrupt service Notice we have to use i8014W_ClearInt(slot); in Interrupt service If you don't clear the Interrupt, the Interrupt service will be blocked here. Step7: i8014W_UnInstallMagicScanISR(slot); i8014W_StopMagicScan( slot); stop the Interrupt service and Magic Scan function Step8: to show calibrated analog data. When we use Magic scan to read read data from FIFO ,the analog data is not calibrated We can use following function to get the calibrated data. void i8014W_CalibrateDataHex(int slot, short iGain,short dataFromFIFO, short* calibratedAI); void i8014W_CalibrateData(int slot, short iGain,short dataFromFIFO, float* calibratedAI); */ #include #include #include "8000E.h" #include "8014W.h" #include #include int slotIndex=-1; short jumper; long TargetCnt=100; unsigned long IntCnt=0; unsigned long T1,T2; int chArr[16], gainArr[16], scanChCount; float sampleRate,realsampleRate=1; int scanMode, triggerSource, triggerState; unsigned short triggerCnt[8]={8,16,32,64,128,256,512,2048}; short triggerLevel=0; short rawData[8192]; short totalScanned=0; char GainStr[5][32]={"+/-10V","+/-5V","+/-2.5V","+/-1.25V","+/-20mA"}; char ModeStr[2][32]={"Standard Mode", "Sample and Hold Mode"}; char SourceStr[3][32]={"Software Command", "Internal Interrupt Signal","External Trigger Signal"}; char StateStr[2][32]={"High","Low"}; int runFlag=1; int selGain; int showCnt=0; void ISRFUN(int slot); void ShowAI(void); void main() { int slot,ch; short i,ret; int maxCh=8; char sTemp[20]; int c; InitLib(); // Call this function initialize the 8000 lib Print("\n\n This Demo will show how to use magic scan function to read analog input\n\n"); Print(" Search I-8014W ....\n"); for(slot=0;slot<8;slot++) { if(i8014W_Init(slot)==0) //find I-8014W module out { slotIndex=slot; break; } } if(slotIndex==-1) { Print("\t There is no i8014 at i8000\n"); DelayMs(100); exit(0); } else { Print("\t There is an i8014 at slot %d\n",slotIndex); } jumper= i8014W_GetSingleEndJumper(slotIndex); if(jumper) { maxCh=16; Print("\t i8014W Input Mode=Single-End and can have maximum 16 analog input\n\r"); } else { maxCh=8; Print("\t i8014W Input Mode=Differential and can have maximum 8 analog input\n\r"); } // define the sampling channels array chArr[] // Differential Mode: element for chArr[] range from channel 0 ~ 7 , // Single ended Mode: element for chArr[] range from channel 0 ~ 15 // max element counts for chArr[] can be 16 // define gain type array for each channel // gainArr[] element for gainArr[] range from channel 0 ~ 15 // Gain value : 0="+/-10V",1="+/-5V",2="+/-2.5V",3="+/-1.25V",4="+/-20mA" // max element counts for gainArr[] can be 16 start: Print ("\n\n Input all i8014W_ConfigMagicScan parameters :\n\r"); Print("\n Step 1: Define scaned channel counts for magic scan:"); Print("\n Input scaned channel counts (1~16) :"); LineInput(sTemp,20); scanChCount=atoi(sTemp); Print(" Now we have scaned channel counts = %d\n\n",scanChCount); // assing input range (gain) Print("\n Step 2: Define input range (gain)"); Print("\n The Gain definition of I-8014W"); for(i=0;i<5;i++) { Print ("\n\t Select %d : %s",i,GainStr[i]); } Print("\n\r"); Print (" Select which Gain of (0~4):",i); LineInput(sTemp,20); selGain = atoi(sTemp); for(i=0;i=TargetCnt) { Print("\n Stop magic scan and FIFO data amount = %d spend time %lu\n", totalScanned, GetTimeTicks()-T1); i8014W_UnInstallMagicScanISR(slotIndex); i8014W_StopMagicScan(slotIndex); runFlag=0; IntCnt=0; } } T2=GetTimeTicks()-T1; // total time for magic scan to polling data Print("Magic scan total spend time = %lu ms \n\n\n",T2); Print("Press 's' or 'S' to Show AI, others to next step\n\r"); c=Getch(); if(c=='s' || c=='S') ShowAI(); Print("Press 'q' or 'Q' to exit program, others to Start magic scan again!\n\r"); c=Getch(); if(c!='q' && c!='Q') goto start; // continue another test else exit(0); // end of program } // Don't use Print, Getch , Scanf in Interrupt service void ISRFUN(int slot) { short ret; int i; long readCnt=0; IntCnt++; //rawData + totalScanned indicate the array pointer ret= i8014W_ReadFIFO_InISR(slot,rawData + totalScanned, triggerLevel,&readCnt); i8014W_ClearInt(slot); if(ret!=0 || readCnt==MAX_FIFO ) { i8014W_UnInstallMagicScanISR(slot); i8014W_StopMagicScan(slot); return; } if(readCnt>0) { totalScanned+= readCnt; if(totalScanned >=TargetCnt) { i8014W_StopMagicScan(slot); i8014W_UnInstallMagicScanISR(slot); } } } void ShowAI(void) { int i,c; float calibratedAI=0; Print("If want to save result to PC, press 'Alt + C' and input 'L1 log.csv'\n"); Print("Press any key to Start to Print all data:\n\n\r"); c=Getch(); for(i=0;i