HMC5883L Magnetometer chip Possibilities.


Closed Thread
Results 1 to 40 of 58

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,692


    Did you find this post helpful? Yes | No

    Default Re: HMC5883L Magnetometer chip Possibilities.

    am I wrong or would right shifting the reading 4 give the same answer without all the math
    x var byte
    reading var word
    x= reading>>4

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: HMC5883L Magnetometer chip Possibilities.

    Hi,

    Shooting from the hip a bit here....

    Since the ATN expects 8bit two's complement values I'm not sure it's going to work when you give it your x and y variables since they are both 16bit variables - even if the values in them are in +/-127 range. Ah, never mind, it probably will since the low byte of the word will look identical anyway....

    Richard,
    You can't simply shift a two's complement number like that, you'll drop the sign.
    You need to remember the sign, shift the abs value and restore the sign
    Code:
    Sign VAR BIT
    Reading VAR WORD
    x VAR BYTE
    
    Sign = Reading.15
    x = ABS(Reading) >> 4
    If Sign THEN x = -x
    /Henrik.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,692


    Did you find this post helpful? Yes | No

    Default Re: HMC5883L Magnetometer chip Possibilities.

    it works on paper , i'm curious to compile it and see what happens , i'm feeling a cast from word to byte and only a 4 bit r-shift might allow the loss of the sign bit to be ignorable . if it works it saves a lot of steps
    I would christen it as quick and dirty code

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: HMC5883L Magnetometer chip Possibilities.

    Hi,
    You're quite right Richard!
    It works provided that x in this case IS declared as a byte (which it was in your code of course)
    Code:
    x = Reading >> 4
    HSEROUT["Reading: ", SDEC Reading, "   X: ", SDEC x,10,13]
    Code:
    Reading: -2048   X: -128
    Reading: 2047   X: 127
    Reading: -100   X: -7
    Reading: 100   X: 6
    If x is declared as a WORD then it fails:
    Code:
    Reading: -2048   X: 3968
    Reading: 2047   X: 127
    Reading: -100   X: 4089
    Reading: 100   X: 6
    /Henrik.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,692


    Did you find this post helpful? Yes | No

    Default Re: HMC5883L Magnetometer chip Possibilities.

    thanks for confirming that henrik ,saves me the trouble .
    I worked that out with the windows7 calculator (in programmer mode) it makes it easy to visualise some solutions , another feature sadly lacking in windoze 8.1
    correction
    not lacking in wdoze8 just hard to find like most of anything that's useful
    Last edited by richard; - 30th December 2014 at 12:38.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,692


    Did you find this post helpful? Yes | No

    Default Re: HMC5883L Magnetometer chip Possibilities.

    maybe this will help

    http://www.starlino.com/imu_guide.html
    Attached Images Attached Images  

  7. #7
    Join Date
    Dec 2012
    Location
    Türkiye
    Posts
    103


    Did you find this post helpful? Yes | No

    Default Re: HMC5883L Magnetometer chip Possibilities.

    I still can't understand which vector shows me the magnetic north in this picture ... But as far as I read the datasheet of this IC , it mentions about a term called Hnorth which is the resultant force of X and Y vectors ... so which one is it then ? Is it XY calculation that shows me the north ?

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,692


    Did you find this post helpful? Yes | No

    Default Re: HMC5883L Magnetometer chip Possibilities.

    if the device is held so that the xy plane is perfectly!!!! level then the xy angle is magnetic north (sort of). if the device is tilted then the xy angle needs to compensated for that tilt . the device alone cannot really be used as a compass . the device output is a 3d vector as drawn by the black line in my previous post, as you can see the result is relative to the devices orientation , if that is unknown (and it is without an external reference ) then its virtually impossible to ascertain a direction from its output. even a small tilt creates substantial error.
    furthermore magnetic field lines are not parallel with the earths surface they tilt into the earth or up to the sky depending on location. not to mention magnetic inclination/deviation etc
    basically the concept of using this chip as a compass is unworkable see post 47
    Last edited by richard; - 3rd February 2015 at 11:57. Reason: typo

Similar Threads

  1. 3 axis digital compass sensor HMC5883L
    By ScaleRobotics in forum General
    Replies: 1
    Last Post: - 8th June 2014, 23:19
  2. How to use this IO chip?
    By wdmagic in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th April 2013, 20:06
  3. compass chip
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th October 2009, 02:42
  4. Do you use ICD possibilities of MicroCode Studio
    By octal in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th December 2007, 18:22
  5. Which chip do i use?
    By The Master in forum Off Topic
    Replies: 77
    Last Post: - 2nd December 2007, 23:28

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts