Im using servoblaster in pcm mode and setting pulsewidth from code for turning my servos position to desired angle. But my question is, cant i use it for controlling the speed of dc motor. I read some recommended pigpio for this purpose. But is it not possible with servoblaster?
2 Answers
You can control the speed of a standard DC motor using PWM.
PWM works my splitting each second into many time slots. The number of time slots per second is the PWM frequency. During each time slot the signal will be high then low. The percentage of the time slot that the signal is high is the PWM duty cycle. It's a gross simplification but for the sake of argument full speed is a 100% duty cycle, half speed is a 50% duty cycle, etc.
Servoblaster generates servo signals. These have a PWM frequency of 50Hz. So each time slot is 20 milliseconds long. Servos typically accept signals in the range 1 to 2 milliseconds long. That is roughly the range which servoblaster will output. That means you can vary the dutycycle between 5-10%. I doubt that will be enough to even start a DC motor turning.
You really need to be using a proper PWM generator.
My pigpio will generate servo signals and PWM signals. pigpio is pre-installed with recent versions of Raspbian.
-
Good explanation. Quick questions: what is the duty cycle range of pigpio? Will it work if i need 1 servo + 2 motors + speakers connected together?– RaspiFanDec 8, 2018 at 11:27
-
pigpio allows 0-100% for general PWM and 2.5-12.5% for servos. Yes you can drive servos and multiple motors simultaneously. You can also use speakers at the same time.– joanDec 8, 2018 at 12:00
-
Exploring servoblaster, i found its maximum pulse width is 20000 us and default range can be changed by setting min and max width params. It solved me the problem of driving motors. It works.– RaspiFanDec 9, 2018 at 12:56
-
@RaspiFan If you get time could you create an answer with what you did, That would help others with the same problem.– joanDec 9, 2018 at 13:13
Found the default cycle time in servoblaster is 20000 us but the default min and max width is restricted to 500 us to 2500 us to protect servos. Changed the default value from 0us to 20000us that solved the problem with motors.
Refer https://github.com/richardghirst/PiBits/blob/master/ServoBlaster/README.txt