I’m using the FreeRTOS in an Arduino Mega and I want to control some Servos using task for each servo. All is working good but I notice that very often the Servos make strange movements because the PWM signal is not good. I tested a similar code but without the FreeRTOS and there aren’t any strange movements on the Servos.
I think that there is a conflict within the FreeRTOS and the Interrupts that controll de PWM siganl of the Servos.
I think the AVR part and therefore the RTOS port are quite simple, and
interrupt nesting is not supported. I suspect your PWM signal is quite
high frequency and the RTOS tick could be adding jitter into its timing
just a guess. Making the RTOS tick slower (configTICK_RATE_HZ) would
lessen but not remove that issue.
Is the Servo PWM being generated by built in hardware, or by software toggling a bit? 50 Hz is 20ms period, so even a 1ms disturbance is 5% of the signal. Even a much smaller disturbance can make a significant ‘kick’ to the servo. If you are generating it with a precisely timed interrupt to a ISR that is toggling the bit, that interrupt must not be blocked for any significant time for any reason. If you can not get that interrupt to interrupt the tick interrupt, you are going to have problems.
That port does not support interrupt nesting, so even if you didn’t
disable the servo interrupt, I’m not sure how the system would behave.
If the servo interrupt is not using any FreeRTOS functions then it might
work, but I would have to study the code to know for sure.