ADC conversion is delayed

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

ADC conversion is delayed

741 Views
aditya_barve
Contributor II

Hello, 

I have PWM of 65kHz, on every falling of the pwm an interrupt is generated. Adc group 1 with 3 channels is configured, whose conversion is started from the PWM interrupt. 

I have set GPIO pin to high in the PWM ISR before starting the conversion, and set it too low at the end of conversion. 

The ADC conversion time observed is around 4.38us, having said that sometimes the adc conversion takes upto 11us. 

What could be the reason for such an abrupt delay in the adc conversion timings ?

aditya_barve_0-1769787866786.png

Is there anything wrong here ?

Thank you,

Aditya

Tags (1)
0 Kudos
Reply
3 Replies

691 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

from the scope screenshot, it appears that the ADC start is also delayed sometimes.
A possible reason could be the interrupt priorities of the enabled interrupts.
If an interrupt with a higher priority is being serviced, it can delay the execution of the lower‑priority interrupt, thus the ADC start or ADC end of conversion notification can be delayed.

If multiple interrupts are used in your system, check their priority configuration.

A recommended solution is to use hardware triggering via the BCTU, along with reading ADC results from the BCTU FIFO using DMA.
This can avoid interrupt‑based triggering and eliminates the observed timing jitter.

BR, Petr

0 Kudos
Reply

665 Views
aditya_barve
Contributor II

Hi PetrS,

As rightly mentioned, this happens due to multiple interrrupts. In this case as I am using a OS timing event driven by a PIT interrupt, the processing of this interrupt causes the delay. 

If I set the PIT interrupt as nested ISR, this behavior is improved with lesser delay but not solved. 

I am using MCAL S32K3_RTD_3_0_0 and find that the built in irq handlers take a long time to execute (approx 24-30us) when comparted to a 65kHz PWM signal (say ADC group Conversion completion every 15us).

From the measurements I find that the existing MCAL handlers cannot be used for such a task involving fast interrupts. Is the observation on NXP's side the same ?

Also, I would like to understand the interrupt latency time and time to execute to 2 successive interrupts whose interrupt status flag is already set. Once the PIT interrupt is serviced, it takes around 10us to service the next available interrupt. What is the status/ action of the controller during these 10us ?

 

Thank you,

Aditya

 

0 Kudos
Reply

570 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

Your observations are correct.
The delays you are seeing are caused by interrupt contention, especially with the PIT‑driven OS timing event. When the PIT interrupt is serviced, lower‑priority ISRs—including your PWM/ADC trigger logic—are delayed. Enabling nested interrupts reduces but cannot eliminate this behavior.

The execution time of the RTD (S32K3_RTD_3_0_0) interrupt handlers you measured (24–30 µs) is expected. The MCAL layers include additional software abstraction and OS hooks, which add latency. For this reason, RTD ISRs are not suitable for very fast, deterministic control loops running at 65 kHz (15 µs period).

For applications requiring precise timing, NXP recommends using hardware triggering via BCTU and reading ADC results from the BCTU FIFO. This removes the CPU and MCAL ISR latency from the sampling path and eliminates the timing jitter.

Regarding the ~10 µs gap before the next pending interrupt is serviced: this time is spent in interrupt entry/exit sequences, MCAL dispatching, OS hooks, etc. This is expected behavior under RTD with multiple active interrupts.

As an additional improvement, you may try building the project with different compiler optimization levels (e.g., -O2 or -Os). Higher optimization can reduce ISR execution time and may improve overall responsiveness, although it will not fully eliminate the fundamental latency limitations.
 
