I'm currently working with servo motors on the raspberry pi for the first time but ran into some problems recently. I'm able to turn the servo without any problems, however when trying to make it stand still I get some nasty jittering. I've looked online for a solution for quiet some time but didn't find anything that works. I'm using a standard SG90 servo and I power it over a breadboard power unit with constant 5V. I already checked for voltage fluctuations and tried different servos, so I'm pretty sure the problem seems to be the code. I'm a programming noob with only basic understanding of C, therefore I'm having a lot more trouble with servos than I should have, since almost all tutorials online use python coding. Anyways I tried to copy a python code from a website and funnily enough it worked like a charm. No jitter at all. Now I'm wondering how I have to change my C code to achieve a similar result as with python.
The code below shows how I interpreted the controlling of a servo by using PWM. The problem is probably the fact how simplistic the code is. I mean it kinda works. But I have no clue how to get rid of the jitter. I would very much appreciate any kind of advice. Thanks for reading :)
servo code c