Timer Interrupts on Due

Hi all,
We were wondering, with so much confusion about timers, PWM etc. whether one of our standard code blocks might come in handy.
This one trades resolution for frequency (as you do). Hope it is useful to somebody; nothing lost if it's not.

// Software PWM for the Arduino Atmel 328p @ 16MHz
//
// Women's Fashion Art Dev team
// 7 January 2013
//
// Default settings:
// volatile byte Maximum_Resolution_In_Percent = 50;
// byte Duty_Cycle_In_Percent = 50;
//
// Measured performance
// Freq: 3.27kHz
// Duty: 49.9%
// Vrms: 2.44V
// Vpp: 5.02V
// Vmin: 80.0 mV
// Vmax: 5.12V
// Vavg: 2.60V
// Target: Arduino Duemilanove - genuine
//
// Version 1.0 - 18 December 2012
//

#include <io.h>

// Variables
volatile byte Count;

// User variables - change these to suit
// volatiles
//
volatile byte Pin = 9;
volatile byte HighCount = 0;
volatile byte Maximum_Resolution_In_Percent = 50; // do not exceed 100% here...

// non volatiles
//
byte Duty_Cycle_In_Percent = 50; // do not exceed 100% here either...

// Setup routine
//
void setup(){

// Set user's preferred pin to output
//
pinMode(Pin, OUTPUT);

// Set up the high count
HighCount = DoCalcs(Maximum_Resolution_In_Percent, Duty_Cycle_In_Percent);

// Clear interrupts
//
cli();

// Configure timer registers
//
TCCR2A = 0;//
TCCR2B = 0;//
TCNT2 = 0;//

// set compare match register
// OCR2A = 99; // 200 Hz at 100% or 400 Hz at 50%
// OCR2A = 49; // 400 Hz at 100% or 800 Hz at 50%
// OCR2A = 24; // 800 Hz at 100% or 1.6 Khz at 50%
OCR2A = 11; // 1.6 kHz at 100% or 3.2 kHz at 50%

// CTC mode
//
TCCR2A |= (1 << WGM21);
//CS11 bit for 8 prescaler
//
TCCR2B |= (1 << CS11);
// timer compare interrupt
//
TIMSK2 |= (1 << OCIE2A);

// Re-enable interrupts
//
sei();

// Create a dependable PWM sequence
//
digitalWrite(Pin, HIGH); // Start off with a high pulse
}

// Interrupt Service Vector (IDE preset)
//
ISR(TIMER2_COMPA_vect){

// PWM High / Low Routine
// Pull pin low once HighCount is achieved
//
if (Count == HighCount) {
digitalWrite(Pin, LOW);
}
// Pull pin high once at the end of our resolution count
//
else if (Count == Maximum_Resolution_In_Percent) {
digitalWrite(Pin, HIGH);
Count = 0;
}
// Bump count by 1
//
Count += 1;
}

// Subroutines
//
int DoCalcs (byte Resolution, byte DutyCycle)
{
// Set up the high count
return (Duty_Cycle_In_Percent / (100 / Maximum_Resolution_In_Percent));
}

// Main loop
// This does nothing at present, but can add other stuff to this
// depending on how hard the timer is being driven....
//
void loop()
{
while (1);
{
// do other stuff here
}
}