ADC_16 conversion occassionally fails to complete, gets stuck in waiting for COCO.

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

ADC_16 conversion occassionally fails to complete, gets stuck in waiting for COCO.

Jump to solution
1,115 Views
randenewberry
Contributor IV

Using a custom board with MK02FN64VLH10 controller, KSDK 1.3, PE 10.6.

I have set up the ADC in the 16 bit differential mode, trigger the ADC from a PIT interrupt (every 62uS), The  Interrupt code is shown below: I take samples and stores them in arrays, as long as the arrays are not full. While samples are being taken and stored in 1 array, I am taking an FFT on the filled array. This works fine the vast majority of the time...

Problem is that after some time between 1 and 10 minutes of continuous good operation, the program gets stuck in the

ADC16_HAL_GetChnConvCompletedFlag

routine and seems to stay there. The interrupt continues to occur, so code is running OK. Since the buffers are now full, it just skips the ADC conversion and returns right back to ADC16_HAL_GetChnConvCompletedFlag  waiting for a conversion to complete...I assume.

Does anyone see anything wrong with the above code or the implementation of starting a conversion, waiting for completion, and getting the value? I tried to manually wait for the COCO bit to set, and that works OK, but has the same problem...

Any help would be greatly appreciated!

pastedImage_1.png

Thank you,

 

Labels (1)
Tags (1)
0 Kudos
1 Solution
948 Views
cutworth
NXP Employee
NXP Employee

Hi Rande,

It's not very clear how you initialized ADC, is it software triggered or hardware triggered? Based on your input, seems you configured ADC as software triggered, each time in PIT timer ISR you start one ADC conversion and waiting for its complete. The code in the PIT timer ISR looks fine, but this will depend on how you configure ADC module.

Do you know how much time it takes for one ADC conversion with your setting? This will depend on ADC clock source you used, if you are using hardware average. Will the ADC conversion time be longer than your timer interval? Also do you enable ADC interrupt and how you handle ADC interrupt?

BTW, actually you can hardware trigger ADC with PIT, the trigger timing will be more precise when you have heavy loading in your MCU. For KSDK1.3, you can refer to code under demo_apps\adc_hw_trigger folder, there is one for PIT trigger.

pastedImage_1.png

Hao

View solution in original post

0 Kudos
4 Replies
949 Views
cutworth
NXP Employee
NXP Employee

Hi Rande,

It's not very clear how you initialized ADC, is it software triggered or hardware triggered? Based on your input, seems you configured ADC as software triggered, each time in PIT timer ISR you start one ADC conversion and waiting for its complete. The code in the PIT timer ISR looks fine, but this will depend on how you configure ADC module.

Do you know how much time it takes for one ADC conversion with your setting? This will depend on ADC clock source you used, if you are using hardware average. Will the ADC conversion time be longer than your timer interval? Also do you enable ADC interrupt and how you handle ADC interrupt?

BTW, actually you can hardware trigger ADC with PIT, the trigger timing will be more precise when you have heavy loading in your MCU. For KSDK1.3, you can refer to code under demo_apps\adc_hw_trigger folder, there is one for PIT trigger.

pastedImage_1.png

Hao

0 Kudos
948 Views
randenewberry
Contributor IV

Hi Culworth,

I was able to workaround the problem by putting a delay (loop with some

nop's) instead of waiting for the COCO bit to set.

The ADC is started based on a PIT timer interrupt every 62us. It takes

8us for the entire ISR, and when my buffer is full (skipping the ADC

start, wait, and get and store value) it takes 2.3us. So my wait loop is

6us, which works fine. The ADC interrupt is disabled.

Thank you for the assistance!

Rande Newberry

H-ITT, LLC, a Hyper-Interactive Teaching Technology Company

420 Shearer Blvd.-Cocoa, FL, 32922

PH: 888-322-0089

rande@h-itt.com

0 Kudos
948 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Rande,

Regarding your issue, can you try to change the software architecture? for example, put the code to start ADC and poll if the ADC conversion is complete in the main() rather than in ISR.

Hope it can help you

BR

Xiangjun Rong

bool PitFlag;

void PIT0_IRQHandler()

{

PIT_HAL_Clear_IntFlag();

PitFlag=true;

}

void main()

{

.......................

while(1)

  {

if(PitFlag)

      {

        ADC16_DRV_ConfigConvChn();

        ADC16_DRV_WaitConvDone();

        sample=ADC16_DRV_GetConvValueSigned();

     PitFlag=false;

       }

  }

}

947 Views
randenewberry
Contributor IV

Hi Xiangjun,

Instead of waiting on the COCO bit to set, I just put a 6us wait (some

nop's in a loop) after starting the ADC and the problem is fixed.

Thank you for the reply!

Rande Newberry

H-ITT, LLC, a Hyper-Interactive Teaching Technology Company

420 Shearer Blvd.-Cocoa, FL, 32922

PH: 888-322-0089

rande@h-itt.com