Hello world!

Leds, Leds, Leds, Leds everywhere…! Well, yes, as Noémie said in her last post, we have been working on the ledstrip lately, trying three different methods to light them on: first, we decided to use SPI&DMA. So Noémie worked on it and read millions of pages of doc (cf. her post “Oh my Doc” 😉 !). Then we thought we could more simply control it with one GPIO and a TIMER. But before, we started with the very simple (but not precise enough) method of bit-banging. Then, we attacked the TIMER method (GPT driver and GPIO control in the callback method). The thing is that the duration of the high signal is as short as 0.4us (the total period is 1.25us, so three times 0.4us, making it three bits to send for a ‘1’ or a ‘0’). This required us to use a 168MHz timer and a callback method every 67 cycles, buuuuut…. the callback fucntion Noémie and I wrote was waaaaaay too big. So today Sam helped me to shorten it a bit a whole lot (by the clever idea of preparing one huge buffer containing all ones and zeores to send, so that the callback method would simply read one bit in the buffer every 67 cycles and send it).

You’ll probably not beleive it… but yes! The whole code was in fact useless! Because even with the optimization, the callback took about 42 processor instructions (so 66 with the 2*12 instructions for entering then exiting the interrupt routine). In short, it’s almost impossbile to use this method if we want to control all of the leds on our ribbon.

So: back to SPI! Hopefully Noémie had already done the beginning of the code (thank you ;)!) So, we changed some bugs and made sure the config was correct (APB1 bus->42MHz->prescaler 16->final freq=2,625MHz which is almost equal to 1/(0.4us) = 2.5MHz). Of course, it was far from working at the beginning. We analyzed the signal with the logic analyser and found some incoherences (there were too many zeroes). As I was desperately trying to understand what was wrong, Sam offered his help 🙂 We reviewed the code and figured out that the code for the generation of the buffer was somehow bugged (writing it just before lunch this noon was obviously not such a good idea!!) In short, after correcting these little mistakes, we tested the code on the led and…. guess what:

led2I’m really so happy. So is Noémie 🙂 Now, we’re sure we can use three SPIs (available on our STM32F407) to control three ledstrips with almost no CPU power required (therefore we think of using it for other purposes, for instance helping the nrf with handling the data it receives by BLE, or even doing other funny things we could do with the leds…).

I have written too much, sorry. Now the priority is to finish the PCBs and to catch up with our lateness in BLE!

See you!


1 comment to RoseOnLeds

  • alexandre

    A fourth solution (beside spi, bitbang and gptimer) is to use the integrated dma coupled to a timer.