Problem with simultaneous QTMR interrupts

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

Problem with simultaneous QTMR interrupts

Jump to solution
2,347 Views
seimonwilliams
Contributor I

I'm using a QTMR to capture an input. But I've noticed that if I have both the Compare and Edge interrupts enabled then, if both interrupts happen very close together, sometimes one of them isn't processed in my ISR.

I've attached a sample code. I started with the MCUXpresso i.MX RT1050 qtmr_timer sample.

TMR3.Timer0 is the primary timer that is used to capture the input.

TMR3.Timer1 is simulating my external hardware that is generating interrupts approx every 100us. It's output pin is fed back into Timer0's input capture pin.

TMR3.Timer2 has the same period as Timer0, but has the output enabled for debug on the oscilloscope.

In the ISR, if the Compare flag is set then for debug I also toggle a GPIO pin - this should follow the Timer2 output pin.

I've noticed that this GPIO pin sometimes doesn't toggle, this always seems to be when the Edge and Compare happen very close together.

The attached png file shows the scope waveform. Overview at the top and zoomed-in in the main area.

Blue is the Input Trigger / Timer1 output.

Yellow is Timer2 output. At this point the Purple should have gone high, but didn't until the next Compare interrupt.

Is there something not right with my ISR, or is this a known behaviour of the QTMR interrupts / status flags?

Thanks.

Labels (1)
Tags (4)
0 Kudos
1 Solution
2,169 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Seimon,

It seems this is a driver problem. QTMR_ClearStatusFlags() is used to clear status flag. No matter which flag should be cleared, it always write something both to SCTRL and CSCTRL.This is a problem. For example, line 465 read SCTRL, at this time IEF didn't come. But after several step, IEF come and reg don't know. So, at line 481, a zero is written to IEF. Then this interrupt is disappear.

My suggestion is

1. Split QTMR_ClearStatusFlags() into QTMR_ClearSCTRLStatusFlags() and QTMR_ClearCSCTRLStatusFlags().

2. Don't use SCTRL[IEF] and SCTRL[TCF] together. They are in same register and improper writting will cover each other. You can use SCTRL[IEF]+CSCTRL[TCF1].

3. Split QTMR_GetStatus() into QTMR_GetSCTRLStatus() and QTMR_GetCSCTRLStatus()

So, the isr code should looks like:

void TMRx_IRQHandler(void)

{

     if (QTMR_GetSCTRLStatus())

    {

        QTMR_ClearSCTRLStatusFlags()

        ....

    }

     if (QTMR_GetCSCTRLStatus())

    {

        QTMR_ClearCSCTRLStatusFlags()

        ....

    }

}

I'll report this problem. Hope we can see any improvement in next SDK version.

Regards,

Jing

View solution in original post

0 Kudos
2 Replies
2,170 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Seimon,

It seems this is a driver problem. QTMR_ClearStatusFlags() is used to clear status flag. No matter which flag should be cleared, it always write something both to SCTRL and CSCTRL.This is a problem. For example, line 465 read SCTRL, at this time IEF didn't come. But after several step, IEF come and reg don't know. So, at line 481, a zero is written to IEF. Then this interrupt is disappear.

My suggestion is

1. Split QTMR_ClearStatusFlags() into QTMR_ClearSCTRLStatusFlags() and QTMR_ClearCSCTRLStatusFlags().

2. Don't use SCTRL[IEF] and SCTRL[TCF] together. They are in same register and improper writting will cover each other. You can use SCTRL[IEF]+CSCTRL[TCF1].

3. Split QTMR_GetStatus() into QTMR_GetSCTRLStatus() and QTMR_GetCSCTRLStatus()

So, the isr code should looks like:

void TMRx_IRQHandler(void)

{

     if (QTMR_GetSCTRLStatus())

    {

        QTMR_ClearSCTRLStatusFlags()

        ....

    }

     if (QTMR_GetCSCTRLStatus())

    {

        QTMR_ClearCSCTRLStatusFlags()

        ....

    }

}

I'll report this problem. Hope we can see any improvement in next SDK version.

Regards,

Jing

0 Kudos
2,169 Views
seimonwilliams
Contributor I

Oh yes, that makes sense.

Thanks for your helpful suggestions, I hadn't noticed the CSCTRL[TCF1] flag.

Cheers,

Seimon

0 Kudos