It is hard to have a good real-time behavior on Linux without proper configurations. I would suggest for you to have it running on a vanilla raspbian lite installation (without anything else installed). This usually will give you better results. Also, you can have a more deterministic response if you change the boot arguments to isolate one core (check https://www.linuxtopia.org/online_books/linux_kernel/kernel_configuration/re46.html 😉 and then change main.cpp config file to run the main OpenPLC task on the isolated core. Something like this on the REAL-TIME INITIALIZATION section should do the job:
//Set process affinity to core 1
if (sched_setaffinity(0, sizeof(mask), &mask) < 0)
printf("WARNING: Error setting affinity of main thread\n");
if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) < 0)
printf("WARNING: Error setting thread affinity of main thread\n");
This sample code makes OpenPLC main task run on core 1. If you had isolated a different core on the bootloader, please change the code accordingly, otherwise it will have no effect in improving your real-time behavior.
With those changes in place, I had pretty good results on a Raspberry Pi. A 10ms scan time should be easily achieved, with almost no deviations.