Arduino FreeRTOS Servo problem

adrigt11 wrote on Sunday, August 13, 2017:


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.

Can anyone help me?

Thanks a lot

rtel wrote on Sunday, August 13, 2017:

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.

adrigt11 wrote on Sunday, August 13, 2017:

The PWM signal is 50Hz to controll the Servo, is not very high frequency. Are you saying that I can modifie de configTICK_RATE_HZ to improve that?

richard_damon wrote on Sunday, August 13, 2017:

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.

adrigt11 wrote on Monday, August 14, 2017:

The PWM signal being generated by the Servo library by ISR. How can I not block the interrupt for the Servos in FreeRTOS?

rtel wrote on Monday, August 14, 2017:

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.