Wanted to follow up on the "slowness" I see. I can't seem to get past 2mhz since when I try to write out the bytes for a 110 strand string all the bytes don't all get written out before the lights think there is a "pause" and they should display the bits they got. When I ratchet down to 2mhz, it appears that java can succesfully write out the bytes quick enough.
I am going to set up a C program to see what performance I can get. I was planning on trying bcm2835( http://www.open.com.au/mikem/bcm2835/index.html ) as the interface to the SPI. If I can get 8 mhz then that would be great.
Barnabybear wrote:
16MHz / 3 (parts) = 5.34MHz / 8 (bits) = 0.667MHz or 667 KHz which is just inside (800KHz – 150KHz = 650KHz).
The bit that doesn’t work is. 677Khz = 1500us / 3 (parts) = 500us.
So: T0H 0 code, high voltage time MAX. 450us TYP. 320us would be 500us high, 1000us low.
and T1H 1 code, high voltage time MIN. 600us TYP. 800us would be 1000us high and 500us low.
I'm going to rephrase your logic in consistent units which I understand (ie: saying the same thing another way).
It sounds as if the logic level for a bit is probably sampled about 525 ns after the line goes high; if you can keep it high at least 75 ns later than that, or bring it low at least 75 ns earlier than that, you are guaranteed to get a 1 or 0 respectively. The cycle time should be about 1250ns (range of about 1050-1540 ns). I can picture that.
16 MHz / 8 bits means the output 8 bit register can be reloaded by SPI every 500 ns (2 Msamples / sec). So yes, there's no way you can raise an output and lower it again in 450 ns, using that hardware. They probably have some extra margin in the specs, and your actual pixels might work OK - but by being out of spec a different batch (or the same batch running at a different temperature) might have problems.
(You could fall within the spec at 20 MHz SPI of course)
If it was important, you could use some external hardware to reshape the pulses (eg: delay rise for 100 ns more than fall, so 500 ns high gets transformed to 400 ns high, and 1000 ns high becomes 900 ns.) That would be more circuitry than you want tho.
It would be interesting to test some strings...
Yep – bang on, in you rephrasing. That’s how I see it.
The SPI on the PI can only do multiples of two starting at 250MHz so 16 or 32 are the options. 32 could do it easily but we are really getting out of DIY territory and I would like this project in the sprit of the PI to be, a project that people can make at home and follow the programming (or at least have some insight as to what’s happening).
So if you want to drive 2811/1804 style pixels from an RPi (with minimal external hardware), you can either hope the spec has enough extra timing margin as described above (500 ns high vs 450 ns high for a zero pixel bit), or drive each string serially rather than 8 strings in parallel. Here is some brainstorming on the latter.
You could come pretty close to the spec by driving a 2811 string with 16 spi bits at 16 MHz per pixel bit (pixel bits at 1 Mbps vs 950 Kbps, with cycles of 1000 ns vs 1050 ns). Using 17 SPI bits per pixel bit would be within spec, but requires a lot of extra work to take care of the non-byte boundary bit packing. The spec is less likely to be very sensitive in this direction (how long before the next rising edge), tho - the most critical timing is probably how long after a rising edge the line level gets sampled.
So for example, you could send SPI bits: 11111000 00000000 for a pixel zero and 11111111 11100000 for a pixel one (at 16 MHz). Easy to tweak these timings.
You could use external AND gates to handle multiple strings. Put the SPI output on one input of several AND gates, put individual GPIO bits (or a demultiplexer etc) on the other input of each gate. Enable one (or more) outputs at a time, send the bit patterns out the SPI port.
Doesn't control as many pixels total as the parallel approach, but should be adequate for many purposes.
Note: you could also drive the pixels with 24 SPI bits per pixel bit and still pack bits on byte boundaries (as sent to the SPI output registers). Just add an extra byte of all 0's after each of the patterns above. That would yield a cycle time of 1500 ns (667 Kbps), within spec. Since need to time multiplex multiple strings, I figured you'd want to finish sending to each string as fast as possible (ie: using close to the maximum pixel bit rate), hence the above suggestion of 16 SPI bits per pixel bit.
Ah, it occurs to me that one could make it even simpler, by running the SPI at 8 MHz.
8 MHz SPI bits
Pixel zero: 11100000
Pixel one: 11111000
This does, as above, still push the spec with a 1000 ns vs 1050 ns cycle time.
The RPi only needs to load the SPI output register half as often, and being a little late in loading the next output byte actually moves the timing into spec (with a delay of up to 540 ns anyway).
You could pack two pixel bits into 3 SPI bytes (adding 0000 to each pattern above) if you wanted to be at the lower end of the pixel rate, like the 24 bit variant above.
