ADC Interrupt in Kinetis MKE02Z

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

ADC Interrupt in Kinetis MKE02Z

4,073 Views
PabloA
Contributor II

Hi there, I'm trying to implement a synchronous measure of samples using as time base a timer interrupt. To do this I chose the ADC One Conversion method inside a timer interrupt in this way:

On Processor Expert:

1. Set Interrupt service / event = Disable (As the Processor Expert help suggest for One Convertion method)

2. SetUp A/D Channel List with my 4 ADC inputs.

3. SetUp Static sample group indexed to my 4 ADC inputs.

On my interrupt function:

ADC_TResultData ADC_Values_Result [4];

void ADC_Sampling (void)

{

     (void) ADC_SelectSampleGroup(ADC_DeviceData,0);

     (void) ADC_StartSingleMeasurement(ADC_DeviceData);

     while (!ADC_GetMeasurementCompleteStatus(ADC_DeviceData)) {}; /* Wait for conversion completeness */

     (void) ADC_GetMeasuredValues(ADC_DeviceData,&ADC_Values_Result);

}

As you can imagine I have some problems with this code.

When it run on main, it works perfectly, if I set Interrupt service / event = Enable, but if I set Interrupt service / event = Disable the processor don't come out from GetMeasurementCompleteStatus while loop;

If I set Interrupt service / event = Enable this function don't works on the timer interrupt.

So, my questions: Why I need to set Interrupt service / event = Enable to make a single measure of a group?

How may I measure the group values without generate interrupts?

I read and implement the One conversion of a created sample group, without interrupt service from Processor Expert Help, but it neither worked.

I will appreciate your help.

Best regards.

15 Replies

2,471 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Pablo,

From the Help of ADC_LDD component ,   GetMeasurementCompleteStauts said   "It can be used to poll the state of measurement if Interrupt service/event is disabled or if OnMeasurementComplete event is disabled by the SetEventMask() methods. "

And you can refer to the Typical usage about with interrupt service and without interrupt sevice : "Continuous measurement of a selected sample group, with interrupt service"  " One conversion of a created sample group, without interrupt service"   of help.

Best Regards,

Alice

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you for your support to us!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

2,471 Views
PabloA
Contributor II

Dear Alice, thank you for your time.

I read One conversion of a created sample group, without interrupt service in the ADC_LDD Help, in fact, Interrupt service/event is disabled in the Processor Expert. Is this enough to make a single conversion without interrupts?

GetMeasurementCompleteStatus don't return conversion complete status and the processor can't go out from the while loop, previous ADC_StartSingleMeasurement.

I missing something that I can't see yet.

Regards.

0 Kudos
Reply

2,471 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Pablo,

About one conversion mode or continuous conversion mode , you need  config on "ADC_PDD_SetContinuousMode()" function.

If you haven't config ,the default is "one conversion mode" .

Detail processing please refer to the screenshot below :

1111.png

2222.png

3333.png

Best Regards,

Alice

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you for your support to us!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

2,471 Views
PabloA
Contributor II

Dear Alice, thank you once again,

I don't have the same code as you send me -StartSingleMeasurement() function- and I dont have any posibility to set Continuous Conversion Mode or One Conversion Mode in my Processor Expert. Even the Processor Expert can't generate ADC_PDD_SetContinuousMode() function, this is not on the functions list. The closest thing to your function is SetOperationMode() but I don't know how to use it.

JPG_1.jpg

This is my StartSingleMeasurement() function:

LDD_TError AD1_StartSingleMeasurement(LDD_TDeviceData *DeviceDataPtr)

