AnsweredAssumed Answered

Having trouble with PIT->PDB->ADC->DMA on K22

Question asked by SCOTT MILLER on Jul 20, 2017
Latest reply on Jul 26, 2017 by Hui_Ma

I'm on CodeWarrior 10.7, using Processor Expert (at least for some parts) and writing code for an MK22FN1M0, and I'm having a heck of a time getting the PDB to work right with the ADC.


My goal is to sample periodically from two ADC channels and place the results in two separate circular buffers via DMA.  The sample rate for the two channels is the same but they're effectively independent and the timing relationship between them is not critical.


I think the way this ought to work is to have the PIT running at the 16 kHz sample rate trigger the PDB, with the PDB in one-shot mode generating the triggers for the ADC's A and B channels in sequence.


I've got the PIT running at the appropriate rate and I can see from the PDB interrupt that the PDB is running correctly.  I've been able to get a few samples out of the ADC but then I get a sequence error and everything stops.


The documentation is scattered and unclear, and I'm seeing other posts here suggesting that maybe the PDB's sequence error flag clearing is just plain broken.  The manual says that a sequence error means that the last conversion was not completed before the next trigger occurred, but I'm getting errors when the conversion time is 4 us and the interval is 4000 us.


It looks to me like maybe the sequence error depends not on whether the conversion is still in progress, but whether the value has been read from the result register yet. Is that correct?


What is the recommended DMA setup to get both result registers at the appropriate time and put them into separate buffers?  The ADC's DMA trigger is common to both A and B channels and I can see several possibilities, but there must be a standard solution for this.  Is there a working example somewhere that uses the PIT, PDB, ADC, and 

DMA together?