16 bit PWM on a mega I have two Arduinos, a nano and a mega. I want to output 16 bit PWM, but can seem to only get it working on the nano. I'm adapting the code from this website: http://www.ofrecordings.com/2014/03/16/how-to-set-up-16-bit-pwm-with-an-arduino-uno-atmega328/

void setup() {
  // Set PB1/2 as outputs.
  DDRB |= (1 &lt;&lt; DDB1) | (1 &lt;&lt; DDB2);

  TCCR1A =
      (1 &lt;&lt; COM1A1) | (1 &lt;&lt; COM1B1) |
      // Fast PWM mode.
      (1 &lt;&lt; WGM11);
  TCCR1B =
      // Fast PWM mode.
      (1 &lt;&lt; WGM12) | (1 &lt;&lt; WGM13) |
      // No clock prescaling (fastest possible
      // freq).
      (1 &lt;&lt; CS10);
  OCR1A = 0;
  // Set the counter value that corresponds to
  // full duty cycle. For 15-bit PWM use
  // 0x7fff, etc. A lower value for ICR1 will
  // allow a faster PWM frequency.
  ICR1 = 0xffff;
}

void loop() {
  // Use OCR1A and OCR1B to control the PWM
  // duty cycle. Duty cycle = OCR1A / ICR1.
  // OCR1A controls PWM on pin 9 (PORTB1).
  // OCR1B controls PWM on pin 10 (PORTB2).
  OCR1A = 0x0000;
  delay(500);
  OCR1A = 0x8000;
  delay(500);
  OCR1A = 0xffff;
  delay(500);
}


That code works on the nano, but not on the mega. I expect that it output PWM on pins 11 and 12, but no luck. Care to explain how I can get it working? It's an entirely different microprocessor, and I'm not sure which parts of the code to change.
Change first line:

    // Set PB1/2 as outputs.
    DDRB |= (1 &lt;&lt; DDB1) | (1 &lt;&lt; DDB2);`


to the

     // Set PB5/6 as outputs. [**Digital pin 11,12 on Arduino Mega!**]
    DDRB |= (1 &lt;&lt; DDB5) | (1 &lt;&lt; DDB6);


Now your PWM should work, but on digital pins 11 &amp; 12 [Arduino Mega].