I would like to use the PDB to trigger DAC updates, but don't think I properly understand the operation of the PDB.
Details of my application:
I am trying to implement a Direct Digital Synthesis (DDS) algorithm using the Programmable Interrupt Timer (PIT). Therefore, each time the PIT issues an interrupt, I increment the phase of an accumulator, which I use with a sinusoidal LUT to set the the next element of the DAC buffer. I would then like to trigger the DAC to update (via PDB) with the recently stored value in the buffer. I therefore issue a software trigger to the PDB, and expect that some delay later (determined by the PDB DAC Interval Value), the DAC outputs the new value.
g_DACBuffIdx = 1;
while (1) {if(PIT_ISR_Flag) {
// 1. increment the phase
g_phase += g_FTW; // a 32-bit phase accumulator, where the Frequency Tuning Word (FTW)
// is determined at the top of the program by the user-input sine freq
// 2. calculate sine LUT index based on MSB of g_phase
g_sineIdx = (uint16_t)((g_phase & 0xFFF00000)>>20U); // get the 12 MSB from g_phase
// to use with a 4096-element sine LUT
// 3. Set the DAC to the new value
DAC_SetBufferValue(DAC_BASEADDR, g_DACBuffIdx, sinLUT[g_sineIdx]);
// 4. increment the DAC buffer index
g_DACBuffIdx++;
g_DACBuffIdx %= 16; // reset each time I reach the end of the DAC buffer
// 5. Trigger the PDB
PDB_DoSoftwareTrigger(PDB_BASEADDR);
// 6. reset the PIT interrupt flag
PIT_ISR_Flag = false;
}
}
If I simply set up the DAC to trigger by software instead of by hardware (i.e. the PDB), and replace the PDB trigger with DAC_DoSoftwareTrigger(DAC_BASEADDR); the above code works fine. What am I not understanding about the operation of the PDB.
I have the PDB set to one-shot mode (continuous mode disabled). Nevertheless, it appears that the DAC updates more than once per while loop iteration. Why would this be? Is there a diagram to of PDB events to understand how it triggers DAC updates?
Note: I am using a K64F on the TWR-K64F120M dev board.