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.

612 lines
31 KiB

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