Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

619 lines
16 KiB

4 years ago
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
4 years ago
​
4 years ago
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
4 years ago
4 years ago
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "StdAfx.h"
  2. #include "ISA.h"
  3. #include "Timer.h"
  4. #include "A2D.h"
  5. #include "SysClock.h"
  6. //#define ENCODER_6000_PULSES
  7. #define LGS_PULSE_COUNT 6000
  8. #define LGS_SERIAL_ENABLE // Enable Embed Serial Number
  9. #ifdef LGS_SERIAL_ENABLE
  10. static WORD wBoardSN = 0xABCD; // Serial Number Of Board
  11. static WORD wProgrammSN = 0;
  12. static BOOL bWorkingEnable = FALSE;
  13. #endif
  14. #ifdef ENCODER_6000_PULSES
  15. #define TEMPERATURE_ENABLE
  16. #else
  17. #define TEMPERATURE_ENABLE
  18. // #define MOTOR_GEAR_RATIO 61 /*150*/ // 61
  19. // #define ENCODER_PULSE_COUNT 6 /*10*/ // 6
  20. #define MOTOR_GEAR_RATIO 150 // 50
  21. #define ENCODER_PULSE_COUNT 1 // 30
  22. #define ENCODER_PULSE_HIRES_COUNT (LGS_PULSE_COUNT / MOTOR_GEAR_RATIO)
  23. #define ENCODER_PULSE_HIRES_REMAIN (LGS_PULSE_COUNT % MOTOR_GEAR_RATIO)
  24. #define HIRES_MEASUREMENT_START_TIME 150
  25. #endif
  26. //#define ISA_DEFAULT_MODE_READ_BUS
  27. sbit ISA_IOW = P3^7;
  28. sbit ISA_IOR = P3^6;
  29. sbit ISA_IOCHRDY = P3^5;
  30. sbit ISA_AEN = P3^4;
  31. sbit ISA_IRQ5 = P1^0;
  32. sbit ISA_BUFFER_OE = P4^6;
  33. sbit ISA_BUFFER_DIR = P4^7; // if low then A = B (ISA = MCU)
  34. sbit ENCODER_PhA = P2^4;
  35. sbit ENCODER_PhB = P2^5;
  36. sbit ENCODER_ZERO = P2^6;
  37. sbit DRY_CONTACT_1 = P1^6;
  38. sbit DRY_CONTACT_2 = P1^7;
  39. sbit LRF_ENABLE = P0^7;
  40. sbit LRF_READY = P2^2;
  41. sbit LRF_SUN_1 = P2^1;
  42. sbit LRF_SUN_2 = P2^0;
  43. sbit HEATER_ENABLE = P0^6;
  44. #define ISA_DIR_IOCHRDY P3MDOUT
  45. #define ISA_DIR_IRQ5 P1MDOUT
  46. #define DRY_CONTACT_DIR P1MDOUT
  47. #define ISA_REGISTER_COUNT 16
  48. // fast variables
  49. static BYTE ISA_bRegEnable = 0;
  50. static BYTE ISA_bRegIndex = 0;
  51. static BYTE ISA_pRegValue[ISA_REGISTER_COUNT];
  52. static BYTE ISA_bTxAddress;
  53. static BYTE ISA_bTxData4[2] = {0};
  54. static BYTE ISA_bTxData5[2] = {0};
  55. static BYTE ISA_bTxIndex = 0;
  56. static BYTE ISA_bAccessCount= 0;
  57. CBYTE ISA_BitReverseTable256[] =
  58. {
  59. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  60. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  61. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  62. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  63. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  64. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  65. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  66. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  67. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  68. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  69. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  70. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  71. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  72. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  73. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  74. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  75. };
  76. // slow variables
  77. static BOOL bZero = TRUE;
  78. static BOOL bZeroCheck = TRUE;
  79. #ifdef ENCODER_6000_PULSES
  80. static BYTE bPhaseStateAB = 0;
  81. #else
  82. static BOOL bReadyZero = FALSE;
  83. static INT nAngle = 0;
  84. static WORD nPulseTime = MICRO_SEC_TO_HIRES(160L);
  85. static BOOL bPhaseCheck = TRUE;
  86. static INT nAngle6 = 0;
  87. static BOOL bReady6 = FALSE;
  88. static INT nPulseCount = 0;
  89. static WORD nHiResolutionCount = 0;
  90. static WORD nHiResolutionTemp = 0;
  91. static DWORD nHiResolutionTimer = 0;
  92. static BYTE nHiResolutionStart = HIRES_MEASUREMENT_START_TIME;
  93. #endif
  94. static BOOL bReset = TRUE;
  95. static UNION_WORD wRange1 = {0};
  96. static UNION_WORD wRange2 = {0};
  97. static WORD wTemperature = 0;
  98. static BOOL bSun1 = FALSE;
  99. static BOOL bSun2 = FALSE;
  100. static INT nZeroShift = 0;
  101. #ifdef TEMPERATURE_ENABLE
  102. static WORD wTemperatureON = 0;
  103. static WORD wTemperatureOFF = 0;
  104. #endif
  105. static BYTE bTemp;
  106. static XBYTE pRelayBuffer[32];
  107. static INT nRelayBuffer = 0;
  108. void ISA_Init()
  109. {
  110. // init fast variables
  111. ISA_bRegEnable = 0;
  112. ISA_bTxIndex = 0;
  113. ISA_bAccessCount = 0;
  114. // init slow variables
  115. bZero = FALSE;
  116. bZeroCheck = TRUE;
  117. #ifdef ENCODER_6000_PULSES
  118. bPhaseStateAB = 0;
  119. #else
  120. bReadyZero = FALSE;
  121. nPulseTime = MICRO_SEC_TO_HIRES(160L);
  122. nAngle = 0;
  123. bPhaseCheck = TRUE;
  124. nAngle6 = 0;
  125. bReady6 = FALSE;
  126. nPulseCount = 0;
  127. nHiResolutionCount = 0;
  128. nHiResolutionTemp = 0;
  129. nHiResolutionTimer = 0;
  130. nHiResolutionStart = HIRES_MEASUREMENT_START_TIME;
  131. #endif
  132. wRange1.wValue = 0;
  133. wRange2.wValue = 0;
  134. wTemperature = 0;
  135. bSun1 = FALSE;
  136. bSun2 = FALSE;
  137. bReset = TRUE;
  138. }
  139. void ISA_Serve()
  140. {
  141. // init DAC0
  142. SFRPAGE = DAC0_PAGE;
  143. DAC0L = 0xFF;
  144. DAC0H = 0xFF;
  145. DAC0CN = 0x80;
  146. SFRPAGE = CONFIG_PAGE;
  147. #ifdef TEMPERATURE_ENABLE
  148. // heater control
  149. P0MDOUT |= (1<<6);
  150. HEATER_ENABLE = TRUE;
  151. #endif
  152. // clear LRF
  153. P0MDOUT |= (1<<7);
  154. LRF_ENABLE = FALSE;
  155. // clear dry contacts
  156. DRY_CONTACT_DIR |= (1<<6);
  157. DRY_CONTACT_DIR |= (1<<7);
  158. DRY_CONTACT_1 = TRUE;
  159. DRY_CONTACT_2 = TRUE;
  160. // clear IRQ5
  161. ISA_DIR_IRQ5 |= (1<<0);
  162. ISA_IRQ5 = 0;
  163. // set ISA data as output
  164. #ifdef ISA_DEFAULT_MODE_READ_BUS
  165. P7MDOUT = 0x00; // set P7 as input
  166. P7 = 0xFF;
  167. #else
  168. P7MDOUT = 0xFF; // set P7 as output
  169. P7 = 0x00;
  170. #endif
  171. #ifndef ENCODER_6000_PULSES
  172. // init HI resolution timer
  173. nHiResolutionCount = HiResTimer0_Get();
  174. nHiResolutionTimer = 0;
  175. nHiResolutionStart = HIRES_MEASUREMENT_START_TIME;
  176. // restart IRQ timer
  177. HiResTimer1_Restart( -nPulseTime );
  178. #endif
  179. SFRPAGE = DAC0_PAGE; // Add 15Sep2009 to speed up motor
  180. DAC0L = 0xFF;
  181. DAC0H = 0xFF; // DAC mid value 0x7D
  182. SFRPAGE = CONFIG_PAGE;
  183. while( TRUE )
  184. {
  185. // process ISA requests
  186. if( ISA_AEN == 0 && P5 == 0x03 )
  187. {
  188. ISA_DIR_IOCHRDY |= (1<<5);
  189. ISA_IOCHRDY = 0; // hold bus circle
  190. if( ISA_IOR == 0 )
  191. {
  192. if( P6 == 0x04 || P6 == 0x05 || P6 == 0x09 || P6 == 0x0A || P6 == 0x0B )
  193. {
  194. ISA_IRQ5 = 0; // clear interrupt
  195. #ifdef ISA_DEFAULT_MODE_READ_BUS
  196. P7MDOUT = 0xFF; // set P7 as output
  197. #endif
  198. ISA_BUFFER_DIR = 0; // set DIR to write to bus
  199. ISA_BUFFER_OE = 0; // set OE low to enable buffer
  200. switch( P6 )
  201. {
  202. case 0x04: P7 = ISA_bTxData4[ISA_bTxIndex]; break;
  203. case 0x05: P7 = ISA_bTxData5[ISA_bTxIndex++]; break;
  204. case 0x09: P7 = 0x5A; break;
  205. // Serial Nuber Handshake
  206. case 0x0A:{
  207. P7 = ISA_BitReverseTable256[ 0xFF & wBoardSN ];
  208. break;
  209. };
  210. case 0x0B:{
  211. P7 = ISA_BitReverseTable256[( wBoardSN >> 8)];
  212. break;
  213. };
  214. }
  215. ISA_IOCHRDY = 1; // ready to end of bus circle
  216. ISA_DIR_IOCHRDY &= ~(1<<5);
  217. if( ISA_bAccessCount ) // decrease access count
  218. ISA_bAccessCount--;
  219. while( ISA_IOR == 0 ); // wait end of bus circle
  220. ISA_BUFFER_OE = 1; // set OE high to Z-state the buffer
  221. #ifdef ISA_DEFAULT_MODE_READ_BUS
  222. P7MDOUT = 0x00; // set P7 as input
  223. P7 = 0xFF;
  224. #endif
  225. }
  226. }
  227. else
  228. if( ISA_IOW == 0 )
  229. {
  230. if( P6 == 0x0A || P6 == 0x0A || P6 == 0x06 || P6 == 0x07 || P6 == 0x08 )
  231. {
  232. ISA_IRQ5 = 0; // clear interrupt
  233. #ifndef ISA_DEFAULT_MODE_READ_BUS
  234. P7MDOUT = 0x00; // set P7 as input
  235. P7 = 0xFF;
  236. #endif
  237. ISA_BUFFER_DIR = 1; // set DIR to read from bus
  238. ISA_BUFFER_OE = 0; // set OE low to enable buffer
  239. switch( P6 )
  240. {
  241. case 0x06: bTemp = P7; bReset = (bTemp ^ ISA_bRegEnable) & 0xC0; ISA_bRegEnable = bTemp; break;
  242. case 0x07: ISA_bRegIndex = ISA_BitReverseTable256[P7] & (ISA_REGISTER_COUNT-1); bReset = TRUE; break;
  243. case 0x08: ISA_pRegValue[ISA_bRegIndex] = ISA_BitReverseTable256[P7]; bReset = TRUE; break;
  244. // Serial Nuber Handshake
  245. case 0x0A:{
  246. bTemp = ISA_BitReverseTable256[P7];
  247. bWorkingEnable = TRUE;
  248. wProgrammSN = bTemp;
  249. break;
  250. };
  251. case 0x0B:{
  252. bTemp = ISA_BitReverseTable256[P7];
  253. bWorkingEnable = TRUE;
  254. wProgrammSN = wProgrammSN & ( bTemp<<8 );
  255. break;
  256. };
  257. }
  258. #ifndef ISA_DEFAULT_MODE_READ_BUS
  259. P7MDOUT = 0xFF; // set P7 as output
  260. #endif
  261. ISA_BUFFER_OE = 1; // set OE high to Z-state the buffer
  262. }
  263. }
  264. ISA_IOCHRDY = 1; // ready to end of bus circle
  265. ISA_DIR_IOCHRDY &= ~(1<<5);
  266. }
  267. #ifdef ENCODER_6000_PULSES
  268. #define PHASE_STATE_AB_MASK ((1<<4)|(1<<5))
  269. // wait for phase change
  270. if( (P2 & PHASE_STATE_AB_MASK) == bPhaseStateAB )
  271. continue;
  272. bPhaseStateAB = P2 & PHASE_STATE_AB_MASK;
  273. #else
  274. // wait for end of ISA serving circle
  275. SFRPAGE = TIMER01_PAGE;
  276. if( !TF1 )
  277. {
  278. SFRPAGE = CONFIG_PAGE;
  279. continue;
  280. }
  281. TF1 = 0;
  282. SFRPAGE = CONFIG_PAGE;
  283. #endif
  284. // if interrupt no LRF is enabled
  285. if( (ISA_bRegEnable & 0xC0) == 0 )
  286. continue;
  287. // reset encoder and timeouts
  288. if( bReset )
  289. {
  290. bReset = FALSE;
  291. ISA_bAccessCount = 0;
  292. ISA_IRQ5 = 0;
  293. bZero = TRUE;
  294. bZeroCheck = FALSE;
  295. if ( wProgrammSN > 0 ) bWorkingEnable = TRUE;
  296. #ifndef ENCODER_6000_PULSES
  297. bReadyZero = FALSE;
  298. nAngle = 0;
  299. nPulseTime = MICRO_SEC_TO_HIRES(160L);
  300. bPhaseCheck = TRUE;
  301. nAngle6 = 0;
  302. bReady6 = FALSE;
  303. nPulseCount = 0;
  304. nHiResolutionCount = 0;
  305. nHiResolutionTemp = 0;
  306. nHiResolutionTimer = 0;
  307. nHiResolutionStart = HIRES_MEASUREMENT_START_TIME;
  308. #endif
  309. nZeroShift = ((WORD)ISA_pRegValue[5] << 8) | ISA_pRegValue[6];
  310. #ifdef TEMPERATURE_ENABLE
  311. wTemperatureON = ADC0_Temperature2Adc( (((LONG)(CHAR)ISA_pRegValue[4]) ) * 10L );
  312. wTemperatureOFF = ADC0_Temperature2Adc( (((LONG)(CHAR)ISA_pRegValue[4]) + 1L) * 10L );
  313. #endif
  314. wRange1.wValue = 0;
  315. wRange2.wValue = 0;
  316. bSun1 = 0;
  317. bSun2 = 0;
  318. SFRPAGE = DAC0_PAGE; // Add 15Sep2009 to speed up motor after reset
  319. DAC0L = 0xFF;
  320. DAC0H = 0xFF; // DAC mid value 0x7D
  321. SFRPAGE = CONFIG_PAGE;
  322. }
  323. #ifndef ENCODER_6000_PULSES
  324. // reset IRQ timer
  325. HiResTimer1_Restart( -nPulseTime );
  326. // calculate hi resolution time
  327. nHiResolutionTemp = HiResTimer0_Get();
  328. nHiResolutionTimer += (DWORD)(nHiResolutionTemp - nHiResolutionCount);
  329. nHiResolutionCount = nHiResolutionTemp;
  330. #endif
  331. // produce zero mark (very importent to syncronize zero mark with encoder positions)
  332. if( ENCODER_ZERO )
  333. {
  334. if( bZeroCheck )
  335. {
  336. bZeroCheck = FALSE;
  337. bZero = TRUE;
  338. #ifndef ENCODER_6000_PULSES
  339. bReadyZero = TRUE;
  340. nAngle = 0;
  341. #endif
  342. }
  343. }
  344. else
  345. bZeroCheck = TRUE;
  346. #ifndef ENCODER_6000_PULSES
  347. // move motor angle
  348. if( ENCODER_PhA )
  349. {
  350. if( bPhaseCheck )
  351. {
  352. bPhaseCheck = FALSE;
  353. // find synch point
  354. if( nAngle6 == ENCODER_PULSE_COUNT )
  355. {
  356. nAngle6 = 0;
  357. bReady6 = TRUE;
  358. // calculate amount of angles until next sync point
  359. nPulseCount += ENCODER_PULSE_HIRES_REMAIN;
  360. if( nPulseCount >= MOTOR_GEAR_RATIO )
  361. {
  362. nPulseCount -= MOTOR_GEAR_RATIO;
  363. nPulseTime = nHiResolutionTimer / ( ENCODER_PULSE_HIRES_COUNT - 1 );
  364. }
  365. else
  366. nPulseTime = nHiResolutionTimer / ( ENCODER_PULSE_HIRES_COUNT ); // changed to +1 from 0 for 6000, in 362 should be 0!!!
  367. // validate time measurement
  368. if( nHiResolutionStart )
  369. {
  370. nHiResolutionStart--;
  371. if( nPulseTime > MICRO_SEC_TO_HIRES(200L) ) // 3 kHz
  372. nPulseTime = MICRO_SEC_TO_HIRES(200L);
  373. }
  374. else
  375. {
  376. if( nPulseTime > MICRO_SEC_TO_HIRES(400L) ) // 2.5 kHz
  377. nPulseTime = MICRO_SEC_TO_HIRES(400L);
  378. }
  379. nHiResolutionTimer = 0;
  380. // update DAC according to speed
  381. SFRPAGE = DAC0_PAGE;
  382. DAC0L = nPulseTime << 2;
  383. DAC0H = nPulseTime >> 6;
  384. /* DAC0L = 0xFF; // DAC mid value
  385. DAC0H = 0x7D;
  386. */
  387. SFRPAGE = CONFIG_PAGE;
  388. }
  389. nAngle6++; //moved from "if" condition to avoid false start without motor
  390. }
  391. }
  392. else
  393. bPhaseCheck = TRUE;
  394. #endif
  395. // set dry contacts
  396. DRY_CONTACT_1 = (ISA_bRegEnable & 0x10) != 0x10;
  397. DRY_CONTACT_2 = (ISA_bRegEnable & 0x20) != 0x20;
  398. // continue to search for zero mark and 6 angles
  399. #ifndef ENCODER_6000_PULSES
  400. if( !bReadyZero || !bReady6 )
  401. continue;
  402. // check zero mark
  403. bZero = (nZeroShift == nAngle);
  404. // move angle
  405. nAngle++;
  406. if( nAngle > LGS_PULSE_COUNT )
  407. continue;
  408. #endif
  409. // if not all data were processed than stop interrupt generation
  410. if( ISA_bAccessCount )
  411. {
  412. ISA_IRQ5 = 0;
  413. ISA_bAccessCount = 0;
  414. ISA_bRegEnable &= ~0xC0;
  415. continue;
  416. }
  417. // start LRF (and temperature measurenment)
  418. LRF_ENABLE = TRUE;
  419. wTemperature = ADC0_Convert( 0x0F );
  420. LRF_ENABLE = FALSE;
  421. // wait for LRF ready (around 15 uS)
  422. // HiResTimer0_Wait( MICRO_SEC_TO_HIRES(15) ); // 20 - ok, but 25 probably better
  423. #ifdef ENCODER_6000_PULSES
  424. // HiResTimer1_Wait( 28+5+15+10 ); // +10 added 2006/11/08
  425. HiResTimer1_Wait( 58 ); // 07Sep2009 try to optimize
  426. #else
  427. // HiResTimer1_Wait( 28+5+10 ); // +10 added 2006/11/08
  428. HiResTimer1_Wait( 30 ); // 07Sep2009 try to optimize (native 43)
  429. #endif
  430. // convert ranges
  431. if( (ISA_bRegEnable & 0x80) == 0x80 )
  432. {
  433. wRange1.wValue = ADC0_Convert( 0x00 );
  434. bSun1 = !LRF_SUN_1;
  435. }
  436. if( (ISA_bRegEnable & 0x40) == 0x40 )
  437. {
  438. wRange2.wValue = ADC0_Convert( 0x01 );
  439. bSun2 = !LRF_SUN_2;
  440. }
  441. #ifdef TEMPERATURE_ENABLE
  442. // heater control
  443. if( HEATER_ENABLE )
  444. {
  445. if( wTemperature < wTemperatureON )
  446. HEATER_ENABLE = FALSE;
  447. }
  448. else
  449. {
  450. // histeresis - one degree of Celsius
  451. if( wTemperature > wTemperatureOFF )
  452. HEATER_ENABLE = TRUE;
  453. }
  454. #endif
  455. #ifdef SPIKES_TEST
  456. if( nAngle & 0x100 )
  457. {
  458. wRange1.wValue = 0x0FFF / 2;
  459. wRange2.wValue = 0x0FFF / 4;
  460. }
  461. else
  462. {
  463. wRange1.wValue = 0x0FFF / 4;
  464. wRange2.wValue = 0x0FFF / 2;
  465. }
  466. #endif
  467. if ( bWorkingEnable ){
  468. // ranges will be negatived on PC side
  469. wRange1.wValue = 0x0FFF - wRange1.wValue;
  470. wRange2.wValue = 0x0FFF - wRange2.wValue;
  471. } else {
  472. wRange1.wValue = 0;
  473. wRange2.wValue = 0;
  474. if ( (nAngle - nZeroShift) == 1113 ) bZero = TRUE;
  475. };
  476. // prepare data for sending to other side
  477. ISA_bTxData4[0] = (ISA_BitReverseTable256[ wRange1.bValue.bLo ] );
  478. ISA_bTxData5[0] = (ISA_BitReverseTable256[ wRange1.bValue.bHi ] & ~0x0F);
  479. ISA_bTxData4[1] = (ISA_BitReverseTable256[ wRange2.bValue.bLo ] );
  480. ISA_bTxData5[1] = (ISA_BitReverseTable256[ wRange2.bValue.bHi ] & ~0x0F);
  481. if( bZero )
  482. {
  483. ISA_bTxData5[0] |= 0x08;
  484. ISA_bTxData5[1] |= 0x08;
  485. bZero = FALSE;
  486. }
  487. if( bSun1 )
  488. {
  489. ISA_bTxData5[0] |= 0x04;
  490. ISA_bTxData5[1] |= 0x04;
  491. }
  492. if( bSun2 )
  493. {
  494. ISA_bTxData5[0] |= 0x02;
  495. ISA_bTxData5[1] |= 0x02;
  496. }
  497. // power OK
  498. ISA_bTxData5[0] |= 0x01;
  499. ISA_bTxData5[1] |= 0x01;
  500. // expected 4 inport reads via ISA bus
  501. ISA_bAccessCount = 4;
  502. ISA_bTxIndex = 0;
  503. // restart ISA bus serve time
  504. ISA_IRQ5 = 1;
  505. }
  506. }