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.

Averaging READings BYTEs etc

Status
Not open for further replies.
Hi P, J and V,
In #13 J said " In #11, The Y values seems to be faulty, if the compass was in the same position between the readings. " As I wasn't sure, so I re-tried, making sure it stayed in the same posisiton.

V, The compass AK8963C puts out 3x2 BYTEs which combine into WORDs, to give the 3-Axis X,Y,Z, needed for 3D operation.

I've just been playing with the Compass and it's READouts. I think the 3xAxis are as shown here:
whe one of the axis is vertical, then it's value doesn't change much, a bit like aiming an iron compass vertically=useless. When an axis is aiming North, then this is when it outputs, stronger value changes, and at right angles to North, then poor values.
Leter in the program, there is a section, that I need reminding about, explaining Octants. These calculations, use the strongest orientation READouts, of each axis.
C
 

Attachments

  • AK8963C DIRECTIONS.jpg
    AK8963C DIRECTIONS.jpg
    23.8 KB · Views: 249
One question to consider - what values does the compass put out? +/-180 makes sense, so a change from +179 to -179 is actually a small change in measured value.
Hi P,
I've been back in time a couple of years, where much of this was explained to me before by some of you.

I've just found a gap in my understanding! The LB changes from 0-255 the HB only changes from 0 or 255 (Apart from the eronious 254), but it must be that the HB actually count 0-255 as well, to output 65535, is this correct? Or why can't I see the 2x BYTEs counting 0-65535

EDIT: Or, in the 2's compliment system, when counting up and reaching 255 in LB, does the LB switch to being HB and the new LB start counting?
C.
 
From the manual the high byte maximum for positive values is 127 and for negative 255.
So the high byte for positive values could be 0-127
Do you ever get low byte value near 255.
Then the value could come to some low byte and high byte 1
Your program reads 20 registers, when only six + maybe status and data ready are needed.
There is also a warning on a couple of the registers: DO NOT ACCESS.
 
From the manual the high byte maximum for positive values is 127 and for negative 255.
So the high byte for positive values could be 0-127
Do you ever get low byte value near 255.
Then the value could come to some low byte and high byte 1
Your program reads 20 registers, when only six + maybe status and data ready are needed.
There is also a warning on a couple of the registers: DO NOT ACCESS.
Hi J,
I recall you mentioning the DO NOT ACCES registers, and I may have changed it now, I'll check later.

Regarding the HB LB question. Knowing that in the 2's compliment section in the program, it mentiones >32767 which implies more than 13 BYTEs, and this is my puzzle, I only see LB = 0-255 and HB = 0 or 255, and nothing in between.
C.
 
16 bit signed numbers are just that. The fact that they appear to only vary between +/-512 is just that, the earths magnetic field isn't very strong. The values can go between +32767 and -32766, that's just how signed integers work. Read more about signed integers. Actually, it may help you to use a language that has signed integers.

Mike.
 
Hi J,
I recall you mentioning the DO NOT ACCES registers, and I may have changed it now, I'll check later.

Regarding the HB LB question. Knowing that in the 2's compliment section in the program, it mentiones >32767 which implies more than 13 BYTEs, and this is my puzzle, I only see LB = 0-255 and HB = 0 or 255, and nothing in between.
C.
The max values I mentioned correspond to field strength of 4912 uT
Your location has a field strength of 48.9 uT
So the total field strength is about 1/100 of the maximum values.

Your program 29.08 calculates and prints the values in floating point.
Why don't you use it to average and put the values
into Magmaster.
 
Hi P and J,
Can you let me know, that you understand, what I am saying regarding the HB. It isn't showing any subtlety, and only show either 0 OR 256, I don't see any thing in between, for example what should I see for 'say' a READing of 4095?
C.
 
Hi P and J,
Can you let me know, that you understand, what I am saying regarding the HB. It isn't showing any subtlety, and only show either 0 OR 256, I don't see any thing in between, for example what should I see for 'say' a READing of 4095?
C.
I understand what you mean.
Your compass is capable of measuring magnetic field strength max 4912 uT, which is about 100 times the field strength on your location.
The measured values are simply smaller than 256 and the high byte is 0.
The first row in #11 in decimal numbers is x,y,z = -114, -60, -278.
Try with some strong magnet and you should get bigger high bytes in positive values and smaller in negative values.
 
Last edited:
I understand what you mean.
Your compass is capable of measuring magnetic field strength max 4912 uT, which is about 100 times the field strength on your location.
The measured values are simply smaller than 256 and the high byte is 0.
The first row in #11 in decimal numbers is x,y,z = -114, -60, -278.
Try with some strong magnet and you should get bigger high bytes in positive values and smaller in negative values.
Hi J,
Again thanks for your patience. It may be frustrating to some, and I hope someone in education looks at this.

A light just came on! I've been looking at the equations in the wrong way. When I seen x/y it is ignored, but if I had put x_raw/y_raw , which are the actual variables, then I would have been drawn in, instead. Now it makes more sense. I'm sure I see this sometimes, and sometimes I don't. This division could then could give positive or negative numbers, and the extra BIT of the overflow HB allows for larger than 256 numbers, Is this correct?
C.
 
Last edited:
Do you mean by X/Y used in calculations of the angle?

It may be confusing to look separately the HB and LB.
They make a 16 bit 2's complement word, where the bit 15 (or bit 7 in HB) is the sign bit.
It is easy when converted to a signed number.
 
Do you mean by X/Y used in calculations of the angle?

