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
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
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/Henrik.Code:Sign VAR BIT Reading VAR WORD x VAR BYTE Sign = Reading.15 x = ABS(Reading) >> 4 If Sign THEN x = -x
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
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]If x is declared as a WORD then it fails:Code:Reading: -2048 X: -128 Reading: 2047 X: 127 Reading: -100 X: -7 Reading: 100 X: 6/Henrik.Code:Reading: -2048 X: 3968 Reading: 2047 X: 127 Reading: -100 X: 4089 Reading: 100 X: 6
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.
maybe this will help
http://www.starlino.com/imu_guide.html
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 ?
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
Bookmarks