Skip to content

Fix with PWM for brightness slowing devices down #6894

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

Merged
merged 1 commit into from
Sep 12, 2022

Conversation

gamblor21
Copy link
Member

Fix for CircuitPython v8.0.0-beta.2: display_shapes.polygon color fill is rendering very slowly

#6734 removed support for auto brightness left a call in displayio_display_background to set the brightness to a 1.0f fixed value. In the previous code another function call checked that auto-brightness was set to True and skipped any work if it was not true and limited to how often the brightness was set.

With the previous PR always calling common_hal_displayio_display_set_brightness to 1.0f it was both preventing the brightness from being set (using the same auto-brightness behavior that no longer exists) and having to change the PWMOut object was slow the lower the frequency of the PWM timer. Most boards with built in displays were set to 50KHz so it was barely noticeable. The Titano was set to 500Hz so the problem became apparent. But there is a measurable speed-up even when the frequency was set to the higher value.

This PR does not fix the brightness from not being set properly. This would be one source of error but apparently others exist still.

But this PR does fix a slowdown with any board using PWM to control the display brightness.

@tlyu
Copy link

tlyu commented Sep 12, 2022

I was just reading through all of that code today and eyeing with suspicion that unconditional call in displayio_display_background, which seems to run every time the displayio background task runs, which might be more often than the refresh rate. I was wondering if the PWM update blocks for until the end of the current PWM cycle…

@dhalbert
Copy link
Collaborator

dhalbert commented Sep 12, 2022

I wonder if this is also going to fix #6838. It certainly looks like it!

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!

@dhalbert dhalbert merged commit 5a053f9 into adafruit:main Sep 12, 2022
@CedarGroveStudios
Copy link

I’m beginning to suspect that since disabling auto refresh restores the ability to control brightness, the SAMD51 TCC timer used for the display backlight PWM is shared with the display auto refresh timing somehow.

@dhalbert
Copy link
Collaborator

dhalbert commented Sep 12, 2022

To check #6838, I tested with a Feather ESP32-S3 TFT with this fix. Now the display is dark until the brightness is set explicitly, but the brightness can now be controlled. I don't think this is a timer issue; the code that @gamblor21 removed forced the brightness to 1.0 on every refresh. But now there's a newly exposed bug that the brightness is not set correctly on initial startup.

@tlyu
Copy link

tlyu commented Sep 12, 2022

I’m beginning to suspect that since disabling auto refresh restores the ability to control brightness, the SAMD51 TCC timer used for the display backlight PWM is shared with the display auto refresh timing somehow.

I think this is not the case, given observations by @gamblor21 in adafruit/Adafruit_CircuitPython_Display_Shapes#57 that creating an independent PWM object does not cause the same delays. I think it's more likely that unconditionally updating the PWM object on each displayio background update task caused a delay that was dependent on the PWM frequency, possibly by blocking until the end of a PWM cycle. (In theory, this might slow down any lengthy computation, not just the Triangle object creation.)

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.

4 participants