/************ Author: Martin Hsu Email: service@icpdas.com Date 2008/03/10 8093 is a 24 bits 3-axis Encode module it can set Encode Mode as 1: cw/ccw ; 2: pulse/dir ; 3: A/B phase Normally, we think 24 bits encode value will be enough for most application. ( 0 ~ 0x7fffff for positive direction, and 0xffffff ~ 0x800000) i8093W_Read24BitEncoder(int slot,int ch, long* EnCode24) will get 24 Bit value , positive direction 0 +++++ ===> 0x007fffff +1 ===> 0xff80000 +++++ ===> 0xffffffff +1 ===> 0 negative direction 0 -1 ===> 0xffffffff ----- ===> 0xff80000 -1 ===> 0x007fffff ----- ===> 0 i8093W_Read32BitEncoder(int slot,int ch, long* EnCode32) will get hardware 24 Bit value + 8 bit software value and get total 32 bit Encoder value , positive direction 0 + 1 ===> 0x00000001 +++++ ===> 0xffffffff +1 ===> 0 negative direction 0 -1 ===> 0xffffffff ----- ===> 0x00000000 -1 ===> 0 #define OK 0 #define ID_ERROR -1 #define SLOT_OUT_RANGE -2 #define CHANNEL_OUT_RANGE -3 #define SELECT_CHANNEL_ERROR -4 #define MODE_ERROR -5 *******************************/ /******************************** 8093 Error Code definition *******************************/ #include "..\..\Lib\8000e.h" #include "..\..\Lib\8093W.h" #include #include char LatchStr[2][32]={"Not Latched", "Latched"}; char ModeStr[4][32]={"Stop", "CW/CCW", "Pulse/Dir","A/B Phase"}; int slotIndex=-1; int runFlag=1; int readFlag=0; int startMode=0; char title[]="Demo for i-8093 Encoder"; void showMenu(void) { Print("\n\n****************************************************\n\r"); Print("Press '1' Step 1 to Set Encoder Mode.\n\r"); Print("Press '2' Step 2 to Set Xor Bit.\n\r"); Print("Press '3' Step 3 to Set Preset Value.\n\r"); Print("Press '4' Step 4 to Read 32 Bit Encoder Value.\n\r"); Print("Press '5' Step 5 to Reset Encoder Value.\n\r"); Print("Press '6' Step 6 to Read Index.\n\r"); Print("Press '7' Step 7 to Read Line Status.\n\r"); Print("Press '8' Step 8 to Read Frequency.\n\r"); Print("Press '9' Step 9 to Set Index Latch Status.\n\r"); Print("Press 'a' Step a to Read Latched Index.\n\r"); Print("Press 'b' Step b to Clear Latched Index.\n\r"); Print("Press 'Q' or 'q' to Exit the program.\n\r"); } int Find_i8093(void) { int i,id,Base,err; for (i=0; i=Now_enVal[ch]) Pre_delta_enVal[ch]=Pre_enVal[ch]-enVal[ch]; else Pre_delta_enVal[ch]=enVal[ch]-Pre_enVal[ch]; Pre_enVal[ch]=enVal[ch]; ret=i8093W_Read32BitEncoder(slotIndex,ch,&enVal[ch]); Print("S[%d]C[%d] %010ld %08lX\t",slotIndex,ch,enVal[ch],enVal[ch]); } Print("\n"); Delay(1000); } showMenu(); break; case '5': //RESET ENCODER VALUE Print("\n\n******** ~ RESET ENCODER VALUE ~ **********\n\r"); Print("Press 'Q' or 'q' to Go Back Main Menu.\n\r"); for(ch=0;ch<3;ch++) { ret=i8093W_ResetEncoder(slotIndex,ch); Print("ret= %d Reset Channel[%d] \n",ret,ch); } showMenu(); break; case '6': //READ INDEX STATUS Print("\n\n******** ~ READ INDEX STATUS ~ **********\n\r"); Print("Press 'Q' or 'q' to Go Back Main Menu.\n\r"); readFlag=1; while(readFlag) { if (Kbhit()) { if(Getch()) readFlag=0; } for(ch=0;ch<3;ch++) { ret=i8093W_GetIndex(slotIndex,ch,&indexVal); Print("S[%d]C[%d] index status %d\n",slotIndex,ch,indexVal); } Delay(500); } showMenu(); break; case '7': //READ LINE STATUS Print("\n\n******** ~ READ LINE STATUS ~ **********\n\r"); readFlag=1; while(readFlag) { if (Kbhit()) { if(Getch()) readFlag=0; } for(ch=0;ch<3;ch++) { ret=i8093W_GetLineStatus(slotIndex, ch, &A_Status,&B_Status,&C_Status); Print("S[%d]C[%d] A_Status[%d] B_Status[%d] C_Status[%d] \n",slotIndex,ch,A_Status,B_Status,C_Status); } Delay(500); } showMenu(); break; case '8': //READ Frequency Print("\n\n******** ~ READ Frequency ~ **********\n\r"); readFlag=1; while(readFlag) { if (Kbhit()) { if(Getch()) readFlag=0; } for(ch=0;ch<3;ch++) { freq=0; ret=i8093W_ReadFreq(slotIndex, ch, &freq); Print("S[%d]C[%d] Freq= %.3f \t",slotIndex,ch,freq); } Print("\n"); Delay(500); } showMenu(); break; case '9': Print("\n\n******** ~ SET Ch Index Latch Status ~ **********\n\r"); Print("Press '0' to Disable Index Latch Status\n"); Print("Press '1' to Enable Index Latch Status\n"); c1=Getch(); if(c1=='0') { for(ch=0;ch<3;ch++) { ret=i8093W_SetIndexLatchStatus(slotIndex,ch,0); Print("\nret= %d Disable Channel[%d] Index Latched Status \n",ret,ch); } } else { for(ch=0;ch<3;ch++) { ret=i8093W_SetIndexLatchStatus(slotIndex,ch,1); Print("\nret= %d Enable Channel[%d] Index Latched Status \n",ret,ch); } } showMenu(); break; case 'a': //READ Index Latched STATUS Print("\n\n******** ~ READ Index Latched STATUS ~ **********\n\r"); readFlag=1; while(readFlag) { if (Kbhit()) { if(Getch()) readFlag=0; } for(ch=0;ch<3;ch++) { ret=i8093W_GetIndexLatchStatus(slotIndex , ch, &latched, &enableLatchStatus); Print("S[%d]C[%d] Z index %s , status 0x%X \n",slotIndex,ch,LatchStr[latched],enableLatchStatus); } Delay(500); } showMenu(); break; case 'b': Print("\n\n******** ~ Clear Index Latched Status ~ **********\n\r"); Print("Press '0~2' to Clear Ch Index Latched Status\n"); c1=Getch(); ch = c1-'0'; i8093W_ClearLatchedIndex(slotIndex, ch); showMenu(); break; case 'Q':case 'q': runFlag= 0; break; } } return 0; }