I am posting the code as an attachment. Hopefully it is simple enough to follow. I will explain my logic, which I think is simple. Also, as per your suggestion, I am not printing the negative values. But the main problem of rapidly changing values still exists. If it takes 396 microseconds for A-D conversion for 3 channels, I have tried sampling once in 800 microseconds and once in 1200 microseconds. But the problem still persists.
Here is my logic.
I have setup the sequence of 0, 1 and 2. Analog to digital conversion is started by setting a bit in ADC registers. I dont use ADCCON3 as is done by adcRead().
Since I am using the sequence, once ADC is started, the data from port 0 is sampled for ADC first. When ADC values are available, (as specified by ADC DMA trigger)
DMA transfer takes place as per the configuration to a destination buffer.
I have setup DMA channels 2, 3 and 4 to read from ports 0, 1 and 2. The inputs are single ended inputs. ADC DMA triggers are used (21 to 23).
As per the manual, once ADC is started, port 0 is sampled first and after the conversion, data is DMAed to the destination. then the port 1 is sampled and so on.
I use repeat single, which refers to rearming the DMA channel after the transfer count is reached. I did use the other option, single, which refers to rearming
the DMA channel in DMA ISR. But that did not really work well. After about 4 or 5 transfers it stops working. But I am ok with repeat single as it is working fine.
Timer is used to start A to D conversion. It takes 132 micro seconds for each conversion. So the min time interval between two ADC start conversion is 396 micro seconds.
In the code, I have used much higher values and tried different values just to see when I get consistent readings. I was not able to get any consistent readings.
I disable DSM for a certain time period just so that I give some time to print the values.
In summary, I want to use the hardware features as much as possible in the hope that it conserves power. So here is the code..
hal.h (4.94 KB)
t1adcdma.c (11.5 KB)