I'm using a RTOS distribution on an ARM embedded device. Currently i'm in need of toggling a signal like this
GPIO_Write(PIN_1, LOW);
vTaskDelay(msec_to_ticks(1));
GPIO_Write(PIN_1, HIGH);
vTaskDelay(msec_to_ticks(1));
GPIO_Write(PIN_1, LOW);
vTaskDelay(msec_to_ticks(3));
GPIO_Write(PIN_1, HIGH);
if (option1){
vTaskDelay(msec_to_ticks(3));
GPIO_Write(PIN_1, LOW);
vTaskDelay(msec_to_ticks(1));
} else {
vTaskDelay(msec_to_ticks(1));
GPIO_Write(PIN_1, LOW);
vTaskDelay(msec_to_ticks(3));
}
GPIO_Write(PIN_1, HIGH);
if (option2){
vTaskDelay(msec_to_ticks(3));
GPIO_Write(PIN_1, LOW);
vTaskDelay(msec_to_ticks(1));
} else {
vTaskDelay(msec_to_ticks(1));
GPIO_Write(PIN_1, LOW);
vTaskDelay(msec_to_ticks(3));
}
GPIO_Write(PIN_1, HIGH);
vTaskDelay(msec_to_ticks(3));
GPIO_Write(PIN_1, LOW);
What i noticed is that based on where and when i call this function (separate thread/task) the signal can be completely wrong (1-2ms off sometimes).
I'm wondering if using taskENTER_CRITICAL() and taskEXIT_CRITICAL can help me to ensure a somewhat accurate signal.
One idea i have is that interrupts with higher priority may kick in and delay the code somewhere (although i've set max priority on the task). The other one is that the timings are correct but GPIO_Write is not taking place immediately.
Any other idea on how can i ensure the code is not interrupted?
Regards,