[urgent] Can UNO support servo and pwm at the same time?

I use pin 8 as servo, pin 9 as pwm output.
However, pin 9 doesn't work as long as I use pin 8 as servo.
It works again only if I don't use servo.

I just searched, servo interferes the functionality of pwm.
"On the Mega, up to 12 servos can be used without interfering with PWM functionality"
But how about UNO???
Can UNO uses any servo without interfering with PWM functionality?

I don't wanna buy a Mega for this ::slight_smile: :cry:

khancatrade:
I just searched, servo interferes the functionality of pwm.
Can UNO uses any servo without interfering with PWM functionality?

You sort of answered your question with the first line?

One method you could use is to "manually" send the pulses to the servo(s) as needed. A simple, single servo demo is shown here:

http://www.linuxcircle.com/2013/07/04/servo-manual-control-without-arduino-servo-library-on-raspberry-pi-and-gertboard/

Ignore the whole "Raspberry Pi" thing - the code should work on a standard Uno. Basically, by using careful timing and sending the PPM to a pin while in loop() - you can control a servo. In theory, you can control more than one, but that will take more effort. Someone has probably already made a library for the purpose - just google around for "Arduino PWM and Servo Control" - and you may find something. For instance, there's this:

http://playground.arduino.cc/ComponentLib/Servo

But I don't know how well (or if) it plays well with the current version of the Arduino system, or if it is even doing things manually or via one or another timer interrupt (I haven't looked at the code). Check it out, look it over - see if you can make it work, or mod it with the knowledge from the other link to get it to work.

The whole point of using a timer interrupt is so that you don't need to "babysit" the update of the servo PPM signals in your code, while also ensuring that you send the pulses at the proper intervals. There's also the issue that when doing this, you have to take care with the rest of your code, so as not to slow things down, and miss pulses (leading to "jitter" of the servo positions). It can be very difficult. So, a timer interrupt is used to keep such things "hidden" - the interrupt handler does the babysitting instead.

A couple of other options are available to you as well:

  1. You could dedicate a second Arduino (or some other microcontroller) to the task of the servo(s) - and communicate with that Arduino using a command protocol (via a serial method of your choosing) to tell it what servo to position where. Research "Serial Servo Controller" for more info - Pololu actually makes such a device, if you didn't want to try to replicate it. There are also chips sold on Ebay based on a particular PIC processor which can control servos in such a manner (with a few minor additional parts).

  2. There's also this chip (Tutorial – Arduino and the TLC5940 PWM LED Driver IC | tronixstuff.com), among others (called PWM driver chips - Adafruit has a selection of them, plus breakout boards - but all are common and can be sourced elsewhere too) - which are basically programmable PWM generators - you can use them for whatever you want - servo control, general PWM purposes, etc. Communication is generally done using I2C or something similar.