BR, Petr
0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2303904%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EADC%20conversion%20is%20delayed%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2303904%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%2C%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20PWM%20of%2065kHz%2C%20on%20every%20falling%20of%20the%20pwm%20an%20interrupt%20is%20generated.%20Adc%20group%201%20with%203%20channels%20is%20configured%2C%20whose%20conversion%20is%20started%20from%20the%20PWM%20interrupt.%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20set%20GPIO%20pin%20to%20high%20in%20the%20PWM%20ISR%20before%20starting%20the%20conversion%2C%20and%20set%20it%20too%20low%20at%20the%20end%20of%20conversion.%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20ADC%20conversion%20time%20observed%20is%20around%204.38us%2C%20having%20said%20that%20sometimes%20the%20adc%20conversion%20takes%20upto%2011us.%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20could%20be%20the%20reason%20for%20such%20an%20abrupt%20delay%20in%20the%20adc%20conversion%20timings%20%3F%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22aditya_barve_0-1769787866786.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22aditya_barve_0-1769787866786.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22aditya_barve_0-1769787866786.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22aditya_barve_0-1769787866786.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22aditya_barve_0-1769787866786.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F375020i96D120F7FB49F196%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22aditya_barve_0-1769787866786.png%22%20alt%3D%22aditya_barve_0-1769787866786.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EIs%20there%20anything%20wrong%20here%20%3F%3C%2FP%3E%3CP%3EThank%20you%2C%3C%2FP%3E%3CP%3EAditya%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2304644%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20ADC%20conversion%20is%20delayed%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2304644%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CDIV%3E%0A%3CP%3Efrom%20the%20scope%20screenshot%2C%20it%20appears%20that%20the%20ADC%20start%20is%20also%20delayed%20sometimes.%3CBR%20%2F%3EA%20possible%20reason%20could%20be%20the%20interrupt%20priorities%20of%20the%20enabled%20interrupts.%3CBR%20%2F%3EIf%20an%20interrupt%20with%20a%20higher%20priority%20is%20being%20serviced%2C%20it%20can%20delay%20the%20execution%20of%20the%20lower%E2%80%91priority%20interrupt%2C%20thus%20the%20ADC%20start%20or%20ADC%20end%20of%20conversion%20notification%20can%20be%20delayed.%3C%2FP%3E%0A%3CP%3EIf%20multiple%20interrupts%20are%20used%20in%20your%20system%2C%20check%20their%20priority%20configuration.%3C%2FP%3E%0A%3CP%3EA%20recommended%20solution%20is%20to%20use%20hardware%20triggering%20via%20the%20BCTU%2C%20along%20with%20reading%20ADC%20results%20from%20the%20BCTU%20FIFO%20using%20DMA.%3CBR%20%2F%3EThis%20can%20avoid%20interrupt%E2%80%91based%20triggering%20and%20eliminates%20the%20observed%20timing%20jitter.%3C%2FP%3E%0A%3CP%3EBR%2C%20Petr%3C%2FP%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2304768%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20ADC%20conversion%20is%20delayed%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2304768%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20PetrS%2C%3C%2FP%3E%3CP%3EAs%20rightly%20mentioned%2C%20this%20happens%20due%20to%20multiple%20interrrupts.%20In%20this%20case%20as%20I%20am%20using%20a%20OS%20timing%20event%20driven%20by%20a%20PIT%20interrupt%2C%20the%20processing%20of%20this%20interrupt%20causes%20the%20delay.%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20set%20the%20PIT%20interrupt%20as%20nested%20ISR%2C%20this%20behavior%20is%20improved%20with%20lesser%20delay%20but%20not%20solved.%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20using%20MCAL%26nbsp%3B%3CSPAN%3ES32K3_RTD_3_0_0%20and%20find%20that%20the%20built%20in%20irq%20handlers%20take%20a%20long%20time%20to%20execute%20(approx%2024-30us)%20when%20comparted%20to%20a%2065kHz%20PWM%20signal%20(say%20ADC%20group%20Conversion%20completion%20every%2015us).%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EFrom%20the%20measurements%20I%20find%20that%20the%20existing%20MCAL%20handlers%20cannot%20be%20used%20for%20such%20a%20task%20involving%20fast%20interrupts.%26nbsp%3BIs%20the%20observation%20on%20NXP's%20side%20the%20same%20%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EAlso%2C%20I%20would%20like%20to%20understand%20the%20interrupt%20latency%20time%20and%20time%20to%20execute%20to%202%20successive%20interrupts%20whose%20interrupt%20status%20flag%20is%20already%20set.%20Once%20the%20PIT%20interrupt%20is%20serviced%2C%20it%20takes%20around%2010us%20to%20service%20the%20next%20available%20interrupt.%20What%20is%20the%20status%2F%20action%20of%20the%20controller%20during%20these%2010us%20%3F%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSPAN%3EThank%20you%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EAditya%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2314477%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20ADC%20conversion%20is%20delayed%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2314477%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CDIV%3E%0A%3CP%3EYour%20observations%20are%20correct.%3CBR%20%2F%3EThe%20delays%20you%20are%20seeing%20are%20caused%20by%20interrupt%20contention%2C%20especially%20with%20the%20PIT%E2%80%91driven%20OS%20timing%20event.%20When%20the%20PIT%20interrupt%20is%20serviced%2C%20lower%E2%80%91priority%20ISRs%E2%80%94including%20your%20PWM%2FADC%20trigger%20logic%E2%80%94are%20delayed.%20Enabling%20nested%20interrupts%20reduces%20but%20cannot%20eliminate%20this%20behavior.%3C%2FP%3E%0A%3CP%3EThe%20execution%20time%20of%20the%20RTD%20(S32K3_RTD_3_0_0)%20interrupt%20handlers%20you%20measured%20(24%E2%80%9330%E2%80%AF%C2%B5s)%20is%20expected.%20The%20MCAL%20layers%20include%20additional%20software%20abstraction%20and%20OS%20hooks%2C%20which%20add%20latency.%20For%20this%20reason%2C%20RTD%20ISRs%20are%20not%20suitable%20for%20very%20fast%2C%20deterministic%20control%20loops%20running%20at%2065%E2%80%AFkHz%20(15%E2%80%AF%C2%B5s%20period).%3C%2FP%3E%0A%3CP%3EFor%20applications%20requiring%20precise%20timing%2C%20NXP%20recommends%20using%20hardware%20triggering%20via%20BCTU%20and%20reading%20ADC%20results%20from%20the%20BCTU%20FIFO.%20This%20removes%20the%20CPU%20and%20MCAL%20ISR%20latency%20from%20the%20sampling%20path%20and%20eliminates%20the%20timing%20jitter.%3C%2FP%3E%0A%3CP%3ERegarding%20the%20~10%E2%80%AF%C2%B5s%20gap%20before%20the%20next%20pending%20interrupt%20is%20serviced%3A%20this%20time%20is%20spent%20in%20interrupt%20entry%2Fexit%20sequences%2C%20MCAL%20dispatching%2C%20OS%20hooks%2C%20etc.%20This%20is%20expected%20behavior%20under%20RTD%20with%20multiple%20active%20interrupts.%3C%2FP%3E%0A%3CDIV%3EAs%20an%20additional%20improvement%2C%20you%20may%20try%20building%20the%20project%20with%20different%20compiler%20optimization%20levels%20(e.g.%2C%20-O2%20or%20-Os).%20Higher%20optimization%20can%20reduce%20ISR%20execution%20time%20and%20may%20improve%20overall%20responsiveness%2C%20although%20it%20will%20not%20fully%20eliminate%20the%20fundamental%20latency%20limitations.%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3EBR%2C%20Petr%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E