A/D, cant identify which sample came from which channel on dsPIC33EP512GP806
I am using a dsPIC33EP512GP806, my code samples 10 channels on 10bit mode, 6 has to be at the highest possible frequency 4 of them can be sampled less regularly. So 6 channels have been sampled every time while the other four has been sampled every second time. To do that I am using simultaneous sampling for 4 channels modules and also use the alternate input sample mode on 2 A/D modules.
The math works 6*1+4*1/2 = 8. So I will get samples from all channels by the second run. I am using the A/D dedicated buffers to collect the samples. The problem is that there is no indicator (or at least I or I can't find) in the ADCON registers that shows which alternative setup is in use, so... problem.
If I keep track how many times I collected the samples then I will know which sample belongs to which channels. Until, there is an error. Once I loose track, there is no way to figure it out. Until the A/D get restarted. Not helpful for a motor drive... :)
There is a solution by the use of DMA channels with scattered/gathered addressing mode and ping-pong buffering mode. Luckily DMA has indicator for ping-pong buffer usage. The address of the sample determines which channel it came from. And just to be sure after reading the value in the buffer should be replaced by an invalid one. For example it can be 1024 or greater or negative. In this case the software can decide if the sample has or hasn't been updated.
I just don't like the complexity of this solution.
I wonder if there is a simple solution?