Finding intermittent faults in PIC PCB Peripherals OSHONSOFT

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi,
I have a PCB, with 2x PIC on, 18F4620 and 18F4431.

The 18F4620 has SPI peripherals: Altimeter, Compass, Radio and Screen. Also is an incremental encoder on 18F4431 connected via software serial
EDIT: NOT SPI

I'm getting an error with the Compass module, and I've been testing it to find where the problem lies, with help from this forum.

The error shows when the COMP shows 306.22 Degrees (It also show this when the COMP is not connected) The readings from Oscilloscope and Analyser shows the COMP is getting it's C/S, and all of the SPI DATA at the PIC.

When I switch OFF/ON the error may or may not appear.

The Voltage shows no dips, on power up.

Once the PIC is running correctly, (while still powered) I can disconnect/connect peripherals, also the programmer, with no affect. The same result when it starts in error.

I've tried changing timings between the READings.

I have a second board that acts the same.

To me it seems to be a PIC start-up problem, but I'm not expert enough to know where to look for it.

Any suggestions for tests, please.

Cheers, Camerart.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi, Note: I've changed the title to show I'm using Oshonsoft to program the PICs.

I've been doing various tests on the PCb to find the fault, and maybe found the area where it lies?

Here is a section of CODE:
The BMP280 (ALTIMETER) always gives correct results. The AK8963C (COMPASS) gives intermittent results.

Note a line with £££££££££££££££ If this line is commented out, then if when the PCB starts up, and the COMP READing is correct, at the next LOOP it errors.

I'm reluctant to change the program, but maybe the READ sections of both modules should have the same order. At the moment they're different.
C
 

Attachments

jjw

Joined Dec 24, 2013
823
If the error is the same with the compass disconnected, it means that the program reads zero for x,y,z
Why do you read always 19 values from the compass when 6 bytes for x,y,z is enough.

What do you mean by the same order in bmp280 and compass?
Check all the chip selects.
You have RD2 as compss. Better to use LATD.2
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
If the error is the same with the compass disconnected, it means that the program reads zero for x,y,z
Why do you read always 19 values from the compass when 6 bytes for x,y,z is enough.

What do you mean by the same order in bmp280 and compass?
Check all the chip selects.
You have RD2 as compss. Better to use LATD.2
Hi J,
The x,y,z DATA arrives at the PIC ok, but as you say doesn't READ it and reports zero, when it goes error. This is intermittent, and what I'm trying to trace.

Originally, I only READ 6BYTEs as can be seen by the comment, but changed it as a check to make sure the other registers, were correct after initialisation.

I show the always working BMP280 set-up, and the intermittent AK8963C set-up, which are not quite the same. Because the COMP has more registers to check, I made a SYMBOL for ADDR, instead of using the REG ADDRESS as a BYTE. (Done at a different time) I would like to write them both the same and use SYMBOLs for both but as the BMP280 is the one that needs changing I'm a little reluctant. (I will try though)

All Chip selects OK, and working.

When looking for errors, I tried LATD, PORTD and RD, I'll put it back to the original LATD.
Thanks.
C.
 

jjw

Joined Dec 24, 2013
823
Why would you change BMP280 when it is working???
I would change the compass:

compss=0 ***** moved before for next loop ****
For I=0 to 18
addr=0x80+I
Spisend addr
....
Next I
compss=1 **** moved after the the loop ****
 
Last edited:

jjw

Joined Dec 24, 2013
823
In the full program checking the RDY with while - wend takes too much time.
It is better to skip the compass program if compass is not ready.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Why would you change BMP280 when it is working???
I would change the compass:

compss=0 ***** moved before for next loop ****
For I=0 to 18
addr=0x80+I
Spisend addr
....
Next I
compss=1 **** moved after the the loop ****
Hi J,
Re: 'checking DRDY' I read the attached as DRDY not being compulsory. Watching DRDY with Oscilloscope, looks like the DATA is ready most of the time, especially, given the length of the LOOP. Once READ it re-sets