{

  AD1_TDeviceDataPtr DeviceDataPrv = (AD1_TDeviceDataPtr)DeviceDataPtr;

  uint8_t Sample;                      /* Index of the sample for FIFO feeding */

  if (ADC_PDD_GetConversionActiveFlag(ADC_BASE_PTR) != 0U) { /* Last measurement still pending? */

    return ERR_BUSY;                   /* Yes, return ERR_BUSY */

  }

  ADC_PDD_SetConversionTriggerType(ADC_BASE_PTR, ADC_PDD_SW_TRIGGER); /* Select SW triggering */

  for (Sample = 0U; Sample < (DeviceDataPrv->GroupPtr->SampleCount - 1U); Sample++) {

    ADC_PDD_WriteStatusControl1Reg(ADC_BASE_PTR, 0U, DeviceDataPrv->GroupPtr->StatusControlRegVal[Sample]); /* Set channel for all samples except last */

  }

  ADC_PDD_WriteStatusControl1Reg(ADC_BASE_PTR, 0U, DeviceDataPrv->GroupPtr->StatusControlRegVal[(DeviceDataPrv->GroupPtr->SampleCount - 1U)] | (uint32_t)(LDD_ADC_ON_MEASUREMENT_COMPLETE)); /* Set last sample of the group with one conversion mode */  

  return ERR_OK;                       /* OK */

}

I tried the same code as ADC_LDD Help without static samples group, but with the same result, without interrupt enable it don't work.

Thank you for your help.

0 Kudos
Reply

2,471 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Pablo ,

Which version CW and PE do you use ? If not the newest version , you'd better update .

From your code , I think this

for (Sample = 0U; Sample < (DeviceDataPrv->GroupPtr->SampleCount - 1U); Sample++) {

    ADC_PDD_WriteStatusControl1Reg(ADC_BASE_PTR, 0U, DeviceDataPrv->GroupPtr->StatusControlRegVal[Sample]); /* Set channel for all samples except last */

  }


control the number of ADC conversion ,  please check the number of "DeviceDataPrv->GroupPtr->SampleCount  ".


Hope it helps

Alice

0 Kudos
Reply

2,471 Views
PabloA
Contributor II

My CodeWarriori is:

CodeWarrior Development Studio

(c) Freescale Semiconductor, Inc. 2014. All rights reserved.

Learn more about CodeWarrior at

http://www.freescale.com/codewarrior

Installed Products:

- CodeWarrior for MCU

  Version: 10.6

  Build Id:140329

Is it the last version?

Regards!

0 Kudos
Reply

2,471 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Pablo,

Yes, CW10.6 is the latest version .

And check the  Processor Expert , whether is the latest version  : "help ->Install new software ", then refer to  the screenshot :

221.png

222.png

If this log is colorized , please update it .

if still can't work ,can you send your project to me ?

Alice

0 Kudos
Reply

2,471 Views
PabloA
Contributor II

Dear Alice, today I spent 4Hs reinstalling CW to SE Version and updating all of components. This is my Available Software Window:

Window.jpg

But, unfortunately, Components Inspector don't have any place to change single measure to continuous conversion mode or vice versa.

I found the ADC_PDD_SetContinuousMode() function that you refer me in the PDD folder, but I don't know how to use it.

So, here you have my code. I hope I'm very confused, it can't be so difficult.

Best regards!

Pablo

0 Kudos
Reply

2,471 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Pablo,

1) I'm sorry I use not the mkeo2z board before.

2) I test on the adc on kE02z board without interrupt refer to help , the result is never run to the "Error = AD1_GetMeasuredValues(MyADCPtr, (LDD_TData *)MeasuredValues);  /* Read measured values */" .(I will check the reason go on).

And now , I modify the " while (!AD1_GetMeasurementCompleteStatus(MyADCPtr)) {};"  to "  while(!(ADC_SC1 & 0x80)){}" , it can work normal .  (see the attchment ) .

Hope it helps

Alice

0 Kudos
Reply

2,471 Views
PabloA
Contributor II

Thank you Alice but it didn't work, the measured result is always zero.

Assuming that it can't work without interrupt, and this interrupt can't run inside the Timer interrup, there is any way to acknowledge timer interrupt to be ADC interrupt able to work?

Regards!

0 Kudos
Reply

2,471 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Pablo,

1)  What do you meaning "this interrupt can't run inside the Timer interrup, there is any way to acknowledge timer interrupt to be ADC interrupt able to work? "?

