16 bit PWM on a mega
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].