start = _getCycleCount(); // get start time of this bit
while (_getCycleCount()-start < t) ; // busy-wait
The function _getCycleCount() returns ccount with is a counter increasing steady from zero to max, but once max is reached it is set to zero again. In the case if start is set to max (or a value almost max) then _getCycleCount()-start will be always smaller than t.
I'd say a fix would be to calculate the cycles to transfer a bit, subtract this value from the max ccount giving the compare value for ccount. And if _getCycleCount() is higher than the compare value just output low until _getCycleCount() is zero again. Keeping the output low for the duration of a very short time (a single bit) should not affect the neopixels at all, according to https://wp.josh.com/2014/05/13/ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/
Or any other idea?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Is there a bug in the souce?
https://github.com/espruino/Espruino/blob/master/libs/neopixel/jswrap_neopixel.c#L246
The function
_getCycleCount()
returns ccount with is a counter increasing steady from zero to max, but once max is reached it is set to zero again. In the case ifstart
is set to max (or a value almost max) then_getCycleCount()-start
will be always smaller thant
.I'd say a fix would be to calculate the cycles to transfer a bit, subtract this value from the max ccount giving the compare value for ccount. And if
_getCycleCount()
is higher than the compare value just output low until_getCycleCount()
is zero again. Keeping the output low for the duration of a very short time (a single bit) should not affect the neopixels at all, according to https://wp.josh.com/2014/05/13/ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/Or any other idea?