Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Twos compliment in Oshonsoft and Compass calibration

Status
Not open for further replies.
I just used the calculator supplied with Windows..
Set it in Programmer mode (in View), then "word" as the data size option.

Entering the value while hex is selected, then switch to decimal.

For a generic calculator, enter the hex (in hex mode), convert to decimal then if the number is larger than 32767, subtract 65536.
That should give the same results.
Hi R.
Ok, the above method works as you say, thanks.

Is it possible to not use the HEX route. The DATA shows two BYTEs of DEC and I want to see the end result in DEC?

EDIT: I think I've worked it out:) (HIGH BYTE X 256 + LOW BYTE) [If > 32767 then] -65536 =X

I'll play with this and the results I'm getting so I can get the feel of what happens, when the module is moved around, before using the calculations, within this thread.

C.
 
Last edited:
Hi R.
Ok, the above method works as you say, thanks.

Is it possible to not use the HEX route. The DATA shows two BYTEs of DEC and I want to see the end result in DEC?

EDIT: I think I've worked it out:) (HIGH BYTE X 256 + LOW BYTE) [If > 32767 then] -65536 =X

I'll play with this and the results I'm getting so I can get the feel of what happens, when the module is moved around, before using the calculations, within this thread.

C.

Look msg #12 in this thread 8 months ago.
X = 65536 - X
If X is 16bit integer, X = 65535 - X + 1
 
Look msg #12 in this thread 8 months ago.
X = 65536 - X
If X is 16bit integer, X = 65535 - X + 1
Hi J,
I have the 8 month old calculation, safely in the program, but 8 months, is a long time, for me to need a refresher course. Using the calculator, with the recent sums, will get me used to twos compliment again, before adding in the calculation to the program, where I'll be able to see what's gong on better.
Cheers, C.
 
That's just normal big endien.

Mike.
Hi M,
I've just got to this in the DATA sheet:
Measuremnet data is stored in two’s complement and Little Endian format. Measurement range of each axis is -8190 ~ +8190 in decimal in 14-bit output, and -32760 ~ 32760 in 16-bit output.
How can I tell one 'endian' from the other?
(Set to 16BIT)
C.
 
If the low byte is first in memory then it's little endian. Most pic 16 bit variables are stored in little endian format.
 
Hi M,
I've just got to this in the DATA sheet:
Measuremnet data is stored in two’s complement and Little Endian format. Measurement range of each axis is -8190 ~ +8190 in decimal in 14-bit output, and -32760 ~ 32760 in 16-bit output.
How can I tell one 'endian' from the other?
(Set to 16BIT)
C.
From the datasheet:
Address Magnetic field Data ( byte)
03 Xlow
04 Xhigh
05 Ylow
06 Yhigh
07 Zlow
08 Zhigh
 
Hi,
I presume then that:
03 Xhigh
04 Xlow
05 Yhigh
06 Ylow
07 Zhigh
08 Zlow
is big endian? Perhaps obvious, but just checking.

C
 
If it needs negative numbers, you must input negative numbers :)
You must convert from the low and high bytes ( twos complement )
to x, y, z values, which will be some +- values.
 
If it needs negative numbers, you must input negative numbers :)
You must convert from the low and high bytes ( twos complement )
to x, y, z values, which will be some +- values.
Hi J,
The Magmaster needs 6x values.
C.
 

Attachments

  • Magmaster DATA.jpg
    Magmaster DATA.jpg
    84.5 KB · Views: 210
Hi,
J and P,
Yes, a bit confusing!
It needs the 6x measurement register READings, in this format. ( I added the - to the HSEROUT, so not real, but it worked)
255, 255, 255
78, 230, 138

255, 255, 255
89, 225, 137

255, 255, 255
84, 230, 146

255, 255, 255
84, 228, 150

255, 255, 255
87, 231, 149

255, 255, 255
81, 231, 143

They are as the image in #52.
Once these are running, they show in the top bar.
Move the compass module around in these 12 orientations, (see image), while pressing the nearby button to enter each READing into Magmaster.

The Magviewer only needs the DATA as #52.
C
 

Attachments

  • ORIENTATION.png
    ORIENTATION.png
    347.5 KB · Views: 211
Last edited:
It appears to need 6 floating point numbers.

Mike.
Hi M,
Re-looking at #52, I think Magmaster may need the results under the lines-----------------------.
I tried 3x values and Magviewer looked the same as 6x, so it looks as though 3x twos compliment values are needed.
C
 
Hi M,
Re-looking at #52, I think Magmaster may need the results under the lines-----------------------.
I tried 3x values and Magviewer looked the same as 6x, so it looks as though 3x twos compliment values are needed.
C
Are you now sending the data through serial interface to Magmaster or inputting it manually?
I think you should send repeatedly N coordinates x1, y1, z1 - xn, yn, zn
Coordinates should be in floating point.
You can then see live 3D data as in video #2 from Magmaster link in #msg 50 and after calibration video #4
 
Hi M and J,
Stuck again :banghead:

Here is the Magmaster DATA again:
Will someone tell me where twos compliment and floating point starts and ends in ABCDEF please?
(I have the calculation for twos compliment)


If I enter A and B I get this (Magviewer)

There are no negatives. so all of the DOTs are in the same quadrant!#

I use the Magviewer LIVE as I send the DATA via serial and radio modules. Once I get DOTs in all 4 quadrants, I'll follow the 12 orientations in the instructions while entering DATA into Magmaster.

EDIT: In yellow
C
 

Attachments

  • Magmaster DATA.jpg
    Magmaster DATA.jpg
    58.6 KB · Views: 278
  • 360.jpg
    360.jpg
    39 KB · Views: 215
Last edited:
Hi M and J,
Stuck again :banghead:

Here is the Magmaster DATA again:
Will someone tell me where twos compliment and floating point starts and ends in ABCDEF please?
(I have the calculation for twos compliment)


If I enter A and B I get this (Magviewer)

There are no negatives. so all of the DOTs are in the same quadrant!#

I use the Magviewer LIVE as I send the DATA via serial and radio modules. Once I get sensible results, I'll follow the 12 orientations in the instructions while entering DATA.
C
The coordinates before the calibration is done can be floating point or 16bit signed integers
When the calbration is done you get the correction coefficients M11 - M33, which are in floating point, see pictures 1 and 9.
Because Oshonsoft does not handle signed integers, it is easier to convert the twos complement coordinates to floating point from the beginning and then send them to Magmaster, something like
Hserout #Xf, #Yf, #Zf.... etc

Converting to floating point can be done in the same way as in the pressure sensor program:
- make 16bit integer from Xlowbyte, Xhighbyte-> Xraw
Xfloat = Xraw
if Xfoat > 32767 then // is it negative
Xfloat = xfloat-65536

edit: corrected the xfoat negative calculation
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top