Finding intermittent faults in PIC PCB Peripherals OSHONSOFT

Thread Starter

camerart

Joined Feb 25, 2013
3,730
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.
Hi J,
Both #18 sections work as good as each other. Both error 25% of the time, but if no error at start-up, then both seem reliable.
I guess that with the [ addr = addr + i ] after SPISEND, then it gets a READing beforethe start of the 1 to 18 LOOP, so givig an extra READ at the end?

EDIT: From the tests I've tried, I'm pretty sure the problem is at the PIC end, as the SPI signals are arriving.

NOTE: Normally I'm programming the PIC using a Pickit3, that has a MCLR PIN, and needs the PIC to be powered up before programming. If I'm not programming, but testing, and try a test, without the Pickit3 attached, then I get error with all the last tries. However, as soon as it was attached and powered, then no error. So perhaps it is a PIC initiation problem
EDIT EDIT: I've just checked the PCB, and noticed that there are no capacitors near the PIC power PINS, which is suggested. I'll add some.
 
Last edited:

jjw

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

Assume that addr is correct 0x80 when the loop starts
i=0 addr to read from =0x80 is correct
i=1 addr =0x81 is correct
i=2 addr =0x83 not correct, skipped 0x82
i=3 addr=0x86 not correct, skipped 0x84, 00x85
etc.
Maybe you get some non zero values and angle is different from 306 but is still wrong.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
For i = 0 To 18 '5 'READ XYZ Xx2 Yx2 Zx2
addr=addr+i
'SPISend addr
'SPIReceive data
'b(i) = data
'Next i

Assume that addr is correct 0x80 when the loop starts
i=0 addr to read from =0x80 is correct
i=1 addr =0x81 is correct
i=2 addr =0x83 not correct, skipped 0x82
i=3 addr=0x86 not correct, skipped 0x84, 00x85
etc.
Maybe you get some non zero values and angle is different from 306 but is still wrong.
Hi J,
Of course! ADDR is incrementing and plussing [ i ]
----------------------------------------------------------------------------
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 + 1
Next i
compss = 1 'CHIP SELECT COMPASS OFF

addr = 0x80
-------------------------------------------------------------------------
Is this correct?
EDIT: addr = 0x80
C
 
Last edited:

jjw

Joined Dec 24, 2013
823
It is correct, but this is simpler
addr=0x80+i
Spisend addr
etc
You could make a test reading xyz one by one without looping and printing them.

Spisend 0x83
Spireceive data
X.lb=data

Spisend 0x84
Spireceive data
X.hb=data

Same for y and z

You could use the analyzer to check the data coming from the compass.
 

jjw

Joined Dec 24, 2013
823
Hi J,
Of course! ADDR is incrementing and plussing [ i ]
----------------------------------------------------------------------------
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 + 1
Next i
compss = 1 'CHIP SELECT COMPASS OFF

addr = 0x80
-------------------------------------------------------------------------
Is this correct?
EDIT: addr = 0x80
C
addr=0x80 has to be before the loop
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
addr=0x80 has to be before the loop
Hi J,
Up to now there was an [ addr = 0x80 ] before the MAIN LOOP, I'll remove it for clarity, and use you CODE.

First/
Connected analyser with recent program with this section (Bear in mind that we don't use the [ i ] anymore, but this is just to show)
-------------------------------------------------------------------------
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 * * * *
--------------------------------------------------------------------------
Here are the Terminal and analyser READings
C.
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi J,
Second test, with individual READs

--------------------------------------------------------------------------------------
compss = 0
SPISend 0x83
SPIReceive data
hxl = data
Hserout "HXL ", #hxl, CrLf
'compss = 1

'compss = 0
SPISend 0x84
SPIReceive data
hxh = data
Hserout "HXH ", #hxh, CrLf
'compss = 1

'compss = 0
SPISend 0x85
SPIReceive data
hxl = data
Hserout "HYL ", #hyl, CrLf
'compss = 1

'compss = 0
SPISend 0x86
SPIReceive data
hxl = data
Hserout "HYH ", #hyh, CrLf
'compss = 1

'compss = 0
SPISend 0x87
SPIReceive data
hxl = data
Hserout "HZL ", #hzl, CrLf
'compss = 1

'compss = 0
SPISend 0x88
SPIReceive data
hxl = data
Hserout "HZH ", #hzh, CrLf
compss = 1

------------------------------------------------------------------------------
TERM and ANALYSER
C
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi J,
Third test/

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

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 + 1
Next i
compss = 1 'CHIP SELECT COMPASS OFF
-------------------------------------------------------------------------------------
Term and Analysis.
C
 

Attachments

jjw

Joined Dec 24, 2013
823
Hi J,
Second test, with individual READs

--------------------------------------------------------------------------------------
compss = 0
SPISend 0x83
SPIReceive data
hxl = data
Hserout "HXL ", #hxl, CrLf
'compss = 1

'compss = 0
SPISend 0x84
SPIReceive data
hxh = data
Hserout "HXH ", #hxh, CrLf
'compss = 1

'compss = 0
SPISend 0x85
SPIReceive data
hxl = data
Hserout "HYL ", #hyl, CrLf
'compss = 1

'compss = 0
SPISend 0x86
SPIReceive data
hxl = data
Hserout "HYH ", #hyh, CrLf
'compss = 1

'compss = 0
SPISend 0x87
SPIReceive data
hxl = data
Hserout "HZL ", #hzl, CrLf
'compss = 1

'compss = 0
SPISend 0x88
SPIReceive data
hxl = data
Hserout "HZH ", #hzh, CrLf
compss = 1

------------------------------------------------------------------------------
TERM and ANALYSER
C
Is the angle sensible?
Could you make individual reads and change the compass orientation after each xyz for example N,E,S,W
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Is the angle sensible?
Could you make individual reads and change the compass orientation after each xyz for example N,E,S,W
Hi J,
I tried individual READs, but I got worse results. I also tried other ideas, but still no good.
We've spent a long time on this, so I think I had better go back and prove the COMP/PCBs and re-calibrate etc, before going farther along this track.

In the meantime, I'll go back to the MAIN thread, and try to finish the MAIN program, without the COMP for now.
Thanks, again for your patience.
C.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
I'm looking for likely things that would give intermittent faults, i,e, Components, soldering, programming etc.

I've got 5xCompass modules, and 3x PCBs.
We've altered the program many times.

I've searched online, and seen mentions of PULL RESISTORS, which I'll try, but having checked with a DATA Analyser, and Oscillator, doubt it's that.

I've just spotted this:
The SCK is oscillating opposite to the D/S recommendations, could this cause intermittent faults? (After past comments, I hope the detail can be seen)
NOTE: The top analysis is working, the bottom is not working. I've tried adding the DIS/ENABLEs in between the READS, but no difference.

EDIT: Here's the SPI clock modes from the 18F4620 D/S
EDIT EDIT: I'm checking this previous explanation: https://forum.allaboutcircuits.com/...wspi-in-oshonsoft.156175/page-10#post-1411674 e,g, #193
C
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
I just tried to change SSPSTAT and SPCON1 to the best of my abilities, but it still errors :(
I'm happy to test any other settings
C
 

jjw

Joined Dec 24, 2013
823
1) No.
2) What do you mean by opposite to recommendations?
Look at the Oshonsoft Basic manual. There are some settings for the Spi clock.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,730
1) No.
2) What do you mean by opposite to recommendations?
Look at the Oshonsoft Basic manual. There are some settings for the Spi clock.
Hi J,
I have collected a lot of help files for Oshonsoft over the years, including PIC Simulator IDE BASIC Compiler Reference Manual , much of it looks redundant, so needs clearing out. I don't think I've got the actual Oshonsoft Basic manual. I'll download it and check your comment.
C
 
Top