/* X702RencDemo.C: Demo program for X702 Compiler: BC++ 3.1 Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum) Compile mode: large Project: X702Renc Demo. ..\..\..\..\lib\7188xbl.lib or 7186EL.LIB or 7188EL.LIB ..\..\..\..\lib\XBoard\X702.lib Hardware: 7188XB\7188EX\7186EX + X702 Description: Setting for encode: Step1: Set XOR logic Step2: Choose encode counting mode => cw/ccw,pulse/dir,(Quadrant)a/b phase Step3: Read encode counting value [5/Mar/2010] by Vic */ /********************************************************************************/ /* X702: 2-axis encoder counter */ /********************************************************************************/ #include #include "..\..\..\..\lib\7188xb.h" #include "..\..\..\..\lib\XBoard\x702.h" int xor1,xor2,mode1,mode2; long EncVal1,EncVal2; void read_enc1( long *); void read_enc2(long *); void main(void) { char Mode[3][15]={"cw\ccw","pulse/dir","a/b"}; InitLib(); X702_Init(); Print("\nxor1 = (0 or 1) ?"); xor1=Getch()-'0'; if (xor1) xor1=1; X702_SetXOR(1,xor1); try_again1: Print("\nmode1 = (1=cw/ccw,2=pulse/dir,3=a/b) ?"); mode1=Getch()-'0'; if(mode1<1 || mode1>3) goto try_again1; X702_SetMode(1,mode1); Print("\nxor2 = (0 or 1) ?"); xor2=Getch()-'0'; if (xor2) xor2=1; X702_SetXOR(2,xor2); try_again2: Print("\nmode2 = (1=cw/ccw,2=pulse/dir,3=a/b) ?"); mode2=Getch()-'0'; if(mode2<1 || mode2>3) goto try_again2; X702_SetMode(2,mode2); X702_ResetEncoder(1); X702_ResetEncoder(2); for (;;) { if (Kbhit()) { Getch(); return; } read_enc1(& EncVal1); read_enc2(&EncVal2); Print("\n(mode1=%s,enc1=%ld) (mode2=%s,enc2=%ld)",Mode[mode1-1],EncVal1,Mode[mode2-1],EncVal2); DelayMs(100); } } // --------------------------------------------------------------- void read_enc1(long *enc1) { X702_Read24BitEncoder(1,enc1); } void read_enc2(long *enc2) { X702_Read24BitEncoder(2,enc2); }