I'm trying to recall how the BYTES are READ, perhaps not the same for both modules.

I notice that in the working BMP280 [ adr = 0xfa + i 'Altimeter ] (i not 1)

I've been trying different numbers here AK8963C [ For i = 0 To 5 ] and find that the ERROR 306.22 is changing to a different fixed number. Therefore, I'm pretty sure the registers are not being correctly READ, but I can't understand how it works sometimes??

I'm going to only READ the 6x REGISTERS needed.
C
 

Attachments

jjw

Joined Dec 24, 2013
823
I wrote 0x80 +I , means capital i
When reading 6 data bytes xyz, did you notice, that they start from 0x83

About RDY:

6.4.3.2. Normal Read Sequence
(1) Check Data Ready or not by any of the following method.
- Polling DRDY bit of ST1 register
- Monitor DRDY pin
When Data Ready, proceed to the next step.

What is the setup of the compass?
Have you looked at the spi signals?
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
I wrote 0x80 +I , means capital i
When reading 6 data bytes xyz, did you notice, that they start from 0x83

About RDY:

6.4.3.2. Normal Read Sequence
(1) Check Data Ready or not by any of the following method.
- Polling DRDY bit of ST1 register
- Monitor DRDY pin
When Data Ready, proceed to the next step.

What is the setup of the compass?
Have you looked at the spi signals?
Hi J,
Ok, I'll change the [ 1 ] to [ i ].

I noticed 0x83 after a while, and also recalled the READ BIT %10000000.

When I re-read the [ or not ] I removed the DRDY. I set it this way previously when the COMP worked before adding it into the MAIN program.

I've trying different line order between SPICSON and SPICSOFF, with no effect, so I'll leave it as #5.

I now HSEROUT all of the BYTES individually. When in ERROR, they all show [ 0 ] or [ 255 ].

I'm now looking at HOFL, in case of OVERFLOWN. Perhaps that's why I READ all of the REGISTERS.
C
 

jjw

Joined Dec 24, 2013
823
I don't know what effect SPICSON, SPICSOFF have as
you ( hopefully ) have not defined Spics register and Spics bit.
Maybe they should not be used at all.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
I don't know what effect SPICSON, SPICSOFF have as
you ( hopefully ) have not defined Spics register and Spics bit.
Maybe they should not be used at all.
Hi J,
SPICSON/OFF are required for Oshonsoft SPI This works with all other modules.

I meant I tried changing the line order in between SPICSON/OFF, but this didn't change anything, so ignore.

How do I check HOFL? I assume it would be something like this: (before READing the REGISTERS for a WHILE/WEND)??
----------------------------------------------------------
SPICSOn
compss = 0 'CHIP SELECT COMPASS ON
SPISend 0x89 'HOFL BYTE
SPIReceive data
compss = 1 'CHIP SELECT COMPASS OFF
SPICSOff
--------------------------------------------------------------
then I don't know what to do?
EDIT: I tried below, which doesn't work (If set for [ 0 ] then it waits forever
-------------------------------------------------------------------------------
hofl:
SPICSOn
compss = 0 'CHIP SELECT COMPASS ON
SPISend 0x89 'HOFL
SPIReceive data
compss = 1 'CHIP SELECT COMPASS OFF
SPICSOff

st_2_raw = data

If st_2_raw.3 = 1 Then Goto hofl
------------------------------------------------------------------------------

C.
 
Last edited:

jjw

Joined Dec 24, 2013
823
How do you know, that SPICSON, SPICSOFF are required?
You can test it leaving them out from BMP280.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Hi J,
This is looking promising. So far always a READing :)
-------------------------------------------------------------------------------------------
compss = 0 'CHIP SELECT COMPASS ON
For i = 0 To 18 '5 'READ XYZ Xx2 Yx2 Zx2
SPISend addr
SPIReceive data
b(i) = data
addr = addr + i
Next i
compss = 1 'CHIP SELECT COMPASS OFF

