For my project we got a pre-installed rpi with all the working libraries and an example program to set a servo in middle position.
The info: in a period of 20ms (50hz) we need 1,5ms to set it to middle position, 2ms to set it to the right, 1ms to set it to the left.
If one would use only softPwm I suppose it would look something like this to set it to the middle:
pinMode(0,output);
digitalWrite(1,LOW);
softPwmCreate(1,0,200);
softPwmWrite(1,185);
But my teacher added: pwmSetClock(500);
And his example program (which doesn't put the servo spot on in the middle but just a little off):
pinMode(0,output);
digitalWrite(1,LOW);
pwmSetClock(500);
softPwmCreate(1,0,500);
softPwmWrite(1,14);
I thought that softPwm uses the 'time off duration' values, so in the example it would mean its off for 486ms? Or did the pwmSetClock(500) change the entire calculation?
Basicly, with these values I would not know how to calculate the values to insert in softPwmWrite() to set the servo to the left or right. The other pwm values (like pwmRange etc) are default as far as I know.
My question: I want to understand how to calculate the value needed for softPwmWrite, to set the pwm to 2ms or 1ms, and how pwmSetClock() changes/affects the calculation. I've been browsing internet for concrete info about this but I can't find any explanations which take pwmSetClock into consideration.