Hello!
I'm trying to run code work of what has a duration about several seconds.
And the problem is that it's only work in continuous manner (if it launched in loop section):
void loop() {
activation_sequence();
}
But I need to run it only once, for example, in setup section like this:
When I try to run it like in the last example, work of the function "activation_sequnce" is broken after some milliseconds, far before end of function, and the following after call of function line of code is executed.
I need this function to be executed fully before execution of following call of this function instruction. How to reach this?
I suppose that the causes are some timeouts or watchdogs and they should be increased. Or blocking call of function should be used. But I don't know how to do this.
Try inserting short delays (e.g.., 1 microsecond) in your while loops to allow the thread to yield control. You may be timing out the watchdog. Keep the serial monitor open while you run the program and it will show the error call stack if your watchdog is resetting.
If you're using the arduino framework, IIRC you can't avoid starting the watchdog and typically they can't be turned off after starting.
I don't think it's wise to attempt to get that level of timing accuracy from busy loops when running with an RTOS. My experience tells me that you'll get very jittery timing. Unfortunately, I haven't used ESP32 enough to know how all its timer functions work, but that would be the right approach.