Shop OBEX P1 Docs P2 Docs Learn Events
APPLICATION DEMO: Calibrating the HM55B Compass using code from the OBEX — Parallax Forums

APPLICATION DEMO: Calibrating the HM55B Compass using code from the OBEX

Beau SchwabeBeau Schwabe Posts: 6,568
edited 2009-05-21 04:31 in Propeller 1
Here is a brief explanation on what to do and how to calibrate the HM55B Compass module.
·
1)·Get the latest program from the OBEX located here... http://obex.parallax.com/objects/48/
·
2) Build the Circuit for the Propeller to communicate with the Compass. (schematic details can be found within the Serial or TV SPIN files from the OBEX)

attachment.php?attachmentid=59938
·
3)·Print·the compass image attached to this post, or download the HM55B documentation from the product page located here... http://www.parallax.com/Portals/0/Downloads/docs/prod/compshop/HM55BModDocs.pdf
·· ... and print page 3 from the PDF.

attachment.php?attachmentid=59936
·
4) Do you know where North is?· I guess that's sort of the point here using a compass isn't it?· Ok, to avoid the Chicken and the Egg scenario, you'll need to determine North either by way of a store bought compass, or lodestone suspended by a string.smilewinkgrin.gif
·
5) Once you are sure·which direction·North is, orient and secure the print-out from step #3 ... I taped mine to a cardboard box away from any metallic objects or my computer.
·
6) Double check all of your wiring and run the Spin program called·... 'HM55B Compass Module Serial DEMO· V1.1'· ... by pressing F10
·
7) Start the Parallax serial terminal (PST.exe), you should see a screen similar to this one...

attachment.php?attachmentid=59937
·
8) Open the program TAB 'HM55B Compass Calibration' by clicking on the program tree located on the left hand side of the Propeller IDE.
·
9) Scroll down to the very bottom of the 'HM55B Compass Calibration'
·
If you have made it this far, the hard part is over
·
10) Point the Demo Board (with compass) in each direction indicated on the print-out.· (There are a total of 16 positions)· For each position make note of the RAW value displayed from the PST and enter·the value into the corresponding "word" position in the 'HM55B Compass Calibration' program.
·
11)· After you have entered in all 16 positions, that's it, you’re done; the 'HM55B Compass Calibration' program is now calibrated to your compass module.

attachment.php?attachmentid=59939
·
Note: from step #10 , it might be easier to write down all of the RAW values first, and then enter them into 'HM55B Compass Calibration' at a later time.
·
·
Running the Program without the DEMO program:
·
·
Setup Block:
CON ''General Constants for Propeller Setup     
    _CLKMODE = XTAL1 + PLL16X 
    _XINFREQ = 5_000_000 

CON ''Setup Constants for the Compass 
    Enable = 0 
    Clock = 1 
    Data = 2 

{{
            ┌────┬┬────┐
      ┌────│1  6│── +5V       P0 = Enable
      │ 1K  │  ├┴──┴┤  │               P1 = Clock
  P2 ┻──│2 │ /\ │ 5│── P0        P2 = Data
            │  │/  \│  │
    VSS ──│3 └────┘ 4│── P1
            └──────────┘
}}

VAR ''Setup variables related to the compass 
    long RawHeading, CorrectHeading
 
OBJ ''Setup Object references that make this demo work 
    HM55B : "HM55B Compass Module Asm" 
    Calibrate : "HM55B Compass Calibration"

Initialization·Block
HM55B.start(Enable,Clock,Data) '' Initialize Compass Object

Main Program Block
RawHeading := HM55B.Theta ' Read RAW 13-bit Angle 
CorrectHeading := Calibrate.Correct(RawHeading) ' Calibrate Correct Heading

·
Basically after setup and initialization, you read the RAW heading directly from the Compass module, and then pass it through the Calibration program which in turn provides an output of the correct heading.


Going Further ...·The·DEMO program with TV output provides a different feel than the serial ASCII version.

This object is also included with the OBEX download.· Simply run the 'HM55B Compass Module_TVDemo_V1.4.spin'·and connect a TV to the video output on the Propeller Demo board instead.· The TV output shows two Compass Arrows indicating the RAW·direction before calibration in "RED" and at the same time it shows the corrected heading after calibration in 'YELLOW'.

attachment.php?attachmentid=59941

·
·
··

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe

IC Layout Engineer
Parallax, Inc.

Post Edited (Beau Schwabe (Parallax)) : 4/8/2009 10:13:38 PM GMT
725 x 725 - 85K
672 x 608 - 64K
2304 x 1728 - 660K
320 x 240 - 33K

