Skip to content

delay() function doesn't work for less than 10ms #2981

Closed
@ducalex

Description

@ducalex

Hardware:

Board: Lolin32
Core Installation version: d5fdd71
IDE name: IDF component
Flash Frequency: 40Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 8.1

Description:

delay() doesn't work for periods smaller than one tick(10ms) (it is also rounded down if not divisible by 1 tick).

It is a small change but I can create a pull request if it is the proper way to do things also, just tell me.

Sketch: (leave the backquotes for code formatting)

Current code is:
void delay(uint32_t ms)
{
    vTaskDelay(ms / portTICK_PERIOD_MS);
}



//  My suggestion is:
void delay(uint32_t ms)
{
    uint32_t delay_end = millis() + ms;
    vTaskDelay(ms / portTICK_PERIOD_MS);
    while (delay_end > millis()) {
        NOP();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions