# Setting up AK8963C Compass chip SPI Oshonsoft

#### camerart

Joined Feb 25, 2013
1,827
Last edited:

#### camerart

Joined Feb 25, 2013
1,827
Hi,
I've just spotted this:
LAYOUT CONSIDERATIONS Besides keeping all components that may contain ferrous materials (nickel, etc.) away from the sensor on both sides of the PCB, it is also recommended that there is no conducting copper under/near the sensor in any of the PCB layers. See recommended layout below. Notice that the one trace under the sensor in the dual supply mode is not expected to carry active current since it is for pin 4 pull-up to VDDIO. Power and ground planes are removed under the sensor to minimize possible source of magnetic noise. For best results, use non-ferrous materials for all exposed copper coding.

I've made all of my modules with an underside ground plane, which I'll need to change.

C.

#### jpanhalt

Joined Jan 18, 2008
8,771
Have you tested that change? That is, a smallish drill will remove the copper easily. Most drills are 118° included angle, aircraft and sheet metal drills are often 135°. That will remove a wider area with less depth. Higher angles don't center as well. If you have access to a mill, of course you can use a 3 mm mill bit.

#### camerart

Joined Feb 25, 2013
1,827
Have you tested that change? That is, a smallish drill will remove the copper easily. Most drills are 118° included angle, aircraft and sheet metal drills are often 135°. That will remove a wider area with less depth. Higher angles don't center as well. If you have access to a mill, of course you can use a 3 mm mill bit.
Hi JP,
I've just scraped the copper off the bottom area of a test chip, with a scalpel. Now to test it.
C

#### camerart

Joined Feb 25, 2013
1,827
Hi,
Just tried to run MAGMASTER, but get a 'serial port' error MAGVIEWER runs ok.
C.

#### jpanhalt

Joined Jan 18, 2008
8,771
This is the Compass-Click bottom with the AK8963. unfortunately the RoHS label covers the area of interest. Top and bottom photos are on that site, if you need any help in routing. Apparently, it has a copper ground plane under the chip (circled area). Also confirmed by inspection of my board.

EDIT: I thought I had edited that comment out before posting. It was for a different BOB.

Last edited:

#### camerart

Joined Feb 25, 2013
1,827
This is the Compass-Click bottom with the AK8963, unfortunately the RoHS label covers the area of interest. Top and bottom photos are on that site, if you need any help in routing. Apparently, it has a copper ground plane under the chip (circled area). Also confirmed by inspection of my board.

View attachment 174748
Hi JP,
I made my own boards from the AK8963C chips. I have them routed and working, but the MAGMASTER settings are causing problems, so I'm going through the instructions again.
C

#### Attachments

• 149.1 KB Views: 6

#### jjw

Joined Dec 24, 2013
508
I changed the atn function to work CW.
No need to subtract atn from 360. ( DEG=360-atn())

Code:
Function atn(x As Single, y As Single) As Single

Const b = 0.596227
Dim tn As Single
Dim at1 As Single
Dim at2 As Single

If y = 0 Then
y = y + 0.000001  'to prevent divide by zero
Endif

tn = x / y
at1 = 90 * tn * (b + tn) / (1 + 2 * b * tn + tn * tn)
at2 = -90 * tn * (b - tn) / (1 - 2 * b * tn + tn * tn)

If x >= 0 Then
If y > 0 Then
atn = 360 - at1
Endif
Endif

If x >= 0 Then
If y < 0 Then
atn = 180 + at2
Endif
Endif

If x < 0 Then
If y < 0 Then
atn = 180 - at1
Endif
Endif

If y > 0 Then
If x < 0 Then
atn = at2
Endif
Endif

End Function

#### camerart

Joined Feb 25, 2013
1,827
I changed the atn function to work CW.
No need to subtract atn from 360. ( DEG=360-atn())
Hi J,
Magic, thank you.
C.

#### camerart

Joined Feb 25, 2013
1,827
Hi,
Is anyone using MAGMASTER/VIEWER?

I can get Magviewer to work most times, but Magmaster has stopped working. I've tried a different computer, no change. I had a pair of HC-12 radios and FTDI USB adapters, then tried hard wiring, no change.

I get serial port error each time.
C.

#### camerart