Comments

  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-04-08 19:27
    This is an strange question; but what is the Parallax Serial terminal?? Just wondering.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Toys are microcontroled.
    Robots are microcontroled.
    I am microcontrolled.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-04-08 19:35
    microcontroled,

    The Parallax Serial terminal is designed to work with the Propeller in a similar way that the DEBUG terminal works with the Basic StampII.

    I have updated the link in my post (thank you I menat to do that anyway), but you can find the PST.exe program here ... http://www.parallax.com/tabid/442/Default.aspx




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Dennis FerronDennis Ferron Posts: 480
    edited 2009-04-11 18:39
    I found a problem with the compass calibration code: it assumes the values in the table will always go up from the beginning of the table to the end. If you happen to have your 8192 to 0 transition occur in the middle of the table instead of at the end (for instance, I calibrated my compass against true north instead of magnetic north) then the original compass calibration object will not make it through the whole calibration table when it looks up the numbers.

    I've attached a zip file that includes a new version 1.1 of the compass calibration object in which I've completely rewritten the DetectRange subroutine so that it doesn't have this problem. The new code is actually simpler (more comments but fewer 'if' statements) and hopefully more reliable.

    (I had to take the spaces out of the file name because it crashed the attachment manager when there were spaces in the file name.)

    Edit: Don't use the one that was attached here; it has a different bug. Use the new one from my post two posts down from here. Thanks.

    Post Edited (Dennis Ferron) : 4/11/2009 7:31:31 PM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-04-11 18:51
    Dennis Ferron,

    Thanks, I'll take a look at it and update the OBEX

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Dennis FerronDennis Ferron Posts: 480
    edited 2009-04-11 19:27
    Hang on! The version I posted above fixes that problem, but in the process introduces a different problem. (It's surprisingly hard to get this right with the wrap-around condition...)

    Attached is the final, fully corrected version. You can run through the entire 360 degrees without any "unexpected jumps";
  • SuperCricketSuperCricket Posts: 17
    edited 2009-04-11 21:14
    Well this is awesome because I was just about to order one to goof around with. Are these things really not calibrated that well from the factory? How many degrees off are they usually from the actual?
  • Dennis FerronDennis Ferron Posts: 480
    edited 2009-04-11 21:44
    I think the issue is that you might have some residual magnetism in the device you're putting the compass in, so they can't really calibrate for that because every place is going to be different. I ended up I think calibrating it 22 degrees from "stock" but I was calibrating it against true north, which is already 10 degrees itself from magnetic north. So really it was more like 12 degrees that I changed it.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-04-11 22:02
    SuperCricket,
    Dennis is correct about·residual magnetism in the device, but much of it depends on the environment and the geographical location.· The natural occurring Earth magnetism·itself is not perfectly balanced and can skew the readings.· Geographic’s makes a difference also... If you were to map out the apparent magnetic strength similar to that of a Smith chart, you'd see·the pattern shift depending on where you were geographically.
    ·
    The Calibration is to help counter some of these anomalies and to gain a certain degree of precision.· The default values directly from the compass are fine for a general heading, but if you want increased resolution, each unit must be calibrated.
    ·

    ·



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • AndreiAndrei Posts: 15
    edited 2009-05-16 09:11
    Hi,
    Even after calibration I can't get a fixed value. What could be the problem?
    Thank you.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-05-16 16:49
    Andrei,

    How is your sensor positioned, is it horizontal to the ground?... are there any devices that would cause any interference? i.e. motors, relay's, etc...

    It is normal for the readings to fluctuate some, can you describe in more detail what you are observing?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • AndreiAndrei Posts: 15
    edited 2009-05-17 09:15
    It is horizontal to the ground but I will check this thing to. I have it on a Boe Bot, Board of Education. Could the PC cause it to fluctuate? or a cell phone? There are the robot motors but I have tried instaling the compass farther to the robot and I could get the same measurements. The readings fluctuate with 8 degrees. And with a capacitor the fluctuations are only 4 degrees. The fluctuation dosen't stop. In the picture is how I have istalled the compass
    Sorry for my english.
    I hope you can help me.
    2330 x 1663 - 1M
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2009-05-17 14:03
    Andrei,

    The HM55B is only accurate to 6-bit (64-direction) resolution after calibration anyway... this equates to 5.625 Deg

    The capacitor helps to stabilize the power to the HM55B by filtering out any power noise.

    I worked this out once:
    Even though you read in the data at 11 bits, the HM55B has a magnetic field range of +/-180 uT with a MAXimum 1.6 LSB/ uT
    So that's only 8 bits right there (360/ 1.6) minus 1 bit of error for the LSB due to nyquist and you only have 7 bits per channel.
    When you combine the two channels to produce a heading, you compound the amount of error into 2 bits of error and end up with 6 bits
    of accuracy.



    Reference:
    http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/Compass/List/0/SortField/4/ProductID/98/Default.aspx
    http://www.parallax.com/Portals/0/Downloads/docs/prod/compshop/HM55BDatasheet.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Evan DanielEvan Daniel Posts: 1
    edited 2009-05-21 04:31
    Is there a recommended place to buy the HM55B sensor IC? I can't seem to find it for sale anywhere. It looks like a good fit for my application, and would use less board area than the KMZ52 and associated signal conditioning (my current choice, but that will require a quad op amp and driver for the S/R coil -- yuck!). I suppose this isn't really the place to be asking, but thanks in advance for any help you can offer.
Sign In or Register to comment.