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.
Hi J,
Here is the BIAS program:
Also the result:
but something's wrong.
C
 

Attachments

  • 18LF4520 8Mhz HC-12 AK8963 221118 1130 SET BIAS Magmaster.bas
    11.2 KB · Views: 339
  • BIAS CALC.txt
    1.5 KB · Views: 312
This is wrong, look at msg #99
x_c = (m11 * x_0) + (m12 * x_0) + (m13 * x_0)
y_c = (m21 * y_0) + (m22 * y_0) + (m23 * y_0)
z_c = (m31 * z_0) + (m32 * z_0) + (m33 * z_0)

There are others, but correct this first.
 
There are no values for m11 - m13, b_x, b_y, b_z

Take out Xnc= Xnc +1, Ync= Ync +1, Znc +1
It is wrong, when you have Xnc = Xnc - 65536
 
Last edited:
This is wrong, look at msg #99
x_c = (m11 * x_0) + (m12 * x_0) + (m13 * x_0)
y_c = (m21 * y_0) + (m22 * y_0) + (m23 * y_0)
z_c = (m31 * z_0) + (m32 * z_0) + (m33 * z_0)

There are others, but correct this first.
Hi J,
Do you mean:
My use of underscores X_C instead of XC?
My use of brackets? (I tried without first then with)
In your message #99 you used X0, (number) and yo (letter) I chose number although I tried letter first.

Or was the error something else?
C.
 
Underscores don't matter. You can use any variable names you want.
Look again #99. Calibrated values should be calculated like this

Xc = m11 * X0 + m12 * Y0 + m13 * Z0
Yc = m21 * X0 + m22 * Y0 + m23 * Z0
Zc = m31 * X0 + m32 * Y0 + m33 * Z0

Then you have not given any values for m11- m33 and bias values Bx By Bz
Try first to send the calibrated values to terminal and look if they are reasonable.
 
Underscores don't matter. You can use any variable names you want.
Look again #99. Calibrated values should be calculated like this

Xc = m11 * X0 + m12 * Y0 + m13 * Z0
Yc = m21 * X0 + m22 * Y0 + m23 * Z0
Zc = m31 * X0 + m32 * Y0 + m33 * Z0

Then you have not given any values for m11- m33 and bias values Bx By Bz
Try first to send the calibrated values to terminal and look if they are reasonable.
Hi J,
I see! Hidden in plain sight.

Success!.
I also found a typo (y instead of an x)

Here is the latest program for Magmaster:
plus a Terminal READout:
plus 3x Magviewer views:

Thanks again, C.
 

Attachments

  • Magmaster calc.txt
    1.2 KB · Views: 326
  • x.jpg
    x.jpg
    96.3 KB · Views: 345
  • y.jpg
    y.jpg
    101.2 KB · Views: 336
  • z.jpg
    z.jpg
    102.8 KB · Views: 331
  • 18LF4520 8Mhz HC-12 AK8963 231118 0930 SET BIAS Magmaster.bas
    11.5 KB · Views: 333
Fine!
Could you test it now:
Start with y pointing to north and rotate 360 degrees clockwise, for example in 45 degrees steps.
Display x, y for each step.
 
Fine!
Could you test it now:
Start with y pointing to north and rotate 360 degrees clockwise, for example in 45 degrees steps.
Display x, y for each step.
Hi J,
Here's a test, showing X,Y,Z READings in 45DEG steps on a terminal.
C.
 

Attachments

  • 0-359.txt
    8.9 KB · Views: 344
Last edited:
Hi,
Does this look correct for the first OCTANT?

'0 - 45 degrees x / y < 1 And x > 0, y > 0
'angle = Arctan( x / y ) × 57.3

If x_c / y_c < 1 Then
If x_c > 0 Then
If y_c > 0 Then
deg = Arctan(y_c / x_c) * 57.3
Endif
Endif
Endif

This gives double digit incorrect figures, with a max of 41.38 when Y is approx 0-90 DEG.
C.
 
Hi,
Does this look correct for the first OCTANT?

'0 - 45 degrees x / y < 1 And x > 0, y > 0
'angle = Arctan( x / y ) × 57.3

