# Arduino FreeRTOS Servo problem

**URL:** <https://forums.freertos.org/t/arduino-freertos-servo-problem/6735>\
**Category:** Kernel\
**Created:** [August 13, 2017, 9:57am UTC](https://forums.freertos.org/t/arduino-freertos-servo-problem/6735 "2017-08-13T09:57:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 13, 2017, 9:57am UTC](https://forums.freertos.org/t/arduino-freertos-servo-problem/6735/1 "2017-08-13T09:57:09Z")

</div>

**[adrigt11](https://sourceforge.net/u/adrigt11/)** wrote on [Sunday, August 13, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/371b42ee/#ebf0):

Hello

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

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [August 13, 2017, 4:20pm UTC](https://forums.freertos.org/t/arduino-freertos-servo-problem/6735/2 "2017-08-13T16:20:20Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Sunday, August 13, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/371b42ee/#ebf0/f167):

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.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 13, 2017, 6:24pm UTC](https://forums.freertos.org/t/arduino-freertos-servo-problem/6735/3 "2017-08-13T18:24:26Z")

</div>

**[adrigt11](https://sourceforge.net/u/adrigt11/)** wrote on [Sunday, August 13, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/371b42ee/#be14):

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?

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [August 13, 2017, 10:25pm UTC](https://forums.freertos.org/t/arduino-freertos-servo-problem/6735/4 "2017-08-13T22:25:35Z")

</div>

**[richard\_damon](https://sourceforge.net/u/richard_damon/)** wrote on [Sunday, August 13, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/371b42ee/#a510):

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.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 14, 2017, 1:29pm UTC](https://forums.freertos.org/t/arduino-freertos-servo-problem/6735/5 "2017-08-14T13:29:50Z")

</div>

**[adrigt11](https://sourceforge.net/u/adrigt11/)** wrote on [Monday, August 14, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/371b42ee/#ed6d):

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

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [August 14, 2017, 6:40pm UTC](https://forums.freertos.org/t/arduino-freertos-servo-problem/6735/6 "2017-08-14T18:40:11Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, August 14, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/371b42ee/#ed6d/e109):

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.
