/* X702IntDemo.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: X702Int Demo. ..\..\..\..\lib\7188xbl.lib or 7186EL.LIB or 7188EL.LIB ..\..\..\..\lib\XBoard\X702.lib Hardware: 7188XB\7188EX\7186EX + X702 Description: Show how to use interrupt(Z axis) to latch encoder counting value. [5/Mar/2010] by Vic */ /********************************************************************************/ /* X702: 2-axis encoder counter */ /********************************************************************************/ #include #include #include #include "..\..\..\..\lib\7188xb.h" #include "..\..\..\..\lib\XBoard\x702.h" extern long EncLatch1,EncLatch2;//defined in int.c extern void InstallInt0Isr(void); extern void InstallInt1Isr(void); extern void RestoreInt0Isr(void); extern void RestoreInt1Isr(void); void read_enc1(long *); void read_enc2(long *); int xor1,xor2,mode1,mode2; long EncVal1,EncVal2; void Show_ABZ(int ch); main() { 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=pule/dir,3=a/b) ?"); mode1=Getch()-'0'; 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=pule/dir,3=a/b) ?"); mode2=Getch()-'0'; X702_SetMode(2,mode2); X702_ResetEncoder(1); X702_ResetEncoder(2); InstallInt0Isr(); //Install interrupt service routine for Z1 InstallInt1Isr(); //Install interrupt service routine for Z2 for (;;) { if (Kbhit()) { RestoreInt0Isr(); RestoreInt1Isr(); 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); Print("(Latch1=%ld,Latch2=%ld)",EncLatch1,EncLatch2); Show_ABZ(2); DelayMs(100); } } void Show_ABZ(int ch) { int index; int A,B,Z,ret; X702_GetLineStatus(ch,&A,&B,&Z); X702_GetIndex(ch,&index); if(index!=Z) { Print("\nX702_GetIndex() function error\n"); exit(1); } Print("Z%dB%dA%d=%d%d%d ",ch,ch,ch,Z,B,A); } void read_enc1(long *enc1) { X702_Read24BitEncoder(1,enc1); } void read_enc2(long *enc2) { X702_Read24BitEncoder(2,enc2); }