Am just posting the Full Code for an USB function generator based upon a
PIC24EP512GU810 (possibly a dsPIC33EP512MU810 should work pin-to-pin compatible).
Features 5..35000000Hz as Square Wave, with frequency approximation as close as possible (of course, not so perfect above 1MHz ), and I am going to go down to 0.1Hz using some further trick;
Same range for Rectangulare Wave, with duty-cycle selectable in 0.1% steps (same, and more, approximation rules apply);
0.1 .. 250KHz Sine, Triangle, Sawtooth Wave - generated with 16levels synthesis (8 at frequencies above 100KHz);
White Noise; and Pink in the to-do list (i.e. do something in software or add a low-pass filter at the output )
Schematic is basically "nothing" i.e. just decoupling capacitors, USB connector at its pins, a few debugging leds, a PWM output - and an I2C EEprom that we used to store waveform so that the device can run stand alone with the programmed wave (the EEprom was already there since we created this PCB for a CAN interface).
Output can be amplified using a large-bandwidth OpAmp such AD8007: USB interface already has an "Amplitude" parameter, unused at the moment.
One possible, simple improvement would be using an 8bit DAC (more is useless, due to IRQ overhead) in place of PWM.
have fun!