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

Speeding up software SPI
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Thu May 24, 2018 12:37 pm     Reply with quote

I think last time I just used a delay_us(1) and then toggled an output and watched the frequency on a scope. Is there a better way to test the speed? I really hope I have not been running slower than I thought this whole time! Man the old 8 bit days were so easy. ;)
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu May 24, 2018 12:46 pm     Reply with quote

Problem with that is the delays involved in the actual output operations. Do a toggle at a much longer interval like 10 seconds, and you can check with a stopwatch.
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Thu May 24, 2018 1:18 pm     Reply with quote

Then I guess that takes any instruction lags out of there. Makes sense.... Thanks.

You would still use delay_ms(10000); then at that point. Or a timer?
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri May 25, 2018 12:52 am     Reply with quote

delay_ms.

The whole point is that this then tells you 'for sure' how long the compiler thinks 10 seconds is in instructions. If the figure is wrong, it says the chip isn't running at the speed the compiler expects.....

Now (of course), if this is 'right', we then have the question of why on earth the SPI rate isn't getting to the 243nSec period?.....
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Fri May 25, 2018 10:18 am     Reply with quote

Ok thought so. I really hope that it's still running at speed.... But it would help in other spots . I think I am getting 970ns which is 4 times slower almost exactly than what you are getting. I will be really mad at myself if this is really the case!

Thanks for all the input..
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Sat May 26, 2018 10:15 am     Reply with quote

Clock is correct.

Here is what i am using to set up the SPI.

#use spi(MASTER, DO=PIN_B11, MODE=3, BITS=8, stream=NEO_PIX)

I am only getting a 960nS bit width.

I am still going to try switching the pinout so I can use hardware SPI for both.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Sat May 26, 2018 11:08 am     Reply with quote

Er. What pin is being used for the clock?.....
I'd suspect the SPI doesn't like not having a clock pin. After all it is a _synchronous_ bus, and therefore requires a clock.
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Sat May 26, 2018 12:02 pm     Reply with quote

No clock needed for neo pixels.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Sat May 26, 2018 1:26 pm     Reply with quote

I'd suspect this is what is killing the clock rate. The SPI is not designed to support operation without a clock. The software is in a mode it is not written to support. Using the hardware SPI, you will have a clock pin.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 26, 2018 1:54 pm     Reply with quote

He has never said how he's measuring the bit rate. He might be
measuring it incorrectly. He has never posted the code loop that
sends the data. If he posted a complete test program, the issue
would probably be cleared up quickly.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Sat May 26, 2018 2:06 pm     Reply with quote

Very true.
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat May 26, 2018 3:53 pm     Reply with quote

the 4x slower is kind of a 'red flag' to me, almost sounds like 'smthing' isn't getting set properly...
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Sat May 26, 2018 6:01 pm     Reply with quote

Measuring bit rate with a logic analyzer. I actually would be getting 1/2 that as I was using 0xC0 to generate the bit length which is 2 hi's.

This code worked fine on a hardware SPI with baud of 6500000.
Code:

#use spi(MASTER, DO=PIN_B11, MODE=3, BITS=8, stream=NEO_PIX)

#define one                                     0xF8
#define zero                                    0xC0

void WS2812_send_data(unsigned char r, unsigned char g, unsigned char b){
    unsigned char s = number_of_bits;
    unsigned long value = 0x00000000;
    value = (((unsigned long)g << 16) | ((unsigned long)r << 8) | ((unsigned long)b));

    while(s > 0)
    {
        if((value & 0x800000) != LOW){
      spi_xfer(NEO_PIX,one);
        }

        else{
      spi_xfer(NEO_PIX,zero);
        }
        value <<= 1;
        s--;
    }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 26, 2018 7:03 pm     Reply with quote

In a previous thread, you said this:
Quote:
Compiler verison is 5.056.

Is that still what you're using ?
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Sat May 26, 2018 7:05 pm     Reply with quote

5.061 now..
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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