addr = 0x80 '!!!!!!!!!!!!!!!!!
-----------------------------------------------------------------------------------------
C.
 

jjw

Joined Dec 24, 2013
823
Hi J,
This is looking promising. So far always a READing :)
-------------------------------------------------------------------------------------------
compss = 0 'CHIP SELECT COMPASS ON
For i = 0 To 18 '5 'READ XYZ Xx2 Yx2 Zx2
SPISend addr
SPIReceive data
b(i) = data
addr = addr + i
Next i
compss = 1 'CHIP SELECT COMPASS OFF

addr = 0x80 '!!!!!!!!!!!!!!!!!
-----------------------------------------------------------------------------------------
C.
Then #5 should have worked. Did you try it at all?
 

Thread Starter

camerart

Joined Feb 25, 2013
3,724
Then #5 should have worked. Did you try it at all?
Hi J,
I always test any suggestions you or anybody makes, including #5

In #5 there are missing sections to fill in, which I did, but can't remember exactly what.

I've done the same thing again, to test #5 again, and it works as good as #14. With the intermittent nature of the error, both examples work 70%. Once working, both seem reliable, so maybe a check, and if necessary reset till working may be needed.

Perhaps, it will be better for me to tidy up the MAIN program, and re-visit this later. What do you think?

Does it matter that RED is before and after the SPISEND/RECEIVE? in the examples:
------------------------------------------------------------------------------------------------------------
'compss = 0 'CHIP SELECT COMPASS ON
'For i = 0 To 18 '5 'READ XYZ Xx2 Yx2 Zx2
'SPISend addr
'SPIReceive data
'b(i) = data
'addr = addr + i
'Next i
'compss = 1 'CHIP SELECT COMPASS OFF

'addr = 0x80 '!!!!!!!!!!!!!!!!! (Superfluous, I think)

compss = 0 '* * * * * moved before For Next loop * * * *
For i = 0 To 18
addr = 0x80 + i
SPISend addr
SPIReceive data
b(i) = data
Next i
compss = 1 '* * * * moved after the the loop * * * *
----------------------------------------------------------------------------------------------------
C
 

jjw

Joined Dec 24, 2013
823
Hi J,
I always test any suggestions you or anybody makes, including #5

In #5 there are missing sections to fill in, which I did, but can't remember exactly what.

I've done the same thing again, to test #5 again, and it works as good as #14. With the intermittent nature of the error, both examples work 70%. Once working, both seem reliable, so maybe a check, and if necessary reset till working may be needed.

Perhaps, it will be better for me to tidy up the MAIN program, and re-visit this later. What do you think?

Does it matter that RED is before and after the SPISEND/RECEIVE? in the examples:
------------------------------------------------------------------------------------------------------------
'compss = 0 'CHIP SELECT COMPASS ON
'For i = 0 To 18 '5 'READ XYZ Xx2 Yx2 Zx2
'SPISend addr
'SPIReceive data
'b(i) = data
'addr = addr + i
'Next i
'compss = 1 'CHIP SELECT COMPASS OFF

'addr = 0x80 '!!!!!!!!!!!!!!!!! (Superfluous, I think)

compss = 0 '* * * * * moved before For Next loop * * * *
For i = 0 To 18
addr = 0x80 + i
SPISend addr
SPIReceive data
b(i) = data
Next i
compss = 1 '* * * * moved after the the loop * * * *
----------------------------------------------------------------------------------------------------
C
addr=0x80+i should be before Spisend addr
 

jjw

Joined Dec 24, 2013
823
compss = 0 'CHIP SELECT COMPASS ON
'For i = 0 To 18 '5 'READ XYZ Xx2 Yx2 Zx2
'SPISend addr
'SPIReceive data
'b(i) = data
'addr = addr + i
'Next i
'compss = 1 'CHIP SELECT COMPASS OFF

This does not work at all.
Find out why by going through the for next loop and calculating addr with each value of i.
 
Top