Joined Feb 25, 2013
1,827
Hi,
It looks as though the best thing is, to open Magviewer/USB input, which is working, and Magmaster/no USB input, and manually input the viewer READings into Magmaster to get the calculation.

Looking at the compass transmissions, I'm getting very varied outputs, so I'm now looking at the DRDY and HOFL in the AK8963C data sheet, to see if the READings can be less varied.

C.

#### Attachments

• 1.1 KB Views: 2

#### jpanhalt

Joined Jan 18, 2008
8,771
Hi C,
About 2 years ago I posted a movie of my AK8963. Here is a link to that movie (sorry it is zipped): https://forum.allaboutcircuits.com/attachments/my-movie-zip.116328/

Here is a snippet from that post that describes my settings (e.g., 100 Hz readings, read x16 in 16-bit mode).
jpanhalt said:
I ended up selecting the AK8963C for my current project. The interface is just as easy as for the BMC156. It offers two sensitivities: 16-bit (0.15 uT/LSB) and 14-bit (0.6 uT/LSB). One can put it in a permanently on mode. It only offers two read frequencies: 8 Hz and 100 Hz. I used 100 Hz and averaged 16 readings at 16-bit resolution. The difference between 8 and 16 readings was imperceptible. I wish I had a standard magnetic source with which to calibrate it, but the observed values seem reasonable based on my location ( http://geomag.usgs.gov/plots/ location key: http://geomag.usgs.gov/monitoring/observatories/ ).
You may want to compare your stability with what that shows.

John

#### camerart

Joined Feb 25, 2013
1,827
Hi C,
About 2 years ago I posted a movie of my AK8963. Here is a link to that movie (sorry it is zipped): https://forum.allaboutcircuits.com/attachments/my-movie-zip.116328/

Here is a snippet from that post that describes my settings (e.g., 100 Hz readings, read x16 in 16-bit mode).

You may want to compare your stability with what that shows.

John

Hi JP,
Your movie is much more stable.

EDIT: Did you use SELF TEST MODE--------------SINGLE MEASUREMENT MODE----------HOFL---------- OR DRDY in your code ?
C.

Last edited:

#### camerart

Joined Feb 25, 2013
1,827
Hi,
In #10, I reported that Magviewer is working, but Magmaster isn't.

I had a section of code that does a DEG calculation, plus a DEG HSEROUT, along with the 3x compass READings. Once the DEG part is removed, Magmaster works ok now.
C

#### camerart

Joined Feb 25, 2013
1,827
Hi,
I'm re-reading the AK8963C data sheet, and am trying the SELF TEST routine.

Here is a program:
Also the D/S SELF TEST page
Also the result.
Does this look correct?
C

#### Attachments

• 8 KB Views: 9
• 198.5 KB Views: 4
• 28.1 KB Views: 4

#### jjw

Joined Dec 24, 2013
508
The results are not ok. X, Y cannot both be zeroes.
Should'nt the x, y, z values be b(0) to b(5) now they start from b(1).

Last edited:

#### camerart

Joined Feb 25, 2013
1,827
The results are not ok. X, Y cannot both be zeroes.
Should'nt the x, y, z values be b(0) to b(5) now they start from b(1).
Hi J,
I changed the B() values to 0-5 and got all zeros.
Then changed the b() values to 6-11 and got these results: 224, 96, 64, 64, 144, 240

so 224 is position 6. These appear to be other register READings, which appears to mean that the DATA isn't being READ.

C

#### jjw

Joined Dec 24, 2013
508
You don't check the rdy bit when reading xyz.

#### camerart

Joined Feb 25, 2013
1,827
You don't check the rdy bit when reading xyz.
Hi J,
Did you read number4 on the self test mode at #15?

Just looking at those results #17 for clues.
224 = 11100000
96 = 01100000
64, 64 = 01000000
144 = 10010000
240 = 11110000
All of the '1's are at the higher end of the BYTE where e,g,0x09 should READ BITs 3 and 4?
C.

Last edited:

#### jjw

Joined Dec 24, 2013
508
Hi J,
Did you read number4 on the self test mode at #15?

Just looking at those results #17 for clues.
224 = 11100000
96 = 01100000
64, 64 = 01000000
144 = 10010000
240 = 11110000
All of the '1's are at the higher end of the BYTE where e,g,0x09 should READ BITs 3 and 4?
C.
What is number4?
In your program there is no check of drdy before reading x, y, z