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

How many instructions does hardware spi take ?

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



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

How many instructions does hardware spi take ?
PostPosted: Fri Feb 24, 2006 7:11 pm     Reply with quote

How long does this op take ?? Where the GOTO is looping back 8 times, no ? My knowledge of assembly is pretty limited.

.................... spi_write(WRITECMD);

02C9: MOVF 13,W
02CA: MOVLW 02
02CB: MOVWF 13
02CC: BSF 03.5
02CD: BTFSC 14.0
02CE: GOTO 2D1
02CF: BCF 03.5
02D0: GOTO 2CC

This should be easy and I searched but I could not find anyone with anything close.

I'm trying to figure out the time my SPI routine is taking. Its 40MHz and I think the fastest it can go is OSC/4 so its 10 or 5MHz if I go with a 20 clock.

I was thinking of maybe setting a RTOS clock up before my Read and Write functions and then reading after as kind of a benchmark... I think that'll work no ?
Ttelmah
Guest







PostPosted: Sat Feb 25, 2006 3:35 am     Reply with quote

No. The goto does not loop eight times. It loops till the byte has transferred.
The byte starts sending, as soon as it is loaded into the register. Eight instruction times from here, the transmission flag will go clear. This will be detected on the third loop, giving ten instruction times from the send, to to exit jump, and a total of twelve instruction times from the load to the exit.
In fact this is one of my 'annoyances' with the CCS SSP functions. At the end of the day, if using the hardware SSP, I want to get on and be doing other things while the transmission takes place, not waiting for it to complete. I use:
Code:

#byte   SSPBUF = 0x13
#byte   SSPCON = 0x14
#byte   I2CBUF = 0x93
#byte   SSPSTAT = 0x94
/* Now the SSP handler code. Using my own, since the supplied routines test the wrong way round for my needs */
#DEFINE READ_SSP()                   (SSPBUF)
#DEFINE WAIT_FOR_SSP()   while((SSPSTAT & 1)==0)
#DEFINE WRITE_SSP(x)   SSPBUF=(x)
#DEFINE CLEAR_WCOL()   SSPCON=SSPCON & 0x3F

Then you can use:
Code:

//Do this if the SSP may still be busy - otherwise no need for this.
WAIT_FOR_SSP();

WRITE_SSP(WRITECMD);
//This puts the byte into the output register, so the SSP starts sending
//Now you can get on with doing other things, while the hardware
//sends the byte.

Now the key difference, is that it becomes _your_ responsibility to verify that the SSP has finished, before reading/writing a byte, but it gives you the ability to go off an do other jobs while the transmission takes place.
At FOSC/4, the difference is probably not worth worrying about. However if (say), you are using a PIC at 40MHz, and SSP at FOSC/64, then you can perform 128 instructions in the time a transfer involves...

Best Wishes
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Sat Feb 25, 2006 12:18 pm     Reply with quote

Ttelmah you are the man!

Thank You very much. I was indeed a little confused as to why the looping was going on but it makes sense now.

If it took 8 iterations that would have made a LARGE difference in my program,

As it is I think it takes me 12 instructions just to dertemine which CS to use so 12 for SPI is not a big deal at all!
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