I am still messing with the idea of multiplexing the output of the SPI. Further testing shows that from java I can drive at 2mhz, not the 4 mhz that I originally thought. Looks like a C program would be faster. I did get the prototype of 16 outputs using a java program and a couple of chips(ADG726, and a line driver)
Here is the prototype circuit. Note: This could also be done with 2 x 74hc4514.
Code:
package test.test2;
import java.util.Random;
import com.pi4j.wiringpi.Gpio;
import com.pi4j.wiringpi.Spi;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
public class App {
public static void main(String[] args) {
// System.out.println("Out:" + Spi.wiringPiSPISetup(0, 500000));//
// 1mhz=1000000
System.out.println("Out:" + Spi.wiringPiSPISetup(0, 2000000));// 1mhz=1000000
System.out.println("Out:" + Gpio.wiringPiSetupSys());
final GpioController gpio = GpioFactory.getInstance();
final GpioPinDigitalOutput pin1 = gpio.provisionDigitalOutputPin(
RaspiPin.GPIO_08, "MyLED", PinState.LOW);
final GpioPinDigitalOutput pin2 = gpio.provisionDigitalOutputPin(
RaspiPin.GPIO_09, "MyLED", PinState.LOW);
final GpioPinDigitalOutput pin3 = gpio.provisionDigitalOutputPin(
RaspiPin.GPIO_07, "MyLED", PinState.LOW);
final GpioPinDigitalOutput pin4 = gpio.provisionDigitalOutputPin(
RaspiPin.GPIO_00, "MyLED", PinState.LOW);
final GpioPinDigitalOutput pin5_en = gpio.provisionDigitalOutputPin(
RaspiPin.GPIO_03, "MyLED", PinState.LOW);
int num_leds = 110;
try {
// Using a file vs wiringPi:
//
// FileOutputStream fos = new FileOutputStream(new
// File("/dev/spidev0.0"));
// fos.write(colors);
// fos.flush(); //limited success with this
Random randomGenerator = new Random();
byte[] colors = new byte[num_leds * 3];
int colorToUse1 = randomGenerator.nextInt(255);
int colorToUse2 = randomGenerator.nextInt(255);
int colorToUse3 = randomGenerator.nextInt(255);
int loc = 0;
long startTimeMillis = System.currentTimeMillis();
for (int j = 0; j < num_leds; j = j + 1) {
// System.out.println("j:" + j);
pin5_en.high(); //force the chip to switch to no outputs
pin1.high();
pin2.high();
pin3.low();
pin4.low();
pin5_en.low(); // force the chip to switch on output per truth table
for (int i = 0; i < num_leds * 3; i = i + 3) {
colors = (byte) 0;
colors[i + 1] = (byte) 0;
colors[i + 2] = (byte) 0;
}
colors[j * 3] = (byte) colorToUse1;
colors[j * 3 + 1] = (byte) colorToUse2;
colors[j * 3 + 2] = (byte) colorToUse3;
Spi.wiringPiSPIDataRW(0, colors, colors.length);
Gpio.delayMicroseconds(600); // need to determine
Thread.sleep(150);
}
System.out.println("Elapsed:"
+ (System.currentTimeMillis() - startTimeMillis));
} catch (Exception e) {
e.printStackTrace();
}
}
}
Barnabybear wrote:
So, off hand, the first section of data required by the 3001s is 15 '1's then 4 'data' - making a 19 bit write to a single string.
To do that the PI would write to the shift register:
The byte x\ff 15 times then the byte x\data 4 times to give a 19 bit write to each of 8 strings.
I don't see the manchester encoding of bits in that description. Not a huge deal, but in addition to the manchester encoding logic, you will need to double your data rate (ie: put out two SPI outputs for each TLS3001 bit time). So if you want to send bits at 400 Kbps (for each of 8 lines), you need to update at 800 Ksps (samples/sec). That is, you have to output two spi bits (per each of the 8 lines) for every TLS3001 Manchester Encoded data bits. Just a heads up; you can accommodate this in your scheme.
Still following with interest.Hadn't come across CISECO before, they've got some interesting products.
While I was searching I also came across this company who are also in your neck of the woods
http://www.pridopia.co.uk/ixx-rspi.html
They have some very interesting I2C & SPI RPI boards, some still in development!
Hi Mike, good to know your still around.
I am still messing with the idea of multiplexing the output of the SPI. Further testing shows that from java I can drive at 2mhz, not the 4 mhz that I originally thought. Looks like a C program would be faster. I did get the prototype of 16 outputs using a java program and a couple of chips(ADG726, and a line driver)
Hi snunn, keep up the good work, you’ll get there. I’m sort of following you code (not a Java man).
Just a thought, but could this delay be messing you up at higher SPI speeds?
Spi.wiringPiSPIDataRW(0, colors, colors.length);
Gpio.delayMicroseconds(600); // need to determine
Thread.sleep(150);
I'm thinking C may be the way to go - but that means I've got to learn it and I've only just filled my head with Python (both 2.7 & 3.x) 🙁 Oh well I'm sure a few beers will make some space up there.
I don't see the manchester encoding of bits in that description. Not a huge deal, but in addition to the manchester encoding logic, you will need to double your data rate (ie: put out two SPI outputs for each TLS3001 bit time). So if you want to send bits at 400 Kbps (for each of 8 lines), you need to update at 800 Ksps (samples/sec). That is, you have to output two spi bits (per each of the 8 lines) for every TLS3001 Manchester Encoded data bits. Just a heads up; you can accommodate this in your scheme.
Hi Zeph, yep completely forgot about the encoding when I typed the reply. I looked at it sometime ago to see if it would be possible with this setup, decided it would and then forgot about it.
But, yes it’s just a double write to them for each bit. Python has a nice ‘Bitwise Operator’.
If a= 0011 1100 then ~a =1100 0011 Which will do the job nicely.
(Binary Ones Complement Operator is unary and has the effect of 'flipping' bits).
The fun one will be 2811s. This will need to be a triple write to send each bit.
First section, high. Second section, high or low (dependant on bit sent). Third section, low.
From the data sheet:
6. High speed mode time( TH+TL=800KHz±150KHZ)
T0H 0 code, high voltage time MAX. 450us TYP. 320us
T1H 1 code, high voltage time MIN. 600us TYP. 800us
So 1 bit needs to written at 800KHz (or 0.8MHz)
8 bits need to be written at 0.8MHz x 8 (bits) = 6.4MHz
I need to send 3 parts to each bit.
So 6.4MHz x 3 (parts) = 19.2 MHz. But the SPI can’t do that the closest it can do is 16MHz.
To reverse the process:
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.
That asks the questions:
How flexible is the timing on the 2811s? And How fast can I get the SPI to work reliably? And with this stinking cold can I think streight enough to have typed this right?
I've not had chance to solder the board up yet - if this cold holds out it may be the some time over the weekend before I get it done and tested.
Hope some or all of this makes sence - feel free to comment, particialy if you have tested the timing on 2811s.
For some reason I didnt paste the last part of the 2811 text.
If I only write to 6 strings (i.e. do a 6 bit SPI write, if that is possable). It drops the 500us down to 375us.
That equates to a 375us '0', 750us '1' and a total length of 1125us. That should be close enough.
Hi all, finaly seem to be shaking off this cold.
Looked a little into C and PI coding and ordered 2 cases for my PIs.
You've got to love perspex or plexiglass (I think is the US name).
http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=251220595424
I thought if the lid was longer on the connector side we could get some holes in there for cable tying the output cables.
So I've got soldering - cuting and trimming - then programming - and testing to do this weekend 🙂

