how to setup the pwm frequency of ATmega16U2

What core are you using for the 16u2? I didn't realize there was an Arduino core for the 16u2, despite that many arduino boards use it programmed to act as a USB<->Serial bridge.

But as with most Arduino boards, to change the PWM frequency, you have to take over one of the timers and manually set the prescaler (and maybe TOP value) - see the datasheet section on the timers, and know that timer0 is generally used for millis() (but check the docs for your core)