STM32F103 - Timer Innaccuracies - Driving A Servo And The Servo Is Twitching
Hello, I am using an STM32F103C8T module (blue pill). I am using it to control a servo, which consists of a 20ms window, with a short pulse (1.0ms to 2.0ms). Like this:
I configured timer 3 like this in CubeMX:
I am using "HAL_TIM_PeriodElapsedCallback", and here is the code that is driving the servo:
Everything works for the most part, but the problem is the servo has a slight twitch to it. It twitches fairly consistently about 2 times per second. I connected the oscilliscope to watch the pulse. I can see that the pulse width is not consistant - it has some variance to it:
https://photos.app.goo.gl/2zXpNaN92md5mdMA6
And here I zoomed in on the end of the pulse - you can see it much more clearly:
https://photos.app.goo.gl/2r8uzPqeje9sbSNZ7
Because of the inconsistent width of the pulse, it causes the servo to twitch - basically following the pulse exactly. Here is a video of that:
https://photos.app.goo.gl/eS6NtWFbSuUNP6SJA
Does anyone know what the problem is? My servo driver code is extremely simple and I can't see anything wrong with it. Do I have the timer setup incorrectly, or is it something else? Any help or advice is greatly appreciated, thanks!