If x_c / y_c < 1 Then
If x_c > 0 Then
If y_c > 0 Then
deg = Arctan(y_c / x_c) * 57.3
Endif
Endif
Endif

This gives double digit incorrect figures, with a max of 41.38 when Y is approx 0-90 DEG.
C.

You state in comments:
'angle = Arctan( x / y ) × 57.3
but your code has the x and y reversed:
deg = Arctan(y_c / x_c) * 57.3

Pick the right one?
 
You state in comments:
'angle = Arctan( x / y ) × 57.3
but your code has the x and y reversed:
deg = Arctan(y_c / x_c) * 57.3

Pick the right one?
Hi S,
I switched x_c and y_c, now at 0Deg 11 shows, 22.5Deg shows 31 and 35DEg shows 40. 35-45 shows 41DEG.

NOTE: When I was 7, I was kept in after school, because I couldn't see the 'carry' when adding tens and units. 38+38 = 66. Even though I've since passed 'O' level maths and physics, it never went way :(

Thanks,
C
 
Can't help much more than looking at the basic math. Also, if Y happens to be exactly zero (0), your logic/formula will fail. One has to test for zero divisor first, before any other math where one divides by a variable.
Of course if Y=0, then your answer will be more limited as to solutions.
 
Hi J,
Here's a test, showing X,Y,Z READings in 45DEG steps on a terminal.
C.
If you want to have the angle clockwise from north, the x values should be negated.
Then with the values from msg #108, 0 is about - 9 or 351 degrees.
45 ~ 35 degrees and 90 ~ 86 degrees.
There is quite a lot deviation between values with the same angle of the sensor.
 
Does any of this take into account magnetic north vs geographic north? That is, if pointing to geographic north, -9Deg (351 Deg) may make sense if that points to the magnetic pole. These external devices can only sense magnetic north.
 
Does any of this take into account magnetic north vs geographic north? That is, if pointing to geographic north, -9Deg (351 Deg) may make sense if that points to the magnetic pole. These external devices can only sense magnetic north.
Hi S,
Regarding Y=0: So far I'm looking at the first OCTANT of the circle, so it's possible that in other OCTANTS there may be 'If y = 0 then'
I'm using Oshonsoft BASIC, and there is a SYNTAX '>=' What I'm following here, I think is written in C+?, and I'm not sure if '> 0' may also mean '>='. Perhaps you know?

At the moment, I'm not concerned with magnetic/true, I'll look farther into this later. I think the deviation here is <1 Deg.
C.
 
Last edited:
If you want to have the angle clockwise from north, the x values should be negated.
Then with the values from msg #108, 0 is about - 9 or 351 degrees.
45 ~ 35 degrees and 90 ~ 86 degrees.
There is quite a lot deviation between values with the same angle of the sensor.
Hi J,
How do I negate X values? Can this be done at the two's compliment stage?

I noticed the deviation in values, also when using MAGMASTER. I can perhaps average them out in some way.
I slowed down the number of READings/sec, also lowered the sensitivity from 16BIT to 14BIT, has this helped?
C.
 

Attachments

  • Variation.txt
    1 KB · Views: 306
Last edited:
Hi J,
How do I negate X values? Can this be done at the two's compliment stage?

I noticed the deviation in values, also when using MAGMASTER. I can perhaps average them out in some way.
I slowed down the number of READings/sec, also lowered the sensitivity from 16BIT to 14BIT, has this helped?
C.
Negate: Xc = - Xc
If changed to 14bit, maybe the 2's complement has to be changed too?
The variation is smaller now.
Can you rotate the full circle.
 
Negate: Xc = - Xc
If changed to 14bit, maybe the 2's complement has to be changed too?
The variation is smaller now.
Can you rotate the full circle.
Hi J,
x_c = - x_c Doesn't compile in OSH BASIC, I'll come back to it later.

I think 14BIT only changes '1' BIT of a BYTE, so I'm guessing that 2's compliment isn't affected. Here's a bit of D/S:
Do you agree?

I tried rotating 360DEg, but something's not right, I'll re-try once the above has been checked.

C.
 

Attachments

  • 14-16BIT.jpg
    14-16BIT.jpg
    115.1 KB · Views: 330
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top