Go Down

Topic: PWM Servo library following the writeAnalog API model (Read 973 times) previous topic - next topic

Makuna

My first post!

With my new 2560 I found it had many supported PWM timers.

I wanted to use these PWM timers to drive servos directly.  This will give the project less interupt overhead than the Servo library.

So I followed the API model (and code) for analogWrite() and came up my own library.  The library files and a simple test project are attached for others to enjoy.

The exposed Api is...
Code: [Select]
void pwmServoAttachPin(uint8_t pin, int pwmDutyCycle = pwmServoCenter);
void pwmServoDetachPin(uint8_t pin);
void pwmServoWrite(uint8_t pin, int pwmDutyCycle);


Note that I intentionally left out range checking for the pulses and left this to the application developer.  I am using servos and motor controllers that support a wider range than normal and this would have got in the way.

Michael
p.s.  I am long term hobby AVR programmer but have only owned my Arduino Mega 2560 for a few weeks.

Go Up