6 years, 9 months ago.

Timing problem after compiling working mbed program with Segger Embedded Studio

Hello everybody,

I am currently trying to control a Adafruit Neopixel strip with the NRF51 Dongle. I found an easy implementation (RedBearNano_NeoPixels) that works perfectly with my board if I compile the program with the mbed compiler. The correct amount of LEDs can be turned on and with different colors.

I tried using the same code with the NRF SDK (looks like the same because the mbed library contains the same gpio libraries as the SDK ) compiling it on Segger Embedded Studio and get very strange behavior. The LEDs are turned on, but only with white light and I cannot turn them off again or control them in any way. I tried increasing my compiler's optimization level and discovered that with Level 3 optimization it almost works perfectly. It works like with the mbed compiler, but there are intensity changes between the different LEDs.

I think that this is related to a timing problem because of the different compilers, but I do not know how I fix this. I don't know where I can see the compiler settings or if I am completely wrong and the problem is something different.

Would be great if someone could help me.

Cheers!

2 Answers

6 years, 9 months ago.

Because of their timing requirements there are two main ways used to drive WS2812 type LEDs (the parts that Adafruit brand as Neopixels).

Method 1: You can bit bash them, the code manually toggles the IO pin at the correct rate using short loops and other tricks to get the timing right. This is both processor and compiler specific but can be made to work on just about any part with enough messing around to get the timings correct. You must also ensure that all other interrupts are disabled when outputting to the LEDs or things won't work.

Method 2: Use SPI. If you can set an SPI bus to run at 12 MHz then you can use 3 bits of SPI data to send 1 bit of LED data. Ideally you would have an SPI bus that allows you to send 12 or 24 bits at a time, that way each SPI transfer will send 4 or 8 bits of data, anything else could get messy. While this is only possible on parts with a suitable SPI interfaces it is a little more portable and makes it possible to run other interrupts while outputting as long as they don't take too long. Taking a quick look the NRF51 does have SPI but it looks to be limited to 8 MHz and I can't see any controls for setting the transfer size so unfortunately this may not be an option with this part. It may still be possible to make this work, the timing requirements for the LEDs have some wriggle room but I'm not sure.

Accepted Answer

Hey Andy,

thank you very much. I will try what you suggested.

Daniel

posted by Daniel Oliva Jürgens 06 Feb 2018
6 years, 9 months ago.

Daniel,

You are correct. Most of those LED strips require very fast very precise timing. If the timing is done in terms of cycle counts instead of milisecond counts then the timings will be different between compilers as they optimize differently.

-Austin

Hey Austin,

thank you very much for your answer! Good to know that I might be looking into the right direction.

Daniel

posted by Daniel Oliva Jürgens 06 Feb 2018