QN9080 ADC speed issue

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

QN9080 ADC speed issue

348 Views
tpgurtpgur2
Contributor I

Hi,

I am working on a project that uses the QN9080 SIP to ADC analog values from sensors and send them over BLE. I am using multiple analog sensors, so I need to perform multiple channels of ADC by switching channels.

 

Here is a simple code I wrote modified from the ADC example code.

 

// Sensor Channel #1
ADC->CH_SEL = 0x00000040;
ADC_DoSoftwareTrigger(ADC);
while(!(ADC_GetStatusFlags(ADC) & kADC_DataReadyFlag)) {}
adcConvResult1 = ADC_GetConversionResult(ADC);
tmp_data[tmp_data_num++] = (uint8_t)(adcConvResult1 >> 15);

// Sensor Channel #2
ADC->CH_SEL = 0x00000100;
ADC_DoSoftwareTrigger(ADC);
while(!(ADC_GetStatusFlags(ADC) & kADC_DataReadyFlag)) {}
adcConvResult1 = ADC_GetConversionResult(ADC);
tmp_data[tmp_data_num++] = (uint8_t)(adcConvResult1 >> 15);

 

I've made the above code work inside the callback function of Ctimer. Because of the sampling rate of the analog sensor output, the callback function needs to iterate at a high rate of about 10 kHz, but the "while(!(ADC_GetStatusFlags(ADC) & kADC_DataReadyFlag)) {}" code above takes too much time.

 

I tested it and found that it works for speeds up to about 400 Hz, and stops at speeds higher than that without moving on from the "while(!(ADC_GetStatusFlags(ADC) & kADC_DataReadyFlag)) {}" code.

 

When I removed the "while(!(ADC_GetStatusFlags(ADC) & kADC_DataReadyFlag)) {}" code, it worked at rates as high as 10 kHz, but the values on each ADC channel were noisy and there was a lot of interference between the channels. This effect increased at higher rates and decreased as I slowed down.

 

Is there any way to lower the delay time of the "while(!(ADC_GetStatusFlags(ADC) & kADC_DataReadyFlag)) {}" code? Alternatively, I would appreciate if you could describe a way to ADC multiple channels at a high speed with minimized noise and interference.

 

PS. I currently have the ADC running in Single mode. If I use Scan mode, I expect the same issue to be repeated because the ADC output value is available after the ADC_DoSoftwareTrigger(ADC); repeated "while(!(ADC_GetStatusFlags(ADC) & kADC_DataReadyFlag)) {}" code.

 

Best regards,

Oh

0 Kudos
Reply
1 Reply

326 Views
Gavin_Jia
NXP TechSupport
NXP TechSupport

Hi @tpgurtpgur2 ,

 

Thanks for contacting NXP support!

ADC conversion takes time, and a while loop waiting for the conversion result using the polling method will take up a lot of CPU time. In order to achieve the high sampling rate of 10kHz, we can consider using ADC interrupt instead of polling. By reading the result in the interrupt service function after conversion, the CPU waiting time can be greatly reduced.

 

Best regards,

Gavin

0 Kudos
Reply