How to get 20khz PWM on pin D9

Pin D9 is the output from the Timer/Counter 1 Output Compare Register A (ORC1A). The highest speed you can run it at is 16 million steps per second or 62.5 kHz for 9-bit PWM (16 MHz / 256 steps). The way to get 20 kHz is to have the timer reset at 800 (16,000,000 / 20,000) instead of 256. This give you a PWM range from 0 to 799.

That's in the Fast PWM mode. For PWM modes where the timer counts up and then down (Phase Correct or Phase and Frequency Correct PWM) you would count up to 400 and back down to 0.

Read all Timer/Counter 1 and PWM modes in the ATmega328p datasheet.