MKL16 ADC read using DMA

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MKL16 ADC read using DMA

1,041 Views
balkrishanaa
Contributor II

Came across code for MKL16 controller, where ADC single channel data is read in DMA interrupt in "uint32 adc_data[4]". And after reading data using DMA_PrepareTransfer(), data in adc_data[1] is used while ignoring adc_data[0]. Code seems to work fine, what can be the justification for this? ADC is configured for differential conversion and auto calibration is enabled.

ADC configuration: resolution = 16 bit

longSampleMode = kADC16_LongSampleCycle24

enableContinuousConversion = false

enableInterruptOnConversionCompleted = false

enable dma = true 

sample code :

uint32AveragedReading;

uint32 adc_data[4];

//interrupt used for reading ADC data

DMA0_IRQHandler()

{

int data;

DMA_ClearChannelStatusFlags();

DMA_PrepareTransfer(&DMA_TransferConfig, (void *)(uint32_t)(&ADC0->R[0]), sizeof(uint32_t),
(void *)adc_data, sizeof(uint32_t), sizeof(adc_data),
kDMA_PeripheralToMemory);

data = adc_data[1];// why adc_data[0] is ignored?

AveragedReading = averaged_value_of_'data';

}

6 Replies

841 Views
balkrishanaa
Contributor II

Hi Sabina,

Thanks for your help. I am trying to reach the developer who wrote this code and I will update this thread if he has any specific reasons for doing this.

Regards,

Balkrishana

0 Kudos

841 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hi Balkrishna,

Could you please tell me which example you are working on and what version of the SDK it is?

Let me know as soon as you can, so I can assist you.

Thank you,

Sabina

0 Kudos

841 Views
balkrishanaa
Contributor II

Hi Simua,

Thanks for your reply. I am using "kds 2.2.0". And could you please tell what you mean by "which example you are working on"?

0 Kudos

841 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hi Balkrishna,

You said that you "Came across code for MKL16 controller". In order for me to be able to better assist you I need to know where you located this code. 

If you can attach the project that would also be helpful.

Thank you,

Sabina

0 Kudos

841 Views
balkrishanaa
Contributor II

Hi Sabina,

Thanks for your reply. Actually, I am working on client project and I got this code from them. I am working on re-designing the code. I would not be able to share code. We are using this ADC to monitor photo-diode readings. Please let me know if you need any other configuration details.

Thanks,

Balkrishana 

0 Kudos

841 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hi Balkrishana,

Thank you for the information you have provided. I tried replicating the code you provided, but the first sample is just as valid as the rest of the samples in the data[4] array. Unfortunately from our side there is no valid reason as to why ignore the first sample that is being read from the ADC. I believe this particular implementation will be specific to your client's needs. I would recommend that you ask them directly why this is being done.

Best Regards,

Sabina