Search code examples
arduinofreertos

FreeRTOS Arduino MEGA 2560 vTaskDelay() not working


I have an Arduino MEGA 2560 running a FreeRTOS sketch using Arduino_FreeRtos. Everything appears to be working correctly except for vTaskDelay functions. Below is one of the areas I am having an issue.

    taskENTER_CRITICAL();
    MOTORS[5].motor(1, 120);
    MOTORS[6].motor(1, 127);
    taskEXIT_CRITICAL();
    vTaskDelay(pdMS_TO_TICKS(9000));
    taskENTER_CRITICAL();
    MOTORS[5].motor(1, 0);
    MOTORS[6].motor(1, 0);
    taskEXIT_CRITICAL();

The first task critical section starts moving my motor forward. There is supposed to be a 9 second delay and then the motor is supposed to stop in the second task critical section. What is actually happening is the motor moves forward for ~1 second and then stops.

I do have INCLUDE_vTaskDelay enabled in the FreeRTOSConfig.h file. enter image description here

What else can I look at to try and find out why vTaskDelay is not working?


Below is the definition for the clock. Per comment that the clock may not be correct. I can't decipher if the clock is correct or not. Hopefully someone can point out if this setting may be causing the issue. enter image description here


Solution

  • The I think the problem is that 128000 >> (portUSE_WDTO + 11) is probably 0 (unless portUSE_WDTO is negative). In order to get the correct timings you need to check that the tick rate is as expected (30ms). This is unlikely to be the case at the moment.