CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC16F677: Mysterious clock period loss in SPI slave mode

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
koesterk



Joined: 15 Apr 2008
Posts: 3

View user's profile Send private message

PIC16F677: Mysterious clock period loss in SPI slave mode
PostPosted: Fri Jan 16, 2009 8:19 am     Reply with quote

Hi guys,

I found a mysterious phenomenon in the PIC16F677 while running in SPI slave mode (CKE=0, CKP=1). Above a certain incoming SPI clock speed I can't hit the short period between "Buffer Full" and the first bit latch of the next byte any more. The CPU is running at 8 MHz and a stream of 5 bytes is coming in/going out on a continuously running clock (this is mandatory for my application).

The test software I wrote is rather trivial: Waiting in an endless loop for "BF" becoming active, then just a simple port toggler.

For SPI clocks below 80 kbps it works fine. The delay between the last bit latching and the port toggler is measured to ~4µs. In this case there is enough time to read the incoming RX byte and write the next TX byte to SSPBUF before the first bit of the next byte is latched.

Above 80 kbps the time between the rising edge of the last bit and the port toggler increases by approx. one SPI clock period, i.e. at least 14..15 µs. In this case I have no chance to fill the SSPBUF in time (100kbps = 10 µs clock period).

Quite interesting that I2C works fine on this device with 100kbps.

Does anybody have an idea why the SSP interface generates its interrupt delayed by one period? I played on master side with the latency between SS becoming active and the first bit going out but it does not help. Are there any restrictions regarding SPI that might cause such an effect?

Thanks a lot and best regards
Klaus

[/code]
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: PIC16F677: Mysterious clock period loss in SPI slave mod
PostPosted: Fri Jan 16, 2009 9:17 am     Reply with quote

I assume that interrupts are disabled and that your tight loop waiting for BF is as tight as possible, such as:

Code:

  do
  {
  }while(!SSPSTAT.BF);

which ought to compile to a loop whose round-trip time is 4 instruction cycles, or 2 usec. Then in one more instruction you can set an output bit, for a maximum latency of 2.5 usec.

Please post the code you are using for this test, and if possible, the dissasembly listing for this critical part of the code so we can count instructions and see if 4 usec. is about right, and if there is anything there that might take 10 usec. more.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Guest








PostPosted: Wed Jan 21, 2009 9:42 am     Reply with quote

Robert

first of all thank you very much for your reply. I did exactly what you assumed: A while loop waiting for the interrupt flag going high and a port toggler afterwards. In total I can expect a maximum latency of 3..4µs.

When I made my measurements I started with 50.000 bps and increased the value in steps of 10.000. Up to 80.000 bps I saw what I expected: roundabout 4 µs delay between last SPI bit latched and the port pin going up. For 90.000 bps I saw an overall delay of ~15µs, for 100.000 bps I measured 14 µs.

In my application the controller sleeps most of the time an wakes up by SPI data coming in. Above a certain limit (between 80k and 90k) it seems that the SPI peripheral loses one SPI clock cycle (i.e. 11µs @ 90k, 10µs @ 100k !!!).

I already reported this behaviour to Microchip. Until now they haven't answered yet. It seems to me that it was a good question. ;-)

I found a similar behaviour described in the errata of the F677, but with a different SPI setup. Unfortunately the described workaround does not work in my case.

Anyway, meanwhile I could convince my colleagues programming the SPI master to accept 50k as maximum speed. Thus, I could finish my software today. When Microchip replies I will forward their answer to this forum. I fear it's a bug in the SSP state machine but let's wait what they write.

Thanks again and best regards
Klaus
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group