Rev 250 | Rev 252 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 250 | Rev 251 | ||
---|---|---|---|
Line 239... | Line 239... | ||
239 | 239 | ||
240 | u8 HMC5843_SelfTest(void) |
240 | u8 HMC5843_SelfTest(void) |
241 | { |
241 | { |
242 | u32 time; |
242 | u32 time; |
243 | s32 XMin = 0, XMax = 0, YMin = 0, YMax = 0, ZMin = 0, ZMax = 0; |
243 | s32 XMin = 0, XMax = 0, YMin = 0, YMax = 0, ZMin = 0, ZMax = 0; |
244 | s32 scale, scale_min, scale_max; |
244 | s16 scale, scale_min, scale_max; |
Line 245... | Line 245... | ||
245 | u8 i = 0; |
245 | u8 i = 0; |
246 | 246 | ||
- | 247 | // activate positive bias field of 0.55 gauss |
|
- | 248 | HMC5843_SetConfiguration(HMC5843_CRA_RATE_50HZ|HMC5843_CRA_MODE_POSBIAS, HMC5843_CRB_GAIN_10GA, HMC5843_MODE_CONTINUOUS); |
|
- | 249 | // wait for stable readings |
|
247 | // activate positive bias field of 0.55 gauss |
250 | time = SetDelay(50); |
248 | HMC5843_SetConfiguration(HMC5843_CRA_RATE_50HZ|HMC5843_CRA_MODE_POSBIAS, HMC5843_CRB_GAIN_10GA, HMC5843_MODE_CONTINUOUS); |
251 | while(!CheckDelay(time)); |
249 | // averaging |
252 | // averaging |
250 | for(i = 0; i<20; i++) |
253 | for(i = 0; i<20; i++) |
251 | { |
254 | { |
Line 256... | Line 259... | ||
256 | YMax += MagVector.Y; |
259 | YMax += MagVector.Y; |
257 | ZMax += MagVector.Z; |
260 | ZMax += MagVector.Z; |
258 | } |
261 | } |
259 | // activate negative bias field of 0.55 gauss |
262 | // activate negative bias field of 0.55 gauss |
260 | HMC5843_SetConfiguration(HMC5843_CRA_RATE_50HZ|HMC5843_CRA_MODE_NEGBIAS, HMC5843_CRB_GAIN_10GA, HMC5843_MODE_CONTINUOUS); |
263 | HMC5843_SetConfiguration(HMC5843_CRA_RATE_50HZ|HMC5843_CRA_MODE_NEGBIAS, HMC5843_CRB_GAIN_10GA, HMC5843_MODE_CONTINUOUS); |
- | 264 | // wait for stable readings |
|
- | 265 | time = SetDelay(50); |
|
261 | while(!CheckDelay(time)); |
266 | while(!CheckDelay(time)); |
262 | // averaging |
267 | // averaging |
263 | for(i = 0; i < 20; i++) |
268 | for(i = 0; i < 20; i++) |
264 | { |
269 | { |
265 | HMC5843_GetMagVector(); |
270 | HMC5843_GetMagVector(); |
266 | time = SetDelay(20); |
271 | time = SetDelay(20); |
Line 275... | Line 280... | ||
275 | scale = 715; // 1300 counts/Gauss * 0.55 Gauss = 715 counts |
280 | scale = 715; // 1300 counts/Gauss * 0.55 Gauss = 715 counts |
276 | scale_min = (scale * 90)/100; |
281 | scale_min = (scale * 90)/100; |
277 | scale_max = (scale * 110)/100; |
282 | scale_max = (scale * 110)/100; |
278 | // check scale for all axes |
283 | // check scale for all axes |
279 | scale = (XMax - XMin)/40; |
284 | scale = (XMax - XMin)/40; |
280 | if((scale > scale_max) || (scale < scale_min)) return 0; |
285 | if((scale > scale_max) || (scale < scale_min)) return(0); |
281 | scale = (YMax + YMin)/40; |
286 | scale = (YMax - YMin)/40; |
282 | if((scale > scale_max) || (scale < scale_min)) return 0; |
287 | if((scale > scale_max) || (scale < scale_min)) return(0); |
283 | scale = (ZMax + ZMin)/40; |
288 | scale = (ZMax - ZMin)/40; |
284 | if((scale > scale_max) || (scale < scale_min)) return 0; |
289 | if((scale > scale_max) || (scale < scale_min)) return(0); |
285 | return 1; |
290 | return(1); |
286 | } |
291 | } |
Line 287... | Line 292... | ||
287 | 292 | ||
288 | 293 | ||
Line 304... | Line 309... | ||
304 | { |
309 | { |
305 | HMC5843_GetIdentification(); |
310 | HMC5843_GetIdentification(); |
306 | if (HMC5843_Identification.A != 0xFF) break; // break loop on success |
311 | if (HMC5843_Identification.A != 0xFF) break; // break loop on success |
307 | UART1_PutString("."); |
312 | UART1_PutString("."); |
308 | repeat++; |
313 | repeat++; |
309 | }while ((HMC5843_Identification.A == 0xFF) && (repeat < 12)); // 12*250ms=3s |
314 | }while ((HMC5843_Identification.A == 0xFF) && (repeat < 12)); |
310 | // if we got it |
315 | // if we got it |
311 | if(HMC5843_Identification.A != 0xFF) |
316 | if(HMC5843_Identification.A != 0xFF) |
312 | { |
317 | { |
313 | sprintf(msg, " HMC5843 ID %d/%d/%d", HMC5843_Identification.A, HMC5843_Identification.B, HMC5843_Identification.C); |
318 | sprintf(msg, " HMC5843 ID %d/%d/%d", HMC5843_Identification.A, HMC5843_Identification.B, HMC5843_Identification.C); |
314 | UART1_PutString(msg); |
319 | UART1_PutString(msg); |