need 5 pwm and servo :(

hi, i a doing a project on a mini pro board, i need 5 pwm output and 2 servo, sadly using servo.h disable 9 and 10 pins so there is is only 4 pwm outputs left :frowning:
i tried to used softwareservo.h which seems to keep 9 and 10 pins available for pwm but impossible to compile :

C:\Users\victor\Documents\arduino-1.0.3\libraries\SoftwareServo\SoftwareServo.cpp: In member function 'uint8_t SoftwareServo::attach(int)':
C:\Users\victor\Documents\arduino-1.0.3\libraries\SoftwareServo\SoftwareServo.cpp:27: error: 'digitalWrite' was not declared in this scope
C:\Users\victor\Documents\arduino-1.0.3\libraries\SoftwareServo\SoftwareServo.cpp:28: error: 'OUTPUT' was not declared in this scope
C:\Users\victor\Documents\arduino-1.0.3\libraries\SoftwareServo\SoftwareServo.cpp:28: error: 'pinMode' was not declared in this scope
C:\Users\victor\Documents\arduino-1.0.3\libraries\SoftwareServo\SoftwareServo.cpp: In member function 'void SoftwareServo::write(int)':
C:\Users\victor\Documents\arduino-1.0.3\libraries\SoftwareServo\SoftwareServo.cpp:51: error: 'clockCyclesPerMicrosecond' was not declared in this scope
C:\Users\victor\Documents\arduino-1.0.3\libraries\SoftwareServo\SoftwareServo.cpp: In static member function 'static void SoftwareServo::refresh()':
C:\Users\victor\Documents\arduino-1.0.3\libraries\SoftwareServo\SoftwareServo.cpp:73: error: 'millis' was not declared in this scope
C:\Users\victor\Documents\arduino-1.0.3\libraries\SoftwareServo\SoftwareServo.cpp:106: error: 'digitalWrite' was not declared in this scope
C:\Users\victor\Documents\arduino-1.0.3\libraries\SoftwareServo\SoftwareServo.cpp:108: error: 'TCNT0' was not declared in this scope
C:\Users\victor\Documents\arduino-1.0.3\libraries\SoftwareServo\SoftwareServo.cpp:123: error: 'digitalWrite' was not declared in this scope

any ideas on how to run 2 servos and keeps pins 9 and 10 alive?
a good solutions could be to edit servo.h library to keep 9 10 pins enable ut i dont even know if it’s possible…
thanks for any of your ideas

EDIT: i found the problem for compiling but this library seems to be “heavy to use” needs refresh every 50 ms and some parameters…not really my best choice :slight_smile:

I am not sure if this is the answer, but try

#include "Arduino.h"

at the top of your sketch

Servos require a constant waveform of between 20 and 50Hz with a pulse width in the region of 1 to 2ms.

Obviously the “lightest” way to produce that waveform is to use the PWM hardware in the chip - but you want to use that for other things, so that’s out.

That only leaves software.

And for a 20Hz waveform, that’s 1/20 = 50ms period, divided by the resolution you want (minimum 1ms resolution, which would give you 0° and 180°, pretty pointless).

The best software solution is a timer based routine which is called every 50ms and outputs a pulse of the desired width. The routine would run for between 1ms and 2ms depending on the angle you want, so would consume at worst 4% of your total CPU time.

I don’t know (as I haven’t looked), but I would hope that’s how the SoftwareServo would work.