16 bit variable frequency PWM on Arduino Mega

I'd like to program an Arduino Mega to give me 16 bit control over both the period and the duty cycle of a single PWM pin. In practice this would mean using the timer control registers (probably for timer 1) to set the period from 1 to 65535, and the duty cycle from 0 to the period.

I think the hardware should allow this, but despite the many Timer 1 examples I've found online, I haven't found one that allows this exact situation. Can anyone help?

EDIT: I think I may have solved this, so before anyone spends time on it, I'll post back when I've got my solution working properly.

This example gives a PWM output on pins 11, 12, and 13, with a variable period, using Timer 1.

// Timer1 pins:  11,   12,   13
//              PB5,  PB6,  PB7
//             OC1A, OC1B, OC1C

void setup() {                

  // Set up hi-res variable frequency PWM on pins D11, D12, D13
  pinMode(11, OUTPUT); // D11/PB5/OC1A as output
  pinMode(12, OUTPUT); // D12/PB6/OC1B as output
  pinMode(13, OUTPUT); // D13/PB7/OC1C as output
  // Stop timer 1
  TCCR1B = 0;
  // Fast PWM mode, turn on PWM for A B and C
  TCCR1A = (1<<WGM11) | (1<<COM1A1) | (1<<COM1B1) | (1<<COM1C1);
  TCCR1B = 2 | (1<<WGM13) | (1<<WGM12);  // 2 gives prescaler 8
  ICR1  = 40000; // Set PWM period to 1 ms
  OCR1A =  2000; // Set D11 to 1ms pulse length
  OCR1B =  4000; // Set D12 to 2ms pulse length
  OCR1C =  3000; // Set D13 to 1.5ms duty cycle

void loop()