Skip to content

ESP32: 200ms flicker every ~17.9 seconds with RMT driver #1329

@Jueff

Description

@Jueff

I discovered an issue that LEDs have short ~200ms flicker every ~17.9 seconds.
I investigated the problem and it turned out, the it has to do with __clock_cycles(). __clock_cycles() returns a 32bit value, each time the 32bit overrun occurs you see a short LED flicker at all LEDs which values change more then 10 times per second.

The sample project below blinks one LED very fast, if you watch the LED you will see the flickering every 17,9 seconds.

Could the problem be caused in the ESP32RMTController::fillNext method?

if (mLastFill != 0 and now > mLastFill) {

doesn't handle overrun correctly

Code sample for problem reproduction

#include <Arduino.h>

#define FASTLED_INTERNAL       // Disable version number message in FastLED library (looks like an error)
#include <FastLED.h>

const unsigned NUM_OF_LEDS = 256;
CRGB leds[NUM_OF_LEDS];

TaskHandle_t  FASTLedTaskHnd;

void setup() {
    Serial.begin(921600);
    //FastLED.addLeds<WS2812B, 27, EOrder::RBG>(leds, 0, NUM_OF_LEDS);
    CLEDController& controller0 = FastLED.addLeds<NEOPIXEL, 27>(leds+  0, NUM_OF_LEDS);
    controller0.clearLeds(256);
    FastLED.setDither(DISABLE_DITHER);
    
    xTaskCreatePinnedToCore(FASTLedTask,"FASTLed",4096,NULL,1,&FASTLedTaskHnd,0);
}

void FASTLedTask( void * parameter ) {
//--------------------------------
  while(1) {
    yield();
    loopFASTLed();
    delay (1);
  }
}

void loop() 
{
}

auto lastSecond = millis()/1000;

void loopFASTLed()
{
    auto timeBefore = millis();
    leds[0].r = ((timeBefore/30)&0x01)*128;
    FastLED.show();
    auto passedTime = millis() - timeBefore;

    if ((passedTime!=8&&passedTime!=7) || timeBefore/1000!=lastSecond)
    {
      lastSecond = timeBefore/1000;
      Serial.print("millis=");
      Serial.print(timeBefore);
      Serial.print(" cycles=");
      Serial.print(__clock_cycles());
      Serial.print(" show() took ");
      Serial.print(passedTime);
      Serial.println(" ms");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions