Shop OBEX P1 Docs P2 Docs Learn Events
Problems with HMC6343 spin object — Parallax Forums

Problems with HMC6343 spin object

4Alex4Alex Posts: 119
edited 2009-05-19 15:12 in Propeller 1
Hi all,

I am currently using the HMC6343 spin object from Tim Moore (Aug 08). This object (and the associated files) is great and provide an excellent digital compass. However, I am experiencing a few problems with the object as implemented. The I2C works well, the IC responds correctly to various reading of its EEPROM (default values matches readings, that is).

However, there seems to be a few problems:

1. The reading of the heading word, (at $50, first 2 bytes), does not correspond in any way to real compass values. Most of the time, rotating the IC result in values varying only of a few tens on degress instead of a full 360.

2. The roll and pitch words are swapped. This is no error from Tim but rather an inversion (I suspect) in the data sheet. A query to the OpMode1 register (bit1) confirms that the IC is configured as a Level setup. Clearly there's an error in the datasheet, then.

3. Does anyone knows what the units for the accelerometer register ($40), and for the magnetometer ($45)?

4. What is the meaning of temp word at register $55?

I am grateful to any one who could provide assistance on this, as Honeywell didnt responded to my emails. I am convinced it would be useful to others as well wishing to use this IC, especially since it cost more than $150 per unit...

Cheers,

Alex

ps: I didn't inserted any code snippet as I am using the objects as is.
pps: I have attached a copy of the datasheet as Howell's site is often down, apparently.

Comments

  • TimmooreTimmoore Posts: 1,031
    edited 2008-10-06 23:20
    I can't put it on a breadboard at the moment- its mostly wired in place but not fully. From memory
    1. I remember the heading results being in 1/10 degree so for example 0-3600 for 360degrees. and I remember seeing this for heading
    2. I missed that but it makes sense, the roll limits were incorrect the doc said +-90 but I saw +-180 - if the pitch and roll were switched this would make sense.
    3. No, but I compared it with another accelometer and I believe its around +-2G or +-3G. For the magnetometer - dont know
    4. No idea
  • 4Alex4Alex Posts: 119
    edited 2008-10-06 23:35
    @Tim,

    Thanks for your reply. BTW, great job on the spin & apps!

    I get the proper overall range (e.g., within 360.0 deg). Its the values that are not varying of more than about 10deg, however you rotate the IC;

    As for the accelerometer, I use 3v3, so according to the datasheet my limits should be +1G to -1G. I dont copy that, at all.

    I approached a magnet (not very close, so I dont offset the straps), and there's little if any significant variation of the magnetometric results. Strange...

    Cheers,

    Alex
  • 4Alex4Alex Posts: 119
    edited 2008-10-07 15:24
    Hi all,

    I am making some progress on the HMC6343 and wanted to share the results.

    The following code works and provide full circle position for both roll and pitch, which is useful to resolve the real spatial orientation of the unit:
    repeat
        uarts.str(0,string("Heading XYZ: Heading: "))
        i2c.i2cstart
        i2c.i2cwrite($32,8)
        i2c.i2cwrite($50,8)
        waitcnt(clkfreq/1000 + cnt) 
        i2c.i2cstart
        i2c.i2cwrite($33,8) 
        'heading
        X := (i2c.i2cRead(i2c#_i2cACK)*256) + i2c.i2cRead(i2c#_i2cACK)
        'Roll
        Y := (i2c.i2cRead(i2c#_i2cACK)*256) + i2c.i2cRead(i2c#_i2cACK) +1800
        'Pitch
        Z := (i2c.i2cRead(i2c#_i2cACK)*256) + i2c.i2cRead(i2c#_i2cNAK) +1800
        
        'i2c.stop     <======= SEE NOTE 
        
        ~~X
        ~~Y
        ~~Z
        'heading display
        uarts.dec(0,||X/10)         
        uarts.tx(0,".")
        uarts.dec(0,||X//10)
        uarts.tx(0," ")
        'roll display
        uarts.str(0,string(" Roll: "))
        uarts.dec(0,(||Y)/10)
        uarts.tx(0,".")
        uarts.dec(0,(||Y)//10)
        uarts.tx(0," ")
        'pitch display
        uarts.str(0,string(" Pitch: "))
        uarts.dec(0,||Z/10)
        uarts.tx(0,".")
        uarts.dec(0,||Z//10)
        uarts.tx(0,13)
        uarts.tx(0,10)
        uarts.tx(0,13)
        uarts.tx(0,10)
        waitcnt(clkfreq + cnt)
    
    


    I still have some issue with the heading (values don't vary fully through 0-359deg). Also, I noticed the following: If the i2c.stop is activated, the first round provide correct results, then the following rounds results in zero values. If I rem out the line, then all the rounds, all the time, provide correct results. Anyone can explain to me why this is happening?

    Finally, everywhere I could find some code or info about the HMC6343, the roll & pitch are swapped from what I experience. Just to make sure I am not all mistaken, can someone confirm that roll means a motion left-right-left, and pitch means a motion front-back-front? If so, this exactly what I experience with the code snippet listed above and contrary to what the datasheet say. The IC is positioned exactly as per page 7 of datasheet with a confirmed Level orientation from OpMode1 register, bit0 (set).

    Cheers,

    Alex
  • TimmooreTimmoore Posts: 1,031
    edited 2008-10-07 16:22
    What basic I2C class are you using? One of the problems I had with this device is it requires slave clock stretching support and none of the i2c drivers supported clock stretching. Before I added this the first read was always correct but not hte following reads, if I slowed the I2C clock down a lot it would work most of the time. Slave clock stretching was required to get consistent results.
  • 4Alex4Alex Posts: 119
    edited 2008-10-07 17:54
    @Tim,

    I use the I2C SPIN Object from James Burrows (May 2006, Version 1.3).

    What is Slave clock stretching and how is it implemented?

    Cheers,

    Alex
  • TimmooreTimmoore Posts: 1,031
    edited 2008-10-07 18:58
    If I remember correctly I put a copy of my Basic_I2C_Driver in the hmc package that supports clock stretching. The problem that clock stretching is meant to solve is if the slave can't output on time, it is allowed to hold the clock pin low and hte master is meant to wait for it to go high before reading. All the I2C drivers I looked at didn't implement this. I had problems with other devices that use micros for the slaves e.g. the ultrasonic sensors from devantech on other systems, so I tried impleemtning clock stretching and found it worked.
  • 4Alex4Alex Posts: 119
    edited 2008-10-07 19:43
    @Tim,

    Yes, a modified version of Basic_I2C_Driver is included in the ZIP file. However, the heading (0-359.9deg) is not functional. All the other heading values (roll & pitch) are ok and also work with the I2C SPIN Object from James Burrows. Since I use this object elsewhere, I simply implemented it with the HMC. First thing I did was using your entire project from the ZIP and tested the HMC module. No correct headings. Only then, did I started modifying the objects. Everything seems to work but the headings.

    Cheers,

    Alex
  • TimmooreTimmoore Posts: 1,031
    edited 2008-10-07 19:48
    What prop board are you using? Check that it has a pull-up resistor on SCL. Many of the boards e.g. PPDB, demo board dont have pullup on SCL. If not add one, clock stretching will not work without it.
  • 4Alex4Alex Posts: 119
    edited 2008-10-07 20:07
    @Tim,

    I have a pull-up on both SDA and SCL (10k) at P28/P29 of the PPL.

    Cheers,

    Alex
  • 4Alex4Alex Posts: 119
    edited 2008-10-09 13:57
    Hi all,

    I finally received answers from Honeywell. This brings some clarification to the HMC6343.
    Somebody said...

    Q: Meaningless values returned from heading register, what's wrong?
    A: Sounds like you have magnetic interference to prevent earth's field detection. Check for magnetized sources nearby.

    Q: At 3v3 the Accelerometer should give a range of +1G to -1G, what the returned values for X,Y,Z means?
    A: The device is compass first, and less a collection of discrete sensors. the accels are about 8600 ADC counts per g.

    Q: The Magnetometer should give a range of +1Gauss to -1Gauss, what the returned values for X,Y,Z means?
    A: Raw mag data is about 13000 ADC counts per gauss.

    Q: What is the meaning of temp word at register $55?
    A: Ignore the temp register, not used.

    I am not completed yet but I'll post a final working code when I get there.

    Cheers,

    Alex
  • orangebitzorangebitz Posts: 2
    edited 2008-12-11 19:49
    Hello,

    The datasheet mentions sending 0x32 followed by 0x50, waiting a few milliseconds and then only needing 0x33 to get data out subsequently. I noticed that I need to send 0x32, 0x50 everytime to get a new reading. I confirmed that it is in continuous run mode. Did you guys have to do this as well? Is the datasheet wrong?
  • 4Alex4Alex Posts: 119
    edited 2008-12-23 22:48
    @orangebitz:

    Sorry if I reply so late but I just noticed your question. I am still working (kind of 'on and off') on the HMC6343. I can talk/setup the IC using Basic I2C Routines Version 1.1 (Written by Michael Green, Modified by James Burrows, and further modified by Tim Moore Jul/Aug 08). I have not see the need to use clock stretching.

    I a nutshell, YES, the datasheet contains several errors. I also have to issue a reading command each time I need data. What follows is applicable to an IC installed in LEVEL position (ds page 7), X-axis pointing forward, top of IC pointing toward ceiling.

    1. After issuing $50 you have to read 3 successive words:
    - First word is HEADING: I still get meaningless (but within 0-3600) heading data from HeadMSB+HeadLSB. Data is at 0.1 resolution;
    - Next word is PITCH: When you tilt the front of the IC upward you get a positive value ranging from 0 to +1800
    (reached when IC is upside down). When you tilt the front of the IC downward you get a negative value ranging from 0 to -1800.
    Data is at 0.1 resolution with 2's-complement;
    - Last word is ROLL: When you tilt the IC toward the left you get a negative value ranging from 0 to -1800 (reached when IC is on its side).
    When you tilt the IC toward the right you get a positive value ranging from 0 to +1800, data is at 0.1 resolution with 2's-complement;

    2. After issuing $40 you have to read 3 successive words for accelerometer values: word1 is acceleration on X axis, word2 is Y axis and word3 is Z axis. Values are defined as 8600 counts per G. Data is returned using 2's-complement. I have not measured anything larger than +/-2G so far. I express data at 0.001 resolution for practicality. When IC is flat, X=0, Y=0, Z=+1. When the IC is tilted upward, X is negative (downward gives a positive value). When the IC is rolled toward the left, Y is positive (toward the right it gives a positive value). The value of Z changes with the tilting (upside down give -1G).

    3. After issuing $45 you have to read 3 successive words for magnetometer values: word1 is magnetic field strength on X axis, word2 is Y axis and word3 is Z axis. Values are defined as 13000 counts per Gauss. Data is returned using 2's-complement. Earth's field is about 0.6Gauss. I have not measured anything even close to that value so far. I do get data variations when I rotate the IC flat but I don't get anything significantly larger when I approach a magnet. I express data at 0.001 resolution for practicality. I have no idea what a negative Gauss value could represent.

    4. I found the Tilt data collected after issuing $55 to be useless.

    5. I successfully recalibrated the IC (issuing $71) but gained very little out of it.

    At this point, I still cannot get any heading value that is meaningful. So far, the HMC6343 as revealed to be little more than a pricey 3-axis accelerometer to me. Did you ever get a full 0-3600 data display from a full rotation? If so (or anybody else for that matter) I'd be grateful to know how that was achieved. I tried 2 ICs. At about a $150USD each, I don't plan to test any additional IC for now!

    Hope this help.

    Cheers and Season's greetings to all,

    Alex
  • orangebitzorangebitz Posts: 2
    edited 2008-12-29 16:38
    Hello Alex,
    I found no issues with my HMC6343 accept that I needed to send the 'read' command everytime. I did have to move a another location when I got weird values for pitch and roll...my heading values is fine. I used an i2c tool from http://i2cchip.com/index and simply used hyperterminal with the commands: PS3250 (stop,start,address+write_bit,command) and then waited a small delay before sending PS3306 (stop,start,address+read_bit,#bits).
    If you are getting weird values, it might be due to magnetic interference...
    Hope this helps?
  • mddfmddf Posts: 1
    edited 2009-04-25 00:51
    Hi,
    I am using the HMC6343 and need to get about 100 degrees of tilt angle.· Does anybody know of a way to fix the error that occurs when the pitch goes above about +60 or below -60.· I tried positioning my sensor so that the initial position for pitch was -60, thus as pitch changes it increased from -60 to +60 keeping it in the range that has no error in the heading or roll raw data.· This worked, yet now when I preform pure roll rotations, pitch and heading raw data have error and change.· Does anyone know of a solution so that I can get 100 degrees of pitch without error in the other rotation data?

    Post Edited (mddf) : 4/25/2009 1:04:58 AM GMT
  • jlucianijluciani Posts: 1
    edited 2009-05-19 15:12
    @4Alex

    I know this an old thread but I hoping you found a solution to your HMC6343 problem (since
    I am having the **exact** same problem [noparse];)[/noparse]

    I am using ATmega644P with the HMC6343. The heading data always read around 1800.
    The pitch and roll seem to be OK. I didn't check the sign of the rotation but I get apx -900
    in one direction and +900 in the opposite direction.

    I looked at the state of the I2C bus and the data being sent and I do not see anything
    unusual. I am hoping you found the magic "send correct heading" incantation.

    (* jcl *)

    www.wiblocks.com
    www.luciani.org
Sign In or Register to comment.