Shop OBEX P1 Docs P2 Docs Learn Events
SimpleIDE SPI bus speed — Parallax Forums

SimpleIDE SPI bus speed

Andrew BubbleAndrew Bubble Posts: 21
edited 2014-12-11 01:39 in Propeller 1
HI Everyone, I need some help with the SPI bus speed using the Simple IDE, I recently posted a thread concerning the I2C bus speed and how to alter this.

I am developing an RGB LED controller using the Propeller chip. I am planning to use the Adafruit 24 Channel 12 bit PWM LED driver board. Link to the product below.

http://www.adafruit.com/products/1429


This uses a Texas Instruments TLC5947. I have looked round the net for information on the SPI bus speed but can't find any info. I plan to dedicate one of the cogs to the task of updating the lights when any of the data changes and I have to send 288 bits or 36 bytes to the TLC5947 chip.

Does any body know if there are a more suitable SPI library where I can set the desired bus speed, or can the one in the standard library be used in a different way.

Regards Andrew

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2014-12-10 09:21
    You didn't say why or how you'd want to set the SPI bus speed. I'm assuming that you want to update the TLC5947s as quickly as possible. According to the TLC5947's datasheet, the maximum clock speed for cascaded devices is 15MHz with a 50% duty cycle clock. This comes out to about 66ns clock width. The native Propeller instructions execute in 50ns. It's possible to use the video generator to produce an SPI data stream faster than that, but you're talking about a small carefully crafted native assembly program to transfer the 9 x 32-bit words needed. The SPI driver in the library is intended for use with slower devices that don't have the timing constraints of the TLC5947.

    Remember that the Propeller does all I/O in software with the exception of video where some things are done in hardware. With a clock speed of 80MHz, native instructions take 50ns. Depending on the memory model you're using, there can be a significant interpretive overhead. Even in-line assembly will only use native instructions if you've enabled caching (see the FAQ for the compiler for details).

    I believe there's an SPI driver in the Propeller Object Exchange that can do 4MHz. I don't think it's designed to have a 50% duty cycle clock and it's written in native assembly code (and Spin) for use with Spin.
  • Andrew BubbleAndrew Bubble Posts: 21
    edited 2014-12-10 10:05
    Hi Mike

    Thanks for the reply and info, and apologies for my ignorance but I assumed there might be a library somewhere similar to the I2C one I am currently using example below.

    i2cOpen(&Dev, scl, sda, ClockSpeed). This has a clock speed parameter which I set to 400 KHz. I don't need a really fast speed and the 4MHz you stated above would be more than sufficient. Do you know what speed the SPI library routines in the Simple IDE run at, I can't find any info on this.

    Also I am very new on the assembler of the Propeller but I am quite proficient using the C language, can you recommend some good reference material for writing assembly within the SimpleIDE.

    Regards Andrew
  • Mike GreenMike Green Posts: 23,101
    edited 2014-12-10 13:02
    The I2C clock speed parameter doesn't quite set the clock speed. There have been several sets of I2C devices over the years. The first allowed clock speeds up to 100KHz. The second allowed clock speeds up to 400KHz. Current devices allow clock speeds up to 1MHz. The ClockSpeed parameter sets the maximum clock speed used for compatibility with slower devices. The actual transmission speed can be less than what's requested. The assembly I2C routines I wrote (for FemtoBasic) operated around 200KHz and could be slowed down for 100KHz devices. Here's (http://obex.parallax.com/object/230) a link for PropComm which runs at 8MHz, but is not SPI ... an example of how to push the effective speed of the Propeller.

    Maybe someone else can chime in on ways to get up to speed using a mixture of C and assembly. Have you any experience with any assembly language or just C?
  • Andrew BubbleAndrew Bubble Posts: 21
    edited 2014-12-10 13:29
    Hi Mike I have experience with assembler Z80, COSMAC 1802 (going back some years) as well as PIC18F series but I have not had any on the Propeller and mostly now use high level languages
  • twm47099twm47099 Posts: 867
    edited 2014-12-10 17:13
    Andrew,
    A few months ago I had a similar question and worked with Andy Lindsay to put together a SPI library for SimpleIDE C. The almost final result is post # 13 in this thread:
    http://forums.parallax.com/showthread.php/157678-C-learning-SPI-example-with-MMA7455-only-gives-values-with-all-bits-set

    Attached to that post is a zip folder that contains the library, the necessary files to include in a project, documentation for the library (in both an HTLM file and in the c and h files), and a couple of example files. The examples are for:
    - DS1620 Digital Thermometer -- libspiasm.c (I need to change that name to something descriptive -- someday)
    - MMA7455 3 axis accelerometer -- mma7455.c

    The method works by using the assembly language routine in the file xSPIAsm.spin (originally SPIAsm.spin from the OBEX with a couple of mods to the assembly language file). xSPIAsm.spin has to be included in the SimpleIDE project list for your program.

    To use this make a folder called MyLibrary under SimpleIDE/Learn/Simple Libraries/ and copy the unzipped folder into it.

    The SPI library should work. My work remaining is to make some examples, make the file names descriptive, and finalize documentation.

    As far as speed goes, the clock setting "clockd_ns" is limited to a minimum of about 300ns (From the spin PASM program, I haven't had a device that goes that fast so I can't test that. So I can't say that this will be as fast as you need.)

    The methods used for developing the PASM library are discussed in this thread:

    http://forums.parallax.com/showthread.php/157441-Can-SPI-in-Simple-Libraries-be-speeded-up

    However, the library attached to post # 66 of that thread is an earlier version, so use the one in post 13 of the first thread. (I have to put the final version in that thread to close it out once its finished.)

    Hope this helps
    Tom
  • Andrew BubbleAndrew Bubble Posts: 21
    edited 2014-12-11 01:39
    Hi Tom, Thanks for the information and I will look at the library and do some testing, as I said earlier I really do not need blistering speed but enough to update all the lights. I really like the Propeller chip and but the lack of high speed libraries like I2C and SPI have made me reluctant to use the chip more often, but the fact that the chip has eight cores and tasks can be easily split between them keeps me interested. Also the likes of Arduino which has a lot of support and if you look at Adafruit concerning their products they always have examples and ready built libraries for the Arduino and Raspberry Pi which means simple test applications can be made quite easily. When it comes to the Propeller then you either have to troll trying to find examples or post questions on this forum. I would like to learn more about the assembly side of things in the future as this may help with a better understanding of the chip.

    Regards Andrew
  • mparkmpark Posts: 1,305
    I needed fast SPI and found this thread. The link in @twm47099's post is broken; here is the correct link: forums.parallax.com/discussion/comment/1297273/#Comment_1297273

    Tom's library is way faster than shift_out & shift_in, so thank you, Tom!
Sign In or Register to comment.