Q:

Problem with PWM interference

I have a following code
  #include <Servo.h> //library for servo drive
  int MotorAPinA = 9;   //pin number for DC drive
  int MotorAPinB = 10;  //pin number for DC drive
  Servo myservo; //create object myservo, class servo from Servo library

void setup() {
  // put your setup code here, to run once:
  pinMode(MotorAPinA, OUTPUT);
  pinMode(MotorAPinB, OUTPUT);
  //myservo.attach(6); //pin number for servo output
  myservo.write(65);
}

void loop() {
  analogWrite(MotorAPinA, 240);
}

This very code works only partly. 
If I comment line 
myservo.attach(6)

then I got my DC drive working. 
If I uncomment this line, my Servo goings crazy (effect looks like myservo.write(0) constantly), until I comment line 
analogWrite(MotorAPinA, 240);

and then I got my servo working properly. 
While myservo.attach(6) is uncommented, DC drive doesn't work (with uncommented analogWrite).
So, basically, I can have or PWM or Servo working simultaneously, but not both
Any ideas? Arduino Uno R3, Arduino 1.8.1. 

A:

Well, your PWM outputs are both on 16b Timer/Counter 1 and the servo is attached to the 8b Timer/Counter 0. So my guess is that 8bit counter has too low resolution for driving the servo and it uses Timer/Counter 1 in full 16b mode for better precision instead (PWM uses just 8bits from 16). Also Timer/Counter 0 is used for counting millis, so its settings can't be changed anyway.
For the confirmation you can either:

use pins 5 and 6 (TC0) or/and pins 3 and 11 (TC2) and for the servo use pin 9 or 10
You can read the values of TC1 configuration registers and according to the datasheet you can figure out what mode is currently used.

EDIT:
So on the Uno board is used Timer/Counter 1 for timing purposes:
  if(timer == _timer1) {
    TCCR1A = 0;             // normal counting mode
    TCCR1B = _BV(CS11);     // set prescaler of 8
    TCNT1 = 0;              // clear the timer count
    TIFR |= _BV(OCF1A);      // clear any pending interrupts;
    TIMSK |=  _BV(OCIE1A) ;  // enable the output compare interrupt
    timerAttach(TIMER1OUTCOMPAREA_INT, Timer1Service);
  }

So no PWM on the OC1A nor OC1B in normal mode and the channel A is taken by Servo.

