I've noticed my lpd8806 strips running significantly slower than on an arduino. So the max SPI clock rate is 2000 kHz, is there any way I can speed that up?
Any chance of being able to speed up SPI - NP2?
#1
Posted 20 January 2013 - 07:38 PM
#2
Posted 20 January 2013 - 07:56 PM
#3
Posted 20 January 2013 - 08:03 PM
#4
Posted 20 January 2013 - 08:16 PM
The code is very simple right now, and I created the exact pattern on my arduino and it is noticeably slower on the NP2. I've pretty much maxed out my last project using an Atmega 1284p @ 16mHz, so I am in the jump to a better processor to achieve more complex patterns.
public static void LightStripSpi()
{
int i = 0;
var spi = new SPI(new SPI.Configuration(Cpu.Pin.GPIO_NONE,
false, 0, 0, false, true, 2000, SPI.SPI_module.SPI1));
var colors = new byte[3 * 94];
var zeros = new byte[3 * ((32 + 63) / 64)];
byte r = 0;
byte g = 0;
byte b = 0;
byte spin = 0;
while (true)
{
// all pixels off
for (int ix = 0; ix < colors.Length; ++ix) colors[ix] = (byte)(0x80 | 0);
switch (i)
{
case 0: r = 127; b = 0; g = 0; break;
case 1: r = 0; b = 127; g = 0; break;
case 2: r = 0; b = 0; g = 127; break;
case 3: r = 127; b = 0; g = 127; break;
case 4: r = 0; b = 127; g = 127; break;
case 5: r = 127; b = 127; g = 0; break;
case 6: r = 127; b = 127; g = 127; break;
}
for (byte o = 0; o < 94; o+=47){
for (byte e = 0; e < 4; e++)
{
colors[(((o + e + spin) % 94) * 3) + 0] = (byte)(0x80 | r); //blue
colors[(((o + e + spin) % 94) * 3) + 1] = (byte)(0x80 | g); //red
colors[(((o + e + spin) % 94) * 3) + 2] = (byte)(0x80 | ; //green
colors[(((93 - (o + e + spin) % 94)) * 3) + 0] = (byte)(0x80 | r); //blue
colors[(((93 - (o + e + spin) % 94)) * 3) + 1] = (byte)(0x80 | g); //red
colors[(((93 - (o + e + spin) % 94)) * 3) + 2] = (byte)(0x80 | ; //green
}
}
spi.Write(colors);
spi.Write(zeros);
i++;
i %= 7;
spin++; spin %= 94;
}
}
#5
Posted 20 January 2013 - 08:18 PM
#6
Posted 20 January 2013 - 08:24 PM
#7
Posted 20 January 2013 - 08:30 PM
ok, I thought it had to do with SPI, I was hoping the NP2 @ 168mHz even though using .Net would be considerably faster than an Atmega @ 16mHz. Bummer
#8
Posted 20 January 2013 - 08:34 PM
Great job guys on the netduino though! Using Visual C# is next to heaven, too bad there is just too much over head.
#9
Posted 20 January 2013 - 08:49 PM
#10
Posted 20 January 2013 - 08:53 PM
Ok, Ill try that. Thank you
#11
Posted 20 January 2013 - 09:00 PM
#12
Posted 21 January 2013 - 05:30 AM
Hanzibal is right: you should create a byte array in advance, then write it via SPI all at once.
The SPI is blazing fast in any Netduino flavor: is able to transfer data much faster than any Arduino can do. That's simply because the Netduino uses the DMA for achieve the transfer while the Arduino must perform it via software.
Furthermore, your above code can be optimized a lot.
Some hints:
while (true) { //create a template array, then use Array.Copy for fast filling for (int ix = 0; ix < colors.Length; ++ix) colors[ix] = (byte)(0x80 | 0); //use a map instead, where "i" is the pointer switch (i) { case 0: r = 127; b = 0; g = 0; break; case 1: r = 0; b = 127; g = 0; break; case 2: r = 0; b = 0; g = 127; break; case 3: r = 127; b = 0; g = 127; break; case 4: r = 0; b = 127; g = 127; break; case 5: r = 127; b = 127; g = 0; break; case 6: r = 127; b = 127; g = 127; break; } //using "int" is lot faster than "byte" for (byte o = 0; o < 94; o+=47){ for (byte e = 0; e < 4; e++) { //the indexing function can be calculated once only colors[(((o + e + spin) % 94) * 3) + 0] = (byte)(0x80 | r); //blue colors[(((o + e + spin) % 94) * 3) + 1] = (byte)(0x80 | g); //red colors[(((o + e + spin) % 94) * 3) + 2] = (byte)(0x80 | ; //green //same as above colors[(((93 - (o + e + spin) % 94)) * 3) + 0] = (byte)(0x80 | r); //blue colors[(((93 - (o + e + spin) % 94)) * 3) + 1] = (byte)(0x80 | g); //red colors[(((93 - (o + e + spin) % 94)) * 3) + 2] = (byte)(0x80 | ; //green } } //join the array pair in a single one spi.Write(colors); spi.Write(zeros); i++; i %= 7; spin++; spin %= 94; }
Also bear in mind that the SPI clock of 2 MHz is fast enough for most applications. Higher clock rates may lead to bad results/malfunctioning, especially whereas the wiring is long and/or noise is relevant.
#13
Posted 21 January 2013 - 08:47 AM
That's simply because the Netduino uses the DMA for achieve the transferUnfortunately, the current implementation of SPI does not use DMA. AFAIK it is planned for Netduino Go (GoBus SPI transport), so hopefully it will be available on other STM32-based boards too.
#14
Posted 21 January 2013 - 11:15 AM
Fyi; I wrote a driver for those strips which is pretty fast;
http://netmftoolbox....are.RgbLedStrip
Maybe you can be inspired by it?
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users