I can definitely explain how but it may be easier for you to use Webbot's Library. If you want me to elaborate on how to manipulate the registers in the atmega640 to create the pwm signal let me know, and I'll post how.