ADC interrupt and channel number

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

ADC interrupt and channel number

Jump to solution
3,179 Views
davithakobyan
Contributor III

I use the ADC hardware trigger example for S32K144 to read ADC using the PDB trigger.

Is it possible to selectively read ADC channels using a hardware trigger?

I have supplemented the ADC hardware trigger example with additional channel 4. The changes are shown in red:

// adConv1.c

/*! adConv1 configuration structure */
const adc_converter_config_t adConv1_ConvConfig0 = {
.clockDivide = ADC_CLK_DIVIDE_1, //ADC_CLK_DIVIDE_4,
.sampleTime = 255U,
.resolution = ADC_RESOLUTION_12BIT,
.inputClock = ADC_CLK_ALT_1,
.trigger = ADC_TRIGGER_HARDWARE,
.pretriggerSel = ADC_PRETRIGGER_SEL_PDB,
.triggerSel = ADC_TRIGGER_SEL_PDB,
.dmaEnable = false,
.voltageRef = ADC_VOLTAGEREF_VREF,
.continuousConvEnable = false,
.supplyMonitoringEnable = false,
};

adc_chan_config_t adConv1_ChnConfig0 = {
.interruptEnable = true,
.channel = ADC_INPUTCHAN_EXT12,
};


adc_chan_config_t adConv1_ChnConfig1 = {
.interruptEnable = true,
.channel = ADC_INPUTCHAN_EXT10,
};

 // main.c

void ADC_IRQHandler(void)
{
    /* Get channel result from ADC channel */
    ADC_DRV_GetChanResult(ADC_INSTANCE, 0U, (uint16_t *)&adcRawValue);
    /* Set ADC conversion complete flag */
    adcConvDone = true;
}

int main(void) {

...

ADC_DRV_ConfigConverter(ADC_INSTANCE, &adConv1_ConvConfig0);
ADC_DRV_AutoCalibration(ADC_INSTANCE);
ADC_DRV_ConfigChan(ADC_INSTANCE, 0UL, &adConv1_ChnConfig0);

ADC_DRV_ConfigChan(ADC_INSTANCE, 4UL, &adConv1_ChnConfig1);

...

}

Could people from NXP clarify the following questions?

1. I can see ADC_IRQHandler being triggered, but cannot find a way to get the channel number for which the ADC is triggered for. Is it possible to get the ADC channel number in the ADC_IRQHandler?

2. Will the ADC_IRQHandler be triggered only for channels 0 and 4 or it will span over all the channel from 0 to 4?

3. Is there a good and simple manual to better understand the ADC hardware working logic when it is coupled with PDB?

Thanks a lot for any clarification.

0 Kudos
1 Solution
3,163 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello @davithakobyan,

1.

You can read the flags like this:

danielmartynek_0-1624280723429.png

2.

Yes you can select which ADC channels get triggered.

danielmartynek_1-1624280865403.png

danielmartynek_2-1624280931217.png

In the example above, ADC0_ch0 is triggered when PDB_CNT == delayValue/2, and ADC0_ch4 when PDB_CNT == delayValue.

 

NOTE:

In the example, the adcConvDone flag can be set only once both ADC results are ready.

Otherwise it would trigger the PDB again before the ADC conversion is complete.

danielmartynek_3-1624281117284.png

3.

I believe these two documents can help you

https://www.nxp.com/docs/en/application-note/AN4822.pdf

https://www.nxp.com/docs/en/supporting-information/Programmable-Delay-Block-Training.pdf

 

Regards,

Daniel

 

 

 

 

View solution in original post

0 Kudos
6 Replies
1,663 Views
siiv
Contributor I

can you tell me how can we use adconvdone flag here and if it  posible attache your total snippet also thank you

0 Kudos
1,640 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @siiv,

Can you please create a new thread.

This one has been closed.

 

Regards,

Daniel

0 Kudos
3,164 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello @davithakobyan,

1.

You can read the flags like this:

danielmartynek_0-1624280723429.png

2.

Yes you can select which ADC channels get triggered.

danielmartynek_1-1624280865403.png

danielmartynek_2-1624280931217.png

In the example above, ADC0_ch0 is triggered when PDB_CNT == delayValue/2, and ADC0_ch4 when PDB_CNT == delayValue.

 

NOTE:

In the example, the adcConvDone flag can be set only once both ADC results are ready.

Otherwise it would trigger the PDB again before the ADC conversion is complete.

danielmartynek_3-1624281117284.png

3.

I believe these two documents can help you

https://www.nxp.com/docs/en/application-note/AN4822.pdf

https://www.nxp.com/docs/en/supporting-information/Programmable-Delay-Block-Training.pdf

 

Regards,

Daniel

 

 

 

 

0 Kudos
1,516 Views
siiv
Contributor I

actually i am  trying to get the tow adc values from the two channels of adc0 inn s32k144 but i got only one channel output, for another one i didnt find anymistake  in that.i attached my file below can you plz review it and tell me sollution. 

0 Kudos
2,874 Views
Alex19
Contributor II

Hello NXP Community,

I try to read the 2 ADC values from internal potentiometer and external, but i can't read the values, i attached my file, can you show me, where i miss something? Thank you 

Alex19_0-1643722449841.png

 

0 Kudos
3,138 Views
davithakobyan
Contributor III

Thanks a lot for very helpful response.

0 Kudos