|
|
View previous topic :: View next topic |
Author |
Message |
Einly
Joined: 10 Sep 2003 Posts: 60
|
How to achieve maximum spi communication speed? |
Posted: Fri Jul 23, 2004 7:52 pm |
|
|
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
|
|
Posted: Fri Jul 23, 2004 8:24 pm |
|
|
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);
|
|
|
|
|
|
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
|