Rev 22 | Rev 25 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 22 | Rev 23 | ||
---|---|---|---|
Line 71... | Line 71... | ||
71 | int16_t RawMagnet2a, RawMagnet2b; |
71 | int16_t RawMagnet2a, RawMagnet2b; |
72 | int16_t RawMagnet3a, RawMagnet3b; |
72 | int16_t RawMagnet3a, RawMagnet3b; |
Line 73... | Line 73... | ||
73 | 73 | ||
Line 74... | Line 74... | ||
74 | uint16_t Led_Timer = 0; |
74 | uint16_t Led_Timer = 0; |
75 | 75 | ||
76 | typedef struct |
76 | struct Scaling_t |
77 | { |
77 | { |
78 | int16_t Range; |
78 | int16_t Range; |
Line 79... | Line 79... | ||
79 | int16_t Offset; |
79 | int16_t Offset; |
80 | } Scaling_t; |
80 | } ; |
81 | 81 | ||
82 | typedef struct |
82 | struct Calibration_t |
83 | { |
83 | { |
84 | Scaling_t X; |
84 | struct Scaling_t X; |
Line 85... | Line 85... | ||
85 | Scaling_t Y; |
85 | struct Scaling_t Y; |
86 | Scaling_t Z; |
86 | struct Scaling_t Z; |
Line 87... | Line 87... | ||
87 | } Calibration_t; |
87 | } ; |
88 | 88 | ||
Line 123... | Line 123... | ||
123 | { |
123 | { |
124 | LED_GRN_TOGGLE; |
124 | LED_GRN_TOGGLE; |
125 | Led_Timer = SetDelay(500); |
125 | Led_Timer = SetDelay(500); |
126 | } |
126 | } |
Line 127... | Line -... | ||
127 | - | ||
128 | 127 | ||
129 | Cx = MagnetX; |
128 | Cx = MagnetX; |
130 | Cy = MagnetY; |
129 | Cy = MagnetY; |
Line 131... | Line 130... | ||
131 | Cz = MagnetZ; |
130 | Cz = MagnetZ; |
Line 165... | Line 164... | ||
165 | 164 | ||
166 | // check both sources of communication for calibration request |
165 | // check both sources of communication for calibration request |
167 | if(I2C_WriteCal.CalByte) cal = I2C_WriteCal.CalByte; |
166 | if(I2C_WriteCal.CalByte) cal = I2C_WriteCal.CalByte; |
Line -... | Line 167... | ||
- | 167 | else cal = ExternData.CalState; |
|
168 | else cal = ExternData.CalState; |
168 | |
169 | 169 | ||
170 | DebugOut.Analog[30] = cal; |
170 | if(cal > 5) cal = 0; |
171 | // blink code for current calibration state |
171 | // blink code for current calibration state |
172 | if(cal) |
172 | if(cal) |
173 | { |
173 | { |
Line 192... | Line 192... | ||
192 | else |
192 | else |
193 | { |
193 | { |
194 | LED_GRN_OFF; |
194 | LED_GRN_OFF; |
195 | } |
195 | } |
Line 196... | Line -... | ||
196 | - | ||
197 | 196 | ||
198 | // calibration state machine |
197 | // calibration state machine |
199 | switch(cal) |
198 | switch(cal) |
200 | { |
199 | { |
201 | case 0: // no calibration |
200 | case 0: // no calibration |
Line 242... | Line 241... | ||
242 | Calibration.Z.Offset = (Zmin + Zmax) / 2; |
241 | Calibration.Z.Offset = (Zmin + Zmax) / 2; |
243 | if((Calibration.X.Range > 150) && (Calibration.Y.Range > 150) && (Calibration.Z.Range > 150)) |
242 | if((Calibration.X.Range > 150) && (Calibration.Y.Range > 150) && (Calibration.Z.Range > 150)) |
244 | { |
243 | { |
245 | // indicate write process by setting the led |
244 | // indicate write process by setting the led |
246 | LED_GRN_ON; |
245 | LED_GRN_ON; |
247 | eeprom_write_block(&Calibration, &eeCalibration, sizeof(Calibration_t)); |
246 | eeprom_write_block(&Calibration, &eeCalibration, sizeof(Calibration)); |
248 | Delay_ms(2000); |
247 | Delay_ms(2000); |
249 | // reset led state |
248 | // reset led state |
250 | LED_GRN_OFF; |
249 | LED_GRN_OFF; |
251 | // reset blinkcode |
250 | // reset blinkcode |
252 | blinkcount = 0; |
251 | blinkcount = 0; |
Line 280... | Line 279... | ||
280 | DebugOut.Analog[13] = Calibration.Z.Range; |
279 | DebugOut.Analog[13] = Calibration.Z.Range; |
281 | DebugOut.Analog[14] = ExternData.CalState; |
280 | DebugOut.Analog[14] = ExternData.CalState; |
282 | DebugOut.Analog[15] = Heading; |
281 | DebugOut.Analog[15] = Heading; |
283 | DebugOut.Analog[16] = ExternData.UserParam[0]; |
282 | DebugOut.Analog[16] = ExternData.UserParam[0]; |
284 | DebugOut.Analog[17] = ExternData.UserParam[1]; |
283 | DebugOut.Analog[17] = ExternData.UserParam[1]; |
285 | DebugOut.Analog[30] = I2C_WriteCal.CalByte; |
- | |
286 | DebugOut.Analog[31] = PC_Connected; |
- | |
287 | } |
284 | } |
Line 288... | Line 285... | ||
288 | 285 | ||
289 | 286 | ||
Line 305... | Line 302... | ||
305 | 302 | ||
306 | Debug_Timer = SetDelay(200); |
303 | Debug_Timer = SetDelay(200); |
Line 307... | Line 304... | ||
307 | Led_Timer = SetDelay(200); |
304 | Led_Timer = SetDelay(200); |
308 | 305 | ||
Line 309... | Line 306... | ||
309 | // read calibration info from eeprom |
306 | // read calibration info from eeprom |
310 | eeprom_read_block(&Calibration, &eeCalibration, sizeof(Calibration_t)); |
307 | eeprom_read_block(&Calibration, &eeCalibration, sizeof(Calibration)); |
311 | 308 | ||
Line 312... | Line -... | ||
312 | ExternData.Orientation = 0; |
- | |
Line 313... | Line 309... | ||
313 | ExternData.CalState = 0; |
309 | ExternData.Orientation = 0; |
314 | I2C_WriteCal.CalByte = 0; |
310 | ExternData.CalState = 0; |
315 | 311 | I2C_WriteCal.CalByte = 0; |
|
316 | Heading = 101; |
- | |
317 | - | ||
318 | // main loop |
312 | |
319 | while (1) |
313 | |
320 | { |
314 | // main loop |
321 | 315 | while (1) |
|
322 | 316 | { |
|
Line 340... | Line 334... | ||
340 | if(ExternData.CalState || I2C_WriteCal.CalByte) Calibrate(); |
334 | if(ExternData.CalState || I2C_WriteCal.CalByte) Calibrate(); |
341 | else CalcHeading(); |
335 | else CalcHeading(); |
Line 342... | Line 336... | ||
342 | 336 | ||
343 | // check data from USART |
337 | // check data from USART |
- | 338 | USART0_ProcessRxData(); |
|
Line 344... | Line 339... | ||
344 | USART0_ProcessRxData(); |
339 | USART0_TransmitTxData(); |
345 | 340 | ||
346 | if(PC_Connected) |
341 | if(PC_Connected) |
347 | { |
342 | { |