It may be confusing to look separately the HB and LB.
They make a 16 bit 2's complement word, where the bit 15 (or bit 7 in HB) is the sign bit.
It is easy when converted to a signed number.
Hi J,
I get the same thought result for XY of Angles as in this case the XY of the XYZ sequence. In Angle XY we have changed to A and O, which makes things work, and in this case X_RAW and Y_RAW make sense, as they mean something.

Yes, I was looking at individual BYTEs, which don't make sense, until 2's compliment rules are applied. Now I see that they must not be separated, for any sense. Here is a sequence, showing that how I was thinking doesn't work. Look at the first pair.

(I also checked Registers 13 and 14 (DO NOT ACCESS), and the program skips them.

EDIT: I kind of understand 2's compliment, but we could repeat hours of trying, like two years ago, and me never quite being familiar with it. It's probably better to carry on with something more constructive.


C.
32737.00,32602.00,32662.00
185, 255, 179, 254, 43, 255
32732.00,32601.00,32661.00
180, 255, 182, 254, 44, 255
32730.00,32603.00,32662.00
185, 255, 177, 254, 45, 255
32732.00,32600.00,32662.00
185, 255, 181, 254, 41, 255
32732.00,32602.00,32660.00
196, 255, 184, 254, 40, 255
32738.00,32604.00,32660.00
205, 255, 187, 254, 43, 255
32742.00,32605.00,32661.00
216, 255, 184, 254, 54, 255
32748.00,32604.00,32667.00
229, 255, 197, 254, 41, 255
32754.00,32610.00,32660.00
233, 255, 193, 254, 43, 255
32756.00,32608.00,32661.00
245, 255, 189, 254, 47, 255
32762.00,32606.00,32663.00
250, 255, 196, 254, 44, 255
32765.00,32610.00,32662.00
249, 255, 203, 254, 41, 255
32764.00,32613.00,32660.00
250, 255, 200, 254, 36, 255
32765.00,32612.00,32658.00
5, 0, 203, 254, 43, 255
2.00,32613.00,32661.00
5, 0, 201, 254, 43, 255
2.00,32612.00,32661.00
10, 0, 208, 254, 44, 255
5.00,32616.00,32662.00
10, 0, 212, 254, 46, 255
5.00,32618.00,32663.00
8, 0, 210, 254, 50, 255
4.00,32617.00,32665.00
21, 0, 213, 254, 47, 255
10.00,32618.00,32663.00
21, 0, 211, 254, 43, 255
10.00,32617.00,32661.00
16, 0, 212, 254, 42, 255
8.00,32618.00,32661.00
18, 0, 230, 254, 44, 255
9.00,32627.00,32662.00
27, 0, 227, 254, 47, 255
13.00,32625.00,32663.00
22, 0, 234, 254, 46, 255
11.00,32629.00,32663.00
33, 0, 241, 254, 47, 255
16.00,32632.00,32663.00
36, 0, 238, 254, 48, 255
18.00,32631.00,32664.00
 
Last edited:
The max values I mentioned correspond to field strength of 4912 uT
Your location has a field strength of 48.9 uT
So the total field strength is about 1/100 of the maximum values.

Your program 29.08 calculates and prints the values in floating point.
Why don't you use it to average and put the values
into Magmaster.
Hi J,
Here is the program 29.08.20

Here's a READout
16.00,-152.00,-216.00
24.00,-146.00,-204.00
18.00,-146.00,-208.00
5.00,-131.00,-217.00
3.00,-119.00,-207.00
3.00,-123.00,-219.00
-1.00,-117.00,-211.00
-8.00,-112.00,-218.00
-13.00,-113.00,-217.00
-13.00,-123.00,-219.00

What next, please?
C
 

Attachments

  • 18F4520 INT8MHz HC12, AK8963C PCB3 MAGMASTER 290820.txt
    4.2 KB · Views: 263
  • Dorchester.jpg
    Dorchester.jpg
    173.8 KB · Views: 247
Dim Xavg as single
Dim Yavg ...
Dim Xavg ...
......

Xavg=0
Yavg=0
Xavg=0

For j=1 to 10 ' for example average of 10 readings
for I = 0 to 18
....

Next I

Xnc=
Ync=
Znc=

Xavg=Xavg+Xnc
Yavg=....
Xavg=....
Next j

Xavg=Xavg/10
Yavg = ...
Xavg= ....
 
When averaging, you should take 8 or 16 sample (or any multiple of 2. That way, a processing-intensive divide does not have to be done. Simply bit-shift right by three bits (if you added 8 readings) or Right-shift 4 bits if you added 16 samples. But you'll have to take care of the data format first (negatives and positives).
 
When averaging, you should take 8 or 16 sample (or any multiple of 2. That way, a processing-intensive divide does not have to be done. Simply bit-shift right by three bits (if you added 8 readings) or Right-shift 4 bits if you added 16 samples. But you'll have to take care of the data format first (negatives and positives).
Hi G,
If you can explain like #36, I'll give it a go, but for now, I'll try J's. Thanks
C.
 
When averaging, you should take 8 or 16 sample (or any multiple of 2. That way, a processing-intensive divide does not have to be done. Simply bit-shift right by three bits (if you added 8 readings) or Right-shift 4 bits if you added 16 samples. But you'll have to take care of the data format first (negatives and positives).
The values to be averaged are in floating point and the rightshift may not work.
 
As oshonsoft doesn't have signed integers then you need to do something different. Midnight here now but I'll try and work something out tomorrow.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top