Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added delay to ensure reset time being met with low led counts (ws2813) #157

Merged
merged 2 commits into from
Jun 1, 2017
Merged

Added delay to ensure reset time being met with low led counts (ws2813) #157

merged 2 commits into from
Jun 1, 2017

Conversation

sschroe
Copy link
Contributor

@sschroe sschroe commented Feb 26, 2017

This aims to add a delay for the ws2813 protocol reset time to be met. As already mentioned in #152 this only is an issue when there is very few leds connected/used and leads to random flickering etc.

From what i could tell the library so far was not enforcing the reset delay at all (or i just missed that part somewhere...), though it rarely is an issue as pretty much none of the ws2812 leds really require 50µs and usually are fine with just 10µs already.

To do this i calculate the theoretical time it takes for the protocol (~1.25µs per bit) to set all leds plus 300µs added on top of it to leave enough room for the reset on ws2813 leds. In the following render calls it is then checked if enough time has already elapsed and if not an usleep with the remainder is done. I didn't add extra handling for timestamp overflows as it should occur only rarely and even then won't be too much of an issue.

It could of course also be done with just a fixed delay for ws2813 but i wanted to avoid adding even more strip types only for that. Though i'm not sure if this solution is really good either. Feedback and tests are welcome.

@jgarff
Copy link
Owner

jgarff commented May 20, 2017

Thanks for the pull request. Just a minor comment, could you change the 300uS hard coded value in the code to a definition somewhere? Also, please rebase to the tip of master as well. The current pull request has merge conflicts. Thanks.

@sschroe
Copy link
Contributor Author

sschroe commented May 22, 2017

Added a define for the wait time and updated to current master.

@jgarff jgarff merged commit 6c0f4db into jgarff:master Jun 1, 2017
@sschroe sschroe deleted the ws2813_reset_time branch June 1, 2017 07:22
jgarff pushed a commit that referenced this pull request Jul 6, 2017
* Pi Zero W v1.1 support added to rpihw.c

* Update rpihw.c (#164)

added raspi Zero W

* Device-tree auto-detect

* Channel gamma support

* Reverted to old detection, added 0x9200c1

* Changed gamma correction to match leds

* Removed dead dt detect code

* Re added "Pi Zero W v1.1", .hwver = 0x9000c1, (#181)

* Added PCM and SPI support. Specifying the corresponding GPIO pin will (#170)

select either PWM, PCM or SPI.
PCM and SPI only support 1 channel.
Increased version to 1.1.0.
Updated README.md

* Fix setting of brightness in go bindings (#174)

Fixes #151

* Added delay to ensure reset time being met with low led counts (#157)

* Fix includes as per #178 (#189)

* clean up doco and strandtest (#187)

* updated documentation on GPIO usage
strandtest now defaults to GRB colour order
added version.h to gitignore

* updated python readme

* more README cleanup

* added notes on spi max transfer size
brindosch pushed a commit to hyperion-project/rpi_ws281x that referenced this pull request Apr 5, 2018
* Added delay to ensure reset time being met with low led counts (jgarff#157)

* Fix includes as per jgarff#178 (jgarff#189)

* clean up doco and strandtest (jgarff#187)

* updated documentation on GPIO usage
strandtest now defaults to GRB colour order
added version.h to gitignore

* updated python readme

* more README cleanup

* added notes on spi max transfer size

* Fix freeze after running for long time  (jgarff#197)

* Whitespace cleanup

* Move channel_protocol_time so it handles 32 bit Color LEDs.

* Fix a freezing issue when running for a long time.

When current_timestamp overflowed 2^64, rolling back to 0 and ws2811->render_wait_until had not, this caused an incredibly long usleep in ws2811_render.

* Update README.md (jgarff#191)

* Update README.md

* updated spi buffer size location

* Add -lrt link flag for systems with older glibc (jgarff#195)

* Fix 32-bit overflow in get_microsecond_timestamp(). (jgarff#206)

On Raspbian systems, the tv_sec member of struct timespec is 32 bits
wide.  get_microsecond_timestamp() was overflowing in 32-bit
arithmetic on this member.  This causes the time that it returns to
jump ahead by many thousands of years at uptime = 35 minutes, 48
seconds.  (While the starting point for CLOCK_MONOTONIC_RAW is
unspecified, it seems to track system uptime in practice.)

This overflow didn't cause noticeable problems for me--ws2811_render()
skips the sleep when it thinks such a huge amount time has
elapsed--but it could possibly result in rarely-occurring skipped
frames if the WS2811 reset time isn't effectively honored by
ws2811_render().

* Add TOOLCHAIN option for cross compilation (jgarff#213)

Use this option if you want to cross-compile the library.
Typical usage is:

  scons TOOLCHAIN=arm-linux-gnueabihf

* Add -Wextra compile option and adapt code to suppress warnings (jgarff#214)

The changes in code are mostly type casts between int ann unsigned.

* Add shared library rasbpian package builder.  The package is not built by
default.  To generate the package you need:

- The dpkg-deb utility.
- Use "scons deb" to generate the package.

* Merge user-settable gamma correction into master (jgarff#216)

Merge user-settable gamma correction into master

* Bug fixes for Stretch and Compute Module support (jgarff#222)

* Bug fixes

Missing aligned(4) attribute in pcm.h makes the PCM case failing under
Stretch, due to a newer version of gcc (6.x).
Also fixed a bug in check_hwver_and_gpionum, so original Model A is
recognised.

* README, using SPI on RPi3

Added note to change the core frequency to 250 MHz when using SPI on
RPi 3.

* README fix

* Add support for Compute Module 1 and 3

* Fix undefined clock_gettime symbol

* add missing memory allocation for SPI mode (jgarff#231)

* added Ctrl-C handler to turn off all LEDs on exit (jgarff#140)

* added Ctrl-C handler to turn off all LEDs on exit

* added option -c

* Fix for segmentation fault on exit for Python API (jgarff#239)

Remove useless __del__ because the cleanup() function gets called by
atexit().
Remove ws.ws2811_fini() call which causes the SEGFAULT on exit.
Python does not complain about the memory leak in this way.

* Add support for new A+ hardware.

* Change default DMA channel to safe choice (10) (jgarff#253)

add warning on README.md

* Add getBrightness for brightness feedback from the buffer (jgarff#248)

* Instructions to install the Python library (jgarff#254)

Solving issue jgarff#142

* Fix for non-root users & SPI (jgarff#257)

* Fix for non-root users can use SPI

* use DEFINE'd device strings

also add a note to the readme

* Basic Golang Examples (jgarff#256)

* Added golang example

* Added basic README for golang examples. Added os exits for errors during color wipes for golang examples

* Fix the default DMA in python code (jgarff#266)

DMA 5 causes file system errors on PI 3

* Fixed typo in README.md (jgarff#273)

Was perusing recent commits and saw this.

* clarify electrical notes (jgarff#264)

* Fixed strandtest.py (jgarff#258)

* Fixed keyboardinterrupt, indentation inconsistency, & a few other minor bugs.  Added shebang.

* Fixed KeyboardInterrupt.  Again.

* KeyboardInterrupt works now.  For sure.

* Tabs to spaces, removed redundant signal handling

* Removed unused sys module import

* Added Raspberry Pi 3 B+ (jgarff#276)

* Added Pi 3 B+

* Remove unused import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants