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