#include "ppmc.h"
#include "extintf.h"
#include <stdio.h>
Include dependency graph for ppmc_encoder.c:
Go to the source code of this file.
Defines | |
#define | CONTROLPORT ppmc_base_addr+2 |
#define | DATAPORT ppmc_base_addr+4 |
Functions | |
int | iopl (int level) |
int | EncoderInit (void) |
int | EncoderQuit (void) |
void | SelectInterruptPeriod (long lPeriodSelect) |
int | EncoderLatch () |
int | EncReadAll (LONGBYTE *lbEnc) |
int | ppmcEncoderSetIndexModel (unsigned int model) |
int | ppmcEncoderNum () |
int | ppmcEncoderRead (int encoder, double *counts) |
int | ppmcEncoderReadAll (int max, double *counts) |
int | ppmcEncoderReadLatch (int encoder, int *flag) |
int | ppmcEncoderReadLevel (int encoder, int *flag) |
int | ppmcEncoderResetIndex (int encoder) |
|
Definition at line 59 of file ppmc_encoder.c. |
|
Definition at line 60 of file ppmc_encoder.c. |
|
Definition at line 157 of file ppmc_encoder.c. 00158 { 00159 static unsigned char byOldByte2[PPMC_MAX_AXIS]; 00160 static unsigned char byEncHighByte[PPMC_MAX_AXIS]; 00161 short i,max; 00162 00163 SelAddr(ENCCNT0); 00164 // outb(0x24,CONTROLPORT); // set EPP port to input mode 00165 max = PPMC_MAX_AXIS; 00166 if (max > 4) max = 4; 00167 for (i = 0; i < max; i++) /* 24 bits means get 3 bytes each */ 00168 { 00169 lbEnc[i].Byte[0] = ReadData(); 00170 lbEnc[i].Byte[1] = ReadData(); 00171 lbEnc[i].Byte[2] = ReadData(); 00172 /* lbEnc[i].Byte[0] = inb(DATAPORT); 00173 lbEnc[i].Byte[1] = inb(DATAPORT); 00174 lbEnc[i].Byte[2] = inb(DATAPORT); */ 00175 } 00176 #ifdef PPMC_8_AXES 00177 if (PPMC_MAX_AXIS > 4) 00178 { 00179 SelAddr(ENCCNT4); 00180 for (i = 4; i < PPMC_MAX_AXIS; i++) /* 24 bits means get 3 bytes each */ 00181 { 00182 lbEnc[i].Byte[0] = ReadData(); 00183 lbEnc[i].Byte[1] = ReadData(); 00184 lbEnc[i].Byte[2] = ReadData(); 00185 } 00186 } 00187 #endif 00188 00189 /* code to sign extend the 24 bit value */ 00190 /* but we won't do this. */ 00191 /*for ( i = 0; i < 8; i++) */ 00192 /* lbEnc[i].Byte[3] = lbEnc[i].Byte[2] & 0x80 ? 0xff : 0; */ 00193 00194 /* maintain the high byte, to extend the counter to 32 bits */ 00195 /* */ 00196 /* base decisions to increment or decrement the high byte */ 00197 /* on the highest 2 bits of the 24 bit value. To get the */ 00198 /* highest 2 bits, use 0xc0 as a mask on byte [2] (the third */ 00199 /* byte). */ 00200 00201 for (i = 0; i < PPMC_MAX_AXIS; i++) 00202 { 00203 /* check for -1 to 0 transition */ 00204 00205 if ( ( (byOldByte2[i] & 0xc0) == 0xc0 ) /* 11xxxxxx */ 00206 && ( (lbEnc[i].Byte[2] & 0xc0) == 0 ) /* 00xxxxxx */ 00207 ) 00208 byEncHighByte[i]++; 00209 00210 /* check for 0 to -1 transition */ 00211 00212 if ( ( (byOldByte2[i] & 0xc0) == 0 ) /* 00xxxxxx */ 00213 && ( (lbEnc[i].Byte[2] & 0xc0) == 0xc0 ) /* 11xxxxxx */ 00214 ) 00215 byEncHighByte[i]--; 00216 00217 lbEnc[i].Byte[3] = byEncHighByte[i]; 00218 byOldByte2[i] = lbEnc[i].Byte[2]; /* current byte 2 becomes old one */ 00219 } 00220 00221 return 0; 00222 } |
|
Definition at line 64 of file ppmc_encoder.c. 00065 { 00066 #ifdef PPMC_8_AXES 00067 unsigned int wAdd; 00068 #endif 00069 short success=0; 00070 00071 00072 /* set all channels to normal mode (no find index, no load counters */ 00073 SelWrt(ENCCTRL_0,0); 00074 #ifdef PPMC_8_AXES 00075 SelWrt(ENCCTRL_1,0); 00076 SelWrt(ENCRATE_1,0); // in all cases, the 2nd encoder board is slaved to first 00077 #endif 00078 // SelWrt(ENCRATE_0,0x10); // make encoder board 0 master 00079 SelWrt(ENCRATE_0,0x00); // don't make encoder board 0 master for software latch 00080 // zero the encoder counters ( not needed ) 00081 SelWrt(ENCLOAD_0,0); /* clear 3-byte preload register */ 00082 WriteData(0); 00083 WriteData(0); 00084 SelWrt(ENCCTRL_0,0xF0); /* select load pos counter # and enable */ 00085 SelWrt(ENCCTRL_0,0xF0); /* select load pos counter # and enable */ 00086 SelWrt(ENCCTRL_0,0xF0); /* delay to give time for load to take place */ 00087 SelWrt(ENCCTRL_0,0xF0); /* more delay */ 00088 SelWrt(ENCCTRL_0,0); /* turn off load position counter function */ 00089 00090 #ifdef PPMC_8_AXES 00091 SelWrt(ENCLOAD_1,0); /* clear 3-byte preload register */ 00092 WriteData(0); 00093 WriteData(0); 00094 for (wAdd = 0; wAdd <= 3; wAdd ++) 00095 { 00096 SelWrt(ENCCTRL_1,(unsigned char)((wAdd>>3)+32)); /* select load pos counter # and enable */ 00097 } 00098 SelWrt(ENCCTRL_1,0); /* turn off load position counter function */ 00099 #endif 00100 return success; 00101 } |
|
Definition at line 148 of file ppmc_encoder.c. |
|
Definition at line 102 of file ppmc_encoder.c. 00103 { 00104 return 0; 00105 } |
|
Definition at line 106 of file ppmc_encoder.c. 00107 { 00108 #ifdef PPMC_8_AXES 00109 SelWrt(ENCRATE_1,0); /* set 2nd board to slave timer mode */ 00110 #endif 00111 00112 switch (lPeriodSelect) 00113 { 00114 case _500_MICROSECONDS: 00115 SelWrt(ENCRATE_0,0x0B); /* master mode, 10 KHz / 5 = 2 KHz */ 00116 break; 00117 case _1_MILLISECOND: 00118 SelWrt(ENCRATE_0,0x16); /* master mode, 10 KHz / 10 = 1 KHz */ 00119 break; 00120 case _2_MILLISECONDS: 00121 SelWrt(ENCRATE_0,0x00); /* master mode, 10 KHz / 16 = 0.667 KHz */ 00122 break; 00123 case _3_MILLISECONDS: 00124 SelWrt(ENCRATE_0,0x10); /* master mode, 10 KHz / 10 = 1 KHz */ 00125 break; 00126 case _4_MILLISECONDS: 00127 SelWrt(ENCRATE_0,0x10); /* master mode, 10 KHz / 10 = 1 KHz */ 00128 break; 00129 case _5_MILLISECONDS: 00130 SelWrt(ENCRATE_0,0x10); /* master mode, 10 KHz / 10 = 1 KHz */ 00131 break; 00132 case _10_MILLISECONDS: 00133 SelWrt(ENCRATE_0,0x10); /* master mode, 10 KHz / 10 = 1 KHz */ 00134 break; 00135 case _100_MILLISECONDS: 00136 SelWrt(ENCRATE_0,0x10); /* master mode, 10 KHz / 10 = 1 KHz */ 00137 break; 00138 case _1_SECOND: 00139 SelWrt(ENCRATE_0,0x10); /* master mode, 10 KHz / 10 = 1 KHz */ 00140 break; 00141 default: 00142 /* wrong input? then don't change it */ 00143 break; 00144 } 00145 } |
|
Definition at line 50 of file ppmc_encoder.c. 00051 { 00052 return 0; 00053 } |
|
Definition at line 236 of file ppmc_encoder.c. Referenced by extEncoderNum().
00237 { 00238 return PPMC_MAX_AXIS; 00239 } |
|
Definition at line 241 of file ppmc_encoder.c. Referenced by extEncoderRead().
00242 { 00243 double allCounts[PPMC_MAX_AXIS]; 00244 00245 if (encoder < 0 || 00246 encoder >= PPMC_MAX_AXIS) { 00247 *counts = 0.0; 00248 return 0; 00249 } 00250 00251 ppmcEncoderReadAll(encoder + 1, allCounts); 00252 00253 *counts = allCounts[encoder]; 00254 00255 return 0; 00256 00257 } |
|
Definition at line 259 of file ppmc_encoder.c. Referenced by extEncoderReadAll(), main(), and ppmcEncoderRead().
00260 { 00261 LONGBYTE lbEnc[PPMC_MAX_AXIS]; 00262 int t; 00263 int smax; /* how many we actually have */ 00264 00265 /* clip smax to max supported-- if they want more, give 00266 them zeros */ 00267 if (max > PPMC_MAX_AXIS) { 00268 smax = PPMC_MAX_AXIS; 00269 } 00270 else { 00271 smax = max; 00272 } 00273 00274 EncoderLatch(); 00275 EncReadAll(lbEnc); 00276 00277 /* fill ours with the actual values */ 00278 for (t = 0; t < smax; t++) { 00279 counts[t] = (double) lbEnc[t].Long; 00280 } 00281 /* and fill the rest with zeros */ 00282 for (t = smax; t < max; t++) { 00283 counts[t] = 0.0; 00284 } 00285 00286 return 0; 00287 } |
|
Definition at line 297 of file ppmc_encoder.c. Referenced by extEncoderReadLatch(), main(), ppmcEncoderReadLevel(), and ppmcEncoderResetIndex().
00298 { 00299 #ifdef NO_INDEX_PULSE 00300 *flag = 1; 00301 return 0; 00302 #else 00303 short int index_sense_data; 00304 short int index_mask; 00305 00306 if (encoder>PPMC_MAX_AXIS) return -1; //not that many encoders 00307 #ifdef PPMC_8_AXES 00308 if (encoder>=4) 00309 { 00310 index_sense_data=SelRead(ENCISR_1); 00311 index_mask=(1<<((short)encoder-4)); 00312 if(index_sense_data&index_mask)*flag=1; 00313 else *flag=0; 00314 return 0; 00315 } 00316 #endif 00317 //either wasn't 8 axis or was first encoder board 00318 index_sense_data=SelRead(ENCISR_0); 00319 index_mask=(1<<((short)encoder)); 00320 if(index_sense_data&index_mask)*flag=1; 00321 else *flag=0; 00322 return 0; 00323 00324 #endif 00325 } |
|
Definition at line 327 of file ppmc_encoder.c. Referenced by extEncoderReadLevel(), and main().
00328 { 00329 return ppmcEncoderReadLatch(encoder,flag); 00330 } |
|
Definition at line 333 of file ppmc_encoder.c. Referenced by extEncoderResetIndex(), and main().
00334 { 00335 int dummyflag; 00336 return ppmcEncoderReadLatch(encoder,&dummyflag); 00337 00338 } |
|
Definition at line 226 of file ppmc_encoder.c. Referenced by extEncoderSetIndexModel().
00227 { 00228 if (model != EXT_ENCODER_INDEX_MODEL_MANUAL) 00229 { 00230 return -1; 00231 } 00232 00233 return 0; 00234 } |