2)  And you don't want to use ADC interrupt , right ?  And i test that , after enable ADC interrupt , while don't use interrupt , the project can work well .

    In this case , if we need continuous measurement ,we can write like this :

  /* Write your code here */

  MyADCPtr = AD1_Init((LDD_TUserData *)NULL);        /* Initialize the device */

    Error = AD1_SelectSampleGroup(MyADCPtr, 0U);       /* Select sample group 0 */

    Error = AD1_StartLoopMeasurement(MyADCPtr);        /* Start continuous measurement */

    for(;;) {

         while (!AD1_GetMeasurementCompleteStatus(MyADCPtr)) {}; /* Wait for conversion completeness */

          Error = AD1_GetMeasuredValues(MyADCPtr, (LDD_TData *)MeasuredValues);  /* Read measured values */

    }

Alice

0 Kudos
Reply

2,471 Views
PabloA
Contributor II

Alice, as you say when I use interrupt in the ADC module it works fine, if I use it in the Main function.

My design have to measure with a fixed period of time, so I thought why don't put the ADC code in a timer interrupt? With every timer overflow I can get mi time fixed measure. But the ADC interrupt seems doesn't work when AD1_StartSingleMeasurement() is called from the timer interrupt.

This does not surprise me, if it is like the old microcontrollers, when the code is running inside a interrupt function, others interrupts have to wait until it finish. If I need to use another interrupt anyway, I had to clear the interrupt bits of the previous one.

But that was with the HS08, I don't know how to do it with Kinetis.

So, thats my problem, if I use Interrupts with the ADC module, it doesn't work in the timer interrupt and if I use the ADC module without interrupts (polling mode) it doesn't work neither.

Thank you for your time.

Regards!

0 Kudos
Reply

2,471 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi, Pablo

The code in the help is really have problem.

And i found a simple demo on community about keo2 adc  without interrupt .

Hope it helps

ALice

0 Kudos
Reply

2,471 Views
PabloA
Contributor II

Hi Alice, finally I solved my problem like the old way, polling mode. I put this code in my Timer Interrupt:

#define ADC_Battery_Current_MASK 1 //Select ADC0_SE1 Battery Current

#define ADC_Battery_Half_V_MASK 2 //Select ADC0_SE2 Battery Full Voltage

#define ADC_Battery_Full_V_MASK 3 //Select ADC0_SE3 Battery Full Voltage

#define ADC_Battery_Temp_MASK 4 //Select ADC0_SE4 Battery Current

void ADC_Sampling (void)

{

  ADC_SC1 = ADC_Battery_Current_MASK;

  while ((ADC_SC1 & ADC_SC1_COCO_MASK) != ADC_SC1_COCO_MASK){}

  Battery_Current = ADC_R;

  ADC_SC1 = ADC_Battery_Half_V_MASK;

  while ((ADC_SC1 & ADC_SC1_COCO_MASK) != ADC_SC1_COCO_MASK){}

  Battery_Half_V = ADC_R;

  ADC_SC1 = ADC_Battery_Full_V_MASK;

  while ((ADC_SC1 & ADC_SC1_COCO_MASK) != ADC_SC1_COCO_MASK){}

  Battery_Full_V = ADC_R;

  ADC_SC1 = ADC_Battery_Temp_MASK;

  while ((ADC_SC1 & ADC_SC1_COCO_MASK) != ADC_SC1_COCO_MASK){}

  Battery_Temp = ADC_R;

}

I used the Process Expert tool to configurate ports, frecuency and so on.

Hope the Process Expert Team can fix this proble, is a very usefull tool.

Thank you for your interest.

Best regards.

2,471 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hi Pablo,

1) KE02 use  ARM M0 core, and the  interrupt support nested feature .

2)I test without interrupt , check the flag,  and without PE , use the cw sample driver , it can work well .(if you need ,I can send you)

3) I will ask the PE team what's wrong whit us .

Hope it helps

Alice

0 Kudos
Reply