Friday, October 28, 2011

Hi-Resolution Custom Compass

I have completed the assembly of my custom compass.

As explained in a previous post, it has a resolution of better than 0.1 degree, and calculates a new tilt-compensated heading more than 10 times per second.

To achieve the output rate of 10 Hz, the compass makes use of 3 MicroMag3 magnetometers working in parallel, each one being responsible for only one axis. In the following figure, the active coil of each magnetometer is marked by a red circle.

I came to the conclusion that a gyro is not needed in a marine compass, as the rate of turn can be calculated from the calibrated output of a fast compass.

The final accuracy of a compass depends entirely on the quality of the calibration, that will be completed as described in the last 3 posts.

After that, I will make comparative tests between this compass and the Airmar H2183.

UPDATE: Some test results

Here is a graph comparing the calibrated output of both compass during a short test run (click on the figure to zoom in). The Airmar H2183 is in blue, and the Hi-Res is in red. Each horizontal division is 0.1 second, so that this excerpt covers around 2 minutes. Over the extended test run that had a duration of 6 minutes, the average difference between the 2 compass has been 0.1 degree. The H2183 seems to overreact somewhat to changes in heading and may thus require more damping. This is also evident from the calibration test run ( I did not found the time to test the instantaneous readings during a typical tack as planned, this will be for next summer. Bottom line : quality of calibration is much more imporant that anything else.




  1. I am very impressed by the ground you have covered on this project.

    I am currently investigating this area for similar objectives as well as a tentative fro a custom autopilot. As sensors such as accurante and tilt compensated compass are a must, I came accross your blog.

    I understand that you were targeting 10Hz sampling rate which finally led you to handle 3 MicroMag3 in parallel as well as the inevitable accelerometers. Is there a specific reason for the 10Hz target ; would you think a 5Hz one could be acceptable and if yes, would an integrated chip such as the HMC6343 be appropriate ?

    Thanks in advance for your comments.


    1. My choice of 10 Hz for the whole system was a design goal that I figured was achievable with simple 8-bit microcontrollers. So I try to get this 10 Hz refresh rate from all the individual components.

      Actually my Airmar H2183 compass has a 5 Hz refresh rate at 4800 baud, but I learned from a commenter that I can get 10 Hz by pushing the baud rate to 38400, although I have not implemented it yet.

      I am quite unconvinced of the quality of the calibration that you can get from the built-in procedures in commercial instruments, but I understand that it is extremely difficult to develop generic procedures for a general audience. This is where you can win with a custom system.

      My hi-resolution compass will be installed next summer alongside the H2183, and I will then have a better idea of its performance. The H2183 claims a 1 deg RMS static accuracy when level. The HMC6343 claims a typical 2 deg RMS when level, and 3 deg RMS with a 15 deg tilt. I think that my hi-resolution compass will be better than 0.5 deg RMS in all these cases.

      The real test will be in dynamic conditions, when the heel and tilt angles are continually oscillating, producing parasitic accelerations that will be interpreted as excess heel and tilt range by the accelerometer. The H2183 has a 3-axis gyro to help correct for this. For the hi-resolution compass, I will experiment with different digital filters: as the parasitic accelerations are periodic, it should be possible to filter them away.

      It is very difficult to tell what would be the HMC6343 performance in dynamic conditions, without submitting it to real tests on the water alongside some reference compass.

      For an autopilot, I think that a 5 Hz refresh rate is fully acceptable, if the data is otherwise accurate and responsive. Hi-quality autopilot software also uses the rate of turn from a gyrocompass to achieve a better performance.

      My ultimate goal (dream) as a sailor is to see a stable wind direction value on my instruments during a tack, when the boat is changing direction while the heel angle passes from -20 deg to 20 deg.

  2. Hello, do you have any idea what are the output units of the MicroMag3? And how to maximize the resolution of the sensor?

    1. The output units of the MicroMag3 are, for each of the 3 axis, an integer value (a count), positive or negative depending on the orientation of the magnetic field in the measured axis.

      You adjust the resolution with the period select(PS) setting (bits PS2,PS1 and PS0 of the command byte, see p. 10 of the datasheet) :

      PS 32 : 0.49 counts/uT uT: microtesla
      PS 64 : 0.98
      PS 128: 1.95
      PS 256: 3.91
      PS 512: 7.81
      PS 1024: 15.62
      PS 2048: 31.24
      PS 4096: 62.48

      Thus, for a Earth's magnetic field of 58 uT, you will get a maximum count (positive or negative) of:

      PS 32 : 28 counts
      PS 64 : 57
      PS 128: 113
      PS 256: 226
      PS 512: 453
      PS 1024: 906
      PS 2048: 1812
      PS 4096: 3624

      If you choose a high resolution, the sampling time is longer and the sampling frequency is thus reduced. To get the highest resolution (which I do), you set the Period Select to 4096.

    2. My name is Ricardo, I'm a brazilian student of electrical engineering. I'm working in a magnetometer.
      I didn't quite understand how I should act to obtain the measurement in uT.
      I'm basing this code
      Could you help me?

      Sorry for my terrible english and congratulations for your project.

    3. Ricardo, from what I understand from the code you are using, you are measuring each axis as an integer number (counts), and there are 31.24 counts per microtesla (period select of 2048).

  3. So how did the comparison between the two compasses work out?

    1. I have added an update to this post with some test results.