ADC no interrupt after software start

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

ADC no interrupt after software start

Jump to solution
1,233 Views
randylee
Contributor V

I'm using MCUexpresso, SDK 2.11.0 on an LPC5512.  I'm just attempting to periodically (slowly) look at a line for ADC Conversion.  I've used some example stuff to set this up sort of but it just isn't going to fire an interrupt.

so I set up ADC0 thusly:

randylee_0-1674575630361.pngrandylee_1-1674575670447.png

 

Code is simple (setup in the normal peripherals.c init stuff):

void ADC0_IRQHANDLER(void)
{
g_LpadcInterruptCounter++;

if (LPADC_GetConvResult(LPADC_BASE, &g_LpadcResultConfigStruct, 0U))
{
g_LpadcConversionCompletedFlag = true;
}
SDK_ISR_EXIT_BARRIER;
}

Then every so often fire off: LPADC_DoSoftwareTrigger(LPADC_BASE, ADC0_BATTLOOK);

I never see an ISR here.

0 Kudos
1 Solution
1,165 Views
randylee
Contributor V

I got this working by dropping back to a fully polling (using the poling ADC example (which I missed the existence of to begin with)).  My application is quite simple so waiting for an ADC to finish isn't a problem.

One thing that I missed in the translation and is of *vital* import is the line:

POWER_DisablePD(kPDRUNCFG_PD_LDOGPADC);

Not having that always gives results that go 1/2 rail no matter what input you have. (see also Solved: LPC55S69 ADC always measuring half rail? - NXP Community)

So I've got this thing pulling some numbers... Now to get the numbers to line up correctly...

View solution in original post

0 Kudos
7 Replies
1,166 Views
randylee
Contributor V

I got this working by dropping back to a fully polling (using the poling ADC example (which I missed the existence of to begin with)).  My application is quite simple so waiting for an ADC to finish isn't a problem.

One thing that I missed in the translation and is of *vital* import is the line:

POWER_DisablePD(kPDRUNCFG_PD_LDOGPADC);

Not having that always gives results that go 1/2 rail no matter what input you have. (see also Solved: LPC55S69 ADC always measuring half rail? - NXP Community)

So I've got this thing pulling some numbers... Now to get the numbers to line up correctly...

0 Kudos
1,212 Views
randylee
Contributor V

In my init code (after the regular SDK init code), I do the following:

LPADC_Enable(LPADC_BASE,true); // turn us on and let's go then
LPADC_DoOffsetCalibration(LPADC_BASE);
LPADC_DoAutoCalibration(LPADC_BASE);

//
// Fire this off right off the bat so we have seomthing to look at later.
//
LPADC_DoSoftwareTrigger(LPADC_BASE, ADC0_BATTLOOK);

On the subsequent polling I break it and look at the registers which shows STAT showing Calibrated so I'm talking to the ADC.. it just doesn't seem to want to fire off a software trigger.  It is also showing it's doing nothing (STAT.ADC_ACTIVE is 0) (STAT.CMDACT is 0)

0 Kudos
1,200 Views
randylee
Contributor V

Interestingly enough, if I manually set some things:

/* Set conversion CMD configuration. */
// simpler configuration thing I think.
LPADC_GetDefaultConvCommandConfig(&mLpadcCommandConfigStruct);
mLpadcCommandConfigStruct.channelNumber = 3; // this is the pin we're on here
LPADC_SetConvCommandConfig(LPADC_BASE, ADC0_TAKEONE, &mLpadcCommandConfigStruct);

/* Set trigger configuration. */
LPADC_GetDefaultConvTriggerConfig(&mLpadcTriggerConfigStruct);
mLpadcTriggerConfigStruct.targetCommandId = ADC0_TAKEONE;
mLpadcTriggerConfigStruct.enableHardwareTrigger = false;
LPADC_SetConvTriggerConfig(LPADC_BASE, 0U, &mLpadcTriggerConfigStruct); /* Configurate the trigger0. */

(this taken from one of the examples) I then get a ISR but it can't get it to shut up (constant ISR).  Now these settings are the same as is in the peripheral.c file so I can only assume there is some order that isn't happening correctly to these.....

0 Kudos
1,174 Views
RaRo
NXP TechSupport
NXP TechSupport

Hello @randylee,

Looking at what you have done. In your init code, you are using LPADC_DoOffsetCalibration(LPADC_BASE) and LPADC_DoAutoCalibration(LPADC_BASE). Both of them were not previously added in your configuration trough ConfigTools, if you want them to be part of your code in peripherals.c, you should add them as follows:

RaulRomero_0-1674798373931.png

[ConfigTools. Peripherals Tool. ADC0. General configuration.]

Also, you should do a previous configuration before and after the ADC configuration. Looking at the examples, and User Manual, you should do something similar to this after the ADC initialization:

while(1)
{  
   LPADC_DoSoftwareTrigger(DEMO_LPADC_BASE, UM); /* UM is trigger mask, look at the following table for choose which trigger should be mask according your needs*/

   while (!g_LpadcConversionCompletedFlag)
   {
   }

   g_LpadcConversionCompletedFlag = false;
}

NOTE: This is for interrupt method.

 

RaulRomero_1-1674798373935.png

[LPC55S1x/LPC551x User Manual. Chapter 39: LPC55S1x/LPC551x 16-bit ADC controller (ADC)]

Hope this helps.

Best regards, Raul.

0 Kudos
1,165 Views
randylee
Contributor V

this is one key thing that I've missed here; this idea that this isn't an index but a bitmap. The tools do not make this clear at all and I think I had it as an index. Moving that around helps some

0 Kudos
1,193 Views
RaRo
NXP TechSupport
NXP TechSupport

Hello @randylee,

Could you please tell me which SDK and version are you using?

Also, could you please try out the LPADC examples? Are they running as intended in your microcontroller?

Related with your polling method, is better if you use LPADC_Init instead of LPADC_Enable, LPADC_Init have a few steps more and includes the LPADC_Enable. Nonetheless, if this init code you are showing includes the ADC0 configuration trough ConfigTools, LPADC_Enable is not needed.

Do you want polling or interrupt method for work with the ADC? In polling the IRQ Handler, EnableIRQ and LPADC_EnableInterrupts are not needed nor used.

Regards, Raul.

0 Kudos
1,165 Views
randylee
Contributor V
A couple of things here:
SDK is (as mentioned) SDK 2.11.0
It's a transliteration issue to use the examples with the tools as the examples don't actually use the config tool sets much. They tend to do a lot with directly programmatically setting up things so a person needs to go through those and figure out what the tools are doing and what needs to get done still. Easy to miss stuff, that's just the way that is.

My code was pulled from the examples almost verbatim. Except for the initialization stuff which I'm struggling with here apparently....
0 Kudos