I am new to the DUE, but I did get the sound to work OK for my purposes. (Make some sound on the speaker on my shield to let me know something is happening...)
//==============================================================================
// SoundNoTimer - Quick and dirty tone function to try to output a frequency
// to a speaker for some simple sounds.
//==============================================================================
void SoundNoTimer(uint8_t _pin, unsigned long duration, unsigned int frequency)
{
// Try to get something working on DUE...
long toggle_count = 0;
long lusDelayPerHalfCycle;
boolean fHigh = false;
// Set the pinMode as OUTPUT
pinMode(_pin, OUTPUT);
digitalWrite(_pin, LOW);
toggle_count = 2 * frequency * duration / 1000;
lusDelayPerHalfCycle = 1000000L/(frequency * 2);
// if we are using an 8 bit timer, scan through prescalars to find the best fit
while (toggle_count--) {
// toggle the pin
fHigh = !fHigh;
digitalWrite(_pin, fHigh? LOW : HIGH);
// delay a half cycle
delayMicroseconds(lusDelayPerHalfCycle);
}
digitalWrite(_pin, LOW);
}
Note on other platforms, this code uses Port Masks and the like to set/clear the values as quickly as possible...
Not saying this is great, but may get you limping along.
Kurt