Well just a quick update on my progress in case anyone is listening. 
I was able to find a piece of code which sets up an interrupt using the SAM's TC (counter)
// Black magic
void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency) {
pmc_set_writeprotect(false);
pmc_enable_periph_clk((uint32_t)irq);
TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK1);
uint32_t rc = VARIANT_MCK/2/frequency; //2 because we selected TIMER_CLOCK1 above
TC_SetRA(tc, channel, rc/2); //50% high, 50% low
TC_SetRC(tc, channel, rc);
TC_Start(tc, channel);
tc->TC_CHANNEL[channel].TC_IER=TC_IER_CPCS;
tc->TC_CHANNEL[channel].TC_IDR=~TC_IER_CPCS;
NVIC_EnableIRQ(irq);
}
void setup(){
pinMode(13,OUTPUT);
// Start timer. Parameters are:
// TC1 : timer counter. Can be TC0, TC1 or TC2
// 0 : channel. Can be 0, 1 or 2
// TC3_IRQn: irq number. See table.
// 40000 : frequency (in Hz)
// The interrupt service routine is TC3_Handler. See table.
startTimer(TC1, 0, TC3_IRQn, 40000); //the last number will be the freq. of interrupt in Hz
// Paramters table:
// TC0, 0, TC0_IRQn => TC0_Handler()
// TC0, 1, TC1_IRQn => TC1_Handler()
// TC0, 2, TC2_IRQn => TC2_Handler()
// TC1, 0, TC3_IRQn => TC3_Handler()
// TC1, 1, TC4_IRQn => TC4_Handler()
// TC1, 2, TC5_IRQn => TC5_Handler()
// TC2, 0, TC6_IRQn => TC6_Handler()
// TC2, 1, TC7_IRQn => TC7_Handler()
// TC2, 2, TC8_IRQn => TC8_Handler()
}
void loop(){
}
volatile boolean l;
// This function is called every 25 uS.
void TC3_Handler()
{
// You must do TC_GetStatus to "accept" interrupt
// As parameters use the first two parameters used in startTimer (TC1, 0 in this case)
TC_GetStatus(TC1, 0);
digitalWrite(13, l = !l); //make a square wave of frequency 20 kHz
}
Big props to Sebastian Vik and @cmaglie for posting this very helpful code.
This is a really powerful tool because you can have a bunch of independent interrupts/ timers.
Since I am sampling an audio signal, I set the interrupt at 40kHz which should allow time between samples to save and recall 2 bytes from the SD card, but also will allow sampling up to 20kHz.
I put the code into practice and it worked nice. I was initially concerned because at about 10kHz, you get a sort of bit-crushed stair step effect on the wave coming from the DAC. Using the cursor; however, I can see there is approx. 25 uS between each stair step so I guess this is to be expected (T = 25uS.)
If anyone has any pointers or is interested in talking about this project in more detail, I'm all ears. Thanks. Will update on progress as I go, (unless I get kicked off here
)
Peace