Connect with us

AK8963 Compass peripheral on 18F4620 intermittent error?

Discussion in 'General Electronics Discussion' started by camerart, Oct 24, 2019.

Scroll to continue with content
  1. camerart

    camerart

    85
    2
    Aug 18, 2010
    Hi,
    Here's a puzzle!
    I made some Compass breakout boards for an AK8963C chip. x5 (Iphone5)

    I have PCBs x3, some with 3x different peripherals, using SPI. 1x PCB with only the Compass, and a simple program on the 18F4620.

    I've been testing each peripheral on separate programs, till almost satisfied, they're working well. Untill I added them all into one program. Now the previouslt reliable Compass, sometimes works, some times doesn't, with no clue to why.

    I've been on another forum, checking the PCBs continuity, also Digital analysis, oscilloscope, with no clear result.

    If anyone has ideas what may be wrong, let me know, and I can repeat any test again, please?

    Camerart.
     

    Attached Files:

  2. Harald Kapp

    Harald Kapp Moderator Moderator

    10,368
    2,262
    Nov 17, 2011
    The problem may as well be your program, not the hardware. How about posting the relevant code snippets? Together with a schematic of the actual wiring, of course.
     
  3. camerart

    camerart

    85
    2
    Aug 18, 2010
    Hi H,
    I use Oshonsoft BASIC only.
    Here is the main snippet:
    And Schematic although as mentioned there are 3x different PCBs with slightly differing tracks.
    ----------------------------------------------------------------------
    'READ COMPASS XYZ REGISTER


    addr = 0x80 '!!!!!!!!!!!!!!!!!

    compss = 0 'CHIP SELECT COMPASS ON
    For i = 0 To 18 '5 'READ XYZ Xx2 Yx2 Zx2
    SPISend addr
    SPIReceive data
    compss = 1
    WaitUs 10
    compss = 0
    b(i) = data
    addr = addr + 1
    Next i
    compss = 1 'CHIP SELECT COMPASS OFF


    'compss = 0 'CHIP SELECT COMPASS ON
    'For i = 0 To 7 '18 '5 'READ XYZ Xx2 Yx2 Zx2
    'addr = 0x80 + i
    'SPISend addr
    'SPIReceive data
    'Next i
    'compss = 1
    'WaitUs 10

    wIa_raw = b(0)
    info_raw = b(1)
    st_1_raw = b(2)

    x_raw.LB = b(3) 'BYTE
    x_raw.HB = b(4) 'BYTE
    y_raw.LB = b(5)
    y_raw.HB = b(6)
    z_raw.LB = b(7)
    z_raw.HB = b(8)

    Hserout "WIA ", #wIa_raw, " ", "INFO ", #info_raw, " ", "XRAW LB ", #x_raw.LB, " ", "XRAW HB ", #x_raw.HB, " ", "YRAW LB ", #y_raw.LB, " ", "YRAW HB ", #y_raw.HB, " ", "ZRAW LB ", #z_raw.LB, " ", CrLf

    -----------------------------------------------------------------------------
    NOTE: [ ' = Commented out ]
    C
     

    Attached Files:

    • SCH.jpg
      SCH.jpg
      File size:
      261.6 KB
      Views:
      5
  4. Harald Kapp

    Harald Kapp Moderator Moderator

    10,368
    2,262
    Nov 17, 2011
    The schematic doesn't show how the compass modules are connected to the processor. Especially how the chip selects are connected.
    There are two ways to connect multiple SPI slaves to one SPI master controller:
    independent: requires three independent chip select signals. This is incompatible with your code as obviously you have only one compss signal.
    daisy chained: This incurs a delay of one clock cycle per component, which in my view is incompatible with your code as in your code each SPI slave is treated in the same way.
     
  5. camerart

    camerart

    85
    2
    Aug 18, 2010
    Hi H,
    If you check centre of the Schematic you can see the 3x SPI connectors, plus a list of C/S for each of the peripherals, on PORTD.

    The COMPSS is the C/S for the Compass and the sequence is the READ of the REGISTERS on the Compass in turn (LOOP).

    Here's the PCB if that makes it clearer.
    C
     

    Attached Files:

    • PCB.jpg
      PCB.jpg
      File size:
      355.1 KB
      Views:
      2
  6. Harald Kapp

    Harald Kapp Moderator Moderator

    10,368
    2,262
    Nov 17, 2011
    I have seen the SPI connectors, but the assignment to CS on port D is not very obvious.
    However, your code does not show the activation of the differnet CD signals for each module. You always activate the single signal compss.
    I'd expect activation of different CS signals for each iteration of the loop according to the assignment of chip select signals to Port D.
     
  7. camerart

    camerart

    85
    2
    Aug 18, 2010
    Hi H,
    I've attached the full program:
    NOTE TRISD and SYMBOLS.
    C.
     

    Attached Files:

    Last edited: Oct 25, 2019
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-