The AVR ATmega processors have several counter/timer registers that can be set up to output PWM. Here is a tutorial on how to set that up: http://sites.google.com/site/qeewiki/books/avr-guide/pwm-on-the-atmega328

The system clock is 16,000,000 Hz so to get to 40,000 Hz you will use a divisor of 400 which would be a Prescaller_value of 2 and a TOP_Value of 199. That should get you 200 levels of PWM at 40,000 samples per second.

You can enable an interrupt at the end of each cycle so you can change the PWM value between each pulse.

I believe you are correct. However in my example i am using it to send IR Remote Control codes, so the processor will be busy with sending the codes regardless of the carrier modulation that i'm creating with the 56kHz. If you are needing real PWM independent of a single task my example would not work. I wasn't sure the use that you were needing. It sounds like it may not fit your needs.