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 to achieve maximum spi communication speed?

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



Joined: 10 Sep 2003
Posts: 60

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger ICQ Number

How to achieve maximum spi communication speed?
PostPosted: Fri Jul 23, 2004 7:52 pm     Reply with quote

Dear all,

I am interfacing AD7716 with PIC16f876. It is a 4 channel adc. Every channel will give 32 bits output. To complete reading the digital output, we have to shift in 32x4 bits using spi communication.

Below is a part of my code:

#use fast_io(b)

//For each channel, I only shift_left 2 bytes since I am only interested in the 2 most significant bytes. After that I just provide 16 clock pulses, without actually reading the data.

for(int i=0;i<16;i++)
{
output_high(SCLK);
output_low(SCLK);
sheft_left(chan0,2,input(SDATA));
}

for(int i=0;i<16;i++)
{
output_high(SCLK);
output_low(SCLK);
}

for(int i=0;i<16;i++)
{
output_high(SCLK);
output_low(SCLK);
sheft_left(chan1,2,input(SDATA));
}

for(int i=0;i<16;i++)
{
output_high(SCLK);
output_low(SCLK);
}

for(int i=0;i<16;i++)
{
output_high(SCLK);
output_low(SCLK);
sheft_left(chan2,2,input(SDATA));
}

for(int i=0;i<16;i++)
{
output_high(SCLK);
output_low(SCLK);
}

for(int i=0;i<16;i++)
{
output_high(SCLK);
output_low(SCLK);
sheft_left(chan3,2,input(SDATA));
}

for(int i=0;i<16;i++)
{
output_high(SCLK);
output_low(SCLK);
}

#use standard_io(b);

I check with oscilloscope and found out that to shift in all the 4 channels, I need around 340us, means 85 us for each channel.

May I know how can I shorten the time needed to shift all the data? By
1) Using different code?
2) Using hardware spi?
3) Using different PIC microcontroller chip?
4) Using DSP?
_________________
Einly
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Fri Jul 23, 2004 8:24 pm     Reply with quote

Change syntax to count down. This;
Code:

for(int i=0;i<16;i++)
{
output_high(SCLK);
output_low(SCLK);
}
Would be faster like this;
Code:

for(int i=16;i>0;i--)
{
output_high(SCLK);
output_low(SCLK);
}

Shift only one byte at a time.This;
Code:
for(int i=0;i<16;i++)
{
output_high(SCLK);
output_low(SCLK);
sheft_left(chan0,2,input(SDATA));
}
Would be faster like this;
Code:

for(int i=8;i>0;i--)
{
output_high(SCLK);
output_low(SCLK);
sheft_left(chan0hi,1,input(SDATA));
}
for(int i=8;i>0;i--)
{
output_high(SCLK);
output_low(SCLK);
sheft_left(chan0lo,1,input(SDATA));
}
chan0 = make16(chan0hi,chan0lo);
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