One LPTMR as Trigger for two ADC_PAL

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

One LPTMR as Trigger for two ADC_PAL

Jump to solution
1,951 Views
EE_CW
Contributor III

Hi together

In a project I want to use the ADC_PAL component for group conversion.

For this I have have two ADC_PAL components with each a group with different adc channels.

Now I want to have these two groups triggered by a LPTMR component continuously. Both adc have the same settings, but adc1 is not running.

Is it not possible to use one LPTMR instance to trigger two ADC_PAL instances?

pastedImage_1.png

Here you can see the start of the continuous conversion.

pastedImage_2.png

pastedImage_3.png

Thanks for your help

regards

Mario

0 Kudos
1 Solution
1,593 Views
cosmindinu
NXP Employee
NXP Employee

Hi Mario,

The problem is caused by this line in the application code: 

status_t adcStartConversionCurrentAndVoltage(void)
{
[...]

state = ADC_EnableHardwareTrigger(&adc0_instance, ADC_GROUPINDEX_00);
state = state && ADC_EnableHardwareTrigger(&adc1_instance, ADC_GROUPINDEX_00);

The compiler optimizes out the second call to ADC_EnableHardwareTrigger(&adc1_instance, ADC_GROUPINDEX_00);

This most likely happens because the first call returns state == STATUS_SUCCESS, which is in fact 0x0000 => && operation with 0 will always be false, so no need to call ADC_EnableHardwareTrigger(&adc1_instance, ADC_GROUPINDEX_00);

Change the line to something like: 

state0 = ADC_EnableHardwareTrigger(&adc0_instance, ADC_GROUPINDEX_00);
state1 = ADC_EnableHardwareTrigger(&adc1_instance, ADC_GROUPINDEX_00);

if( state0 == STATUS_SUCCESS && state1 == STATUS_SUCCESS)

...

and the scenario will work fine.

Hope it helps,

Best regards,

Cosmin

View solution in original post

6 Replies
1,593 Views
cosmindinu
NXP Employee
NXP Employee

Hi Mario, Diana,

Sorry for the late response

ADC_PAL supports the scenario for using LPTMR to trigger conversions in parallel on both instances of ADC. Just make sure to uncheck Extension Supply Monitoring Enable for the adc_pal configured over ADC1, to avoid the DEV_ASSERT, as already mentioned by Diana.

Each ADC_PAL instance already uses 1 ADC instance and 1 PDB, so it is not possible/required to add them in the project when using also ADC_PAL. The ADC_PAL uses also TRGMUX to route LPTMR signal to the PDB and ADC.

Are you configuring ADC_PAL1 on ADC0 & PDB0 and ADC_PAL2 on ADC1 & PDB1? Also make sure you are calling ADC_Init and ADC_EnableHardwareTrigger, for each instance and group.

Could you please provide more info on the behavior which you are encountering? Or if possible attach the project?

Best regards,

Cosmin

0 Kudos
1,593 Views
EE_CW
Contributor III

Hi Cosmin

Thanks for your answer.

Yes, originally I configured ADC_PAL0 on ADC0 & PDB0 and ADC_PAL1 on ADC1 & PDB1.

I attached my sample project.

There I wait until a conversion of ADC0 or ADC1 is done.

I'm calling the ADC_init and ADC_EnableHardwareTrigger of both instances.

But it seems that the ADC1 doesn't work, because I never get the convDone-Flag.

The Callback-function of ADC1 also never gets called.

I tried also SW-Triggering. There I changed both ADC_PAL instances to SW Triggering. Then I called the ADC_StartGroupConversion() of both ADCs during LPTMR_ISR. But even then it didn't work. Only one ADC seemed to work.

Hope you can follow my descritions.

Regards

Mario

0 Kudos
1,594 Views
cosmindinu
NXP Employee
NXP Employee

Hi Mario,

The problem is caused by this line in the application code: 

status_t adcStartConversionCurrentAndVoltage(void)
{
[...]

state = ADC_EnableHardwareTrigger(&adc0_instance, ADC_GROUPINDEX_00);
state = state && ADC_EnableHardwareTrigger(&adc1_instance, ADC_GROUPINDEX_00);

The compiler optimizes out the second call to ADC_EnableHardwareTrigger(&adc1_instance, ADC_GROUPINDEX_00);

This most likely happens because the first call returns state == STATUS_SUCCESS, which is in fact 0x0000 => && operation with 0 will always be false, so no need to call ADC_EnableHardwareTrigger(&adc1_instance, ADC_GROUPINDEX_00);

Change the line to something like: 

state0 = ADC_EnableHardwareTrigger(&adc0_instance, ADC_GROUPINDEX_00);
state1 = ADC_EnableHardwareTrigger(&adc1_instance, ADC_GROUPINDEX_00);

if( state0 == STATUS_SUCCESS && state1 == STATUS_SUCCESS)

...

and the scenario will work fine.

Hope it helps,

Best regards,

Cosmin

1,593 Views
EE_CW
Contributor III

Hi Cosmin

Thanks for your answer.

With your suggestion it works. Thanks a lot.

regards

Mario

0 Kudos
1,593 Views
dianabatrlova
NXP TechSupport
NXP TechSupport

Hi Mario,

Please, accept my apologies for the delay. I do some tests with the adc_pal_s32k144 example. I have added the second pal component and I have used the same configuration for ADC1 such as for ADC0, with device triggering unit PDB1 and with unchecked Extension Supply Monitoring Enable which is only available on ADC0.

If it is enabled for ADC1, then a DEV_ASSERT in ADC_Init() will be triggered.

pastedImage_1.png

Is it your issue?

I hope it helps.

Best regards,

Diana

0 Kudos
1,593 Views
EE_CW
Contributor III

Hi Diana

Thank you for your answer.

For my project I use a LPTMR instance which should trigger both ADC at the same time.

With unchecked "Extension Supply Monitoring Enable" it still does not work.
Did you used a PDB Component for triggering the ADCs?

Because if I try to use a PDB instead of a LPTMR as trigger there is an error in the ADC_PAL instance that the PDB instance is already used by the PDB component:

pastedImage_1.png

Thanks for your feedback

regards

Mario

0 Kudos