Incorrect Timer period and stops after some time

Hello all, Just starting with FreeRTOS and Arduino (Mega2560). I created a simple program to blink two LED, Green every 5 sec Blue turn on after 500ms Behaviour i got: -Blue turns on. -Green blink but what seems like every 1 second -After a minute Green is stuck at On and BLue starts blinking help is appreciated thanks ~~~ #include <Arduino_FreeRTOS.h>

include “timers.h”

include <Arduino.h>

define ONESHOTTIMERPERIOD (pdMSTO_TICKS(500))

define AUTORELOADTIMERPERIOD (pdMSTO_TICKS(5000))

int blueLedPin = 13, greenLedPin = 11; const uint8t *blueLed = (uint8t *)&blueLedPin; const uint8_t *greenLed = (uint8_t *)&greenLedPin; TimerHandlet xOneShotTimer; TimerHandlet xAutoReloadTimer; BaseTypet xOneShotTimerStarted; BaseTypet xAutoReloadTimerStarted; void prvOneShotTimerCallback(TimerHandlet xTimer); void prvAutoReloadTimerCallback(TimerHandlet xTimer); void setup() { Serial.begin(115200); Serial.println(“Setup “);
pinMode(blueLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);


xOneShotTimer = xTimerCreate("One Shot",
                                    ONE_SHOT_TIMER_PERIOD,
                                    pdFALSE,
                                    (void *)0,
                                    prvOneShotTimerCallback
                                    );
xAutoReloadTimer = xTimerCreate("Auto Reload",
                                        AUTO_RELOAD_TIMER_PERIOD,
                                        pdTRUE,
                                        (void *)0,
                                        prvAutoReloadTimerCallback
                                        );


if ((xOneShotTimer != NULL) && (xAutoReloadTimer != NULL))
{
    xOneShotTimerStarted = xTimerStart(xOneShotTimer, 0);
    xAutoReloadTimerStarted = xTimerStart(xAutoReloadTimer, 0);
}

while ((xOneShotTimerStarted != pdPASS) && (xAutoReloadTimerStarted != pdPASS)){}
vTaskStartScheduler();
Serial.println("end");
} void prvOneShotTimerCallback(TimerHandlet xTimer) { TickTypet xTimerNow; xTimerNow = xTaskGetTickCount(); Serial.print(“One-shot timer : “); Serial.println(xTimerNow); digitalWrite(blueLedPin, digitalRead(blueLedPin) ^ 1); } void prvAutoReloadTimerCallback(TimerHandlet xTimer) { TickTypet xTimerNow; xTimerNow = xTaskGetTickCount(); Serial.print(“Auto- Reload timer : “); Serial.println(xTimerNow); digitalWrite(greenLedPin, digitalRead(greenLedPin) ^ 1); } void loop(){} ` ~~~

Incorrect Timer period and stops after some time

I don’t know how the Arduino port works, or really how Arduino works, but there is nothing obviously wrong with your code. Is the LED used by any other code? Maybe the unexpected flashing pattern is controlled by something else – an error handler for example. Look though the following list for the normal options, such as ensuring you don’t have stack overflow, you do have asserts defined, etc. In this case it is the timer task stack that is of interest as the timer callbacks both execute in the context of the timer task (which is also why it is ok to access the serial port from both as they will never interrupt each other). https://www.freertos.org/FAQHelp.html

Incorrect Timer period and stops after some time

Thanks Richard Looks like i got some reading to do

Incorrect Timer period and stops after some time

follow up question. Since Timer are executed by TimerTask, then will it be same if i have two taks, one with 1/2 sec and one with 5 sec delay using vTaskDelay instead of two timer?

Incorrect Timer period and stops after some time

Will what be the same?