Interrupt for Capture on Standard Timer 0 not being called

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

Interrupt for Capture on Standard Timer 0 not being called

Jump to solution
1,891 Views
safiullah_hussa
Contributor III

I am trying to initiate a Timer (Timer 0) interrupt on the rising edge of a pulse.

The timer is in the Timer mode so as to count the clocks between the rising edges.

Following is my initialization code

   // Init board hardware.
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
    BOARD_InitBootPeripherals();
   // Init FSL debug console.
    BOARD_InitDebugConsole();
 CLOCK_AttachClk(kFRO_HF_to_CTIMER0);
    PRINTF("Configuring Timer 0...\n");
    const uint32_t port1_pin26_config = ( //Configure as CT_INP3
              IOCON_FUNC3 |
                                            // No addition pin function
           IOCON_MODE_PULLDOWN |
                                            // Standard mode, output slew rate control is enabled
                                            IOCON_PIO_SLEW_STANDARD |
                                            // Input function is not inverted
                                            IOCON_PIO_INV_DI |
                                            // Enables digital function
                                            IOCON_PIO_DIGITAL_EN |
                                            // Open drain is disabled
                                            IOCON_PIO_OPENDRAIN_DI);
    // PORT1 PIN26
    IOCON_PinMuxSet(IOCON, 1, 26, port1_pin26_config);
    INPUTMUX_Init(INPUTMUX);
    INPUTMUX_AttachSignal(INPUTMUX, 1, kINPUTMUX_CtimerInp3ToTimer0Captsel);
    INPUTMUX_Deinit(INPUTMUX);
    CTIMER_GetDefaultConfig(&g_ctimer_config);
    CTIMER_Init(CTIMER0, &g_ctimer_config);
    CTIMER0->CTCR &= 0x0000000F;
    CTIMER0->CTCR |= ((0x2 << 5) | (1 << 4));
    CTIMER_RegisterCallBack(CTIMER0, &g_ctimer_callback[0], kCTIMER_SingleCallback);
    CTIMER_SetupCapture(CTIMER0, kCTIMER_Capture_1, kCTIMER_Capture_RiseEdge, true);
    CTIMER_EnableInterrupts(CTIMER0, kCTIMER_Capture1InterruptEnable);
    CTIMER_StartTimer(CTIMER0);
However, The callback function for the capture is never called.
The callback code looks like this
void ctimer_capture_callback(uint32_t arg_flags);
void ctimer_match_callback(uint32_t arg_flags);

/******************************************************************************
 * Global Variables
 *****************************************************************************/
ctimer_config_t g_ctimer_config;
ctimer_callback_t g_ctimer_callback[] = {NULL, NULL, NULL, NULL, NULL, ctimer_capture_callback, NULL, NULL};
uint32_t g_timer_val = 0;
uint8_t g_valid_lock = 0;
/******************************************************************************
 * Function Definition
 *****************************************************************************/
void ctimer_capture_callback(uint32_t arg_flags)
{
 if (CTIMER_GetStatusFlags(CTIMER0) & kCTIMER_Capture1InterruptEnable){ //Breakpoint here
//...
}
}
The code never reaches the breakpoint ( if (CTIMER_GetStatusFlags(CTIMER0) & kCTIMER_Capture1InterruptEnable){ line) However the timer does get reset on capture so I believe the reset on capture functionality is working.
What am I doing wrong?
Labels (2)
0 Kudos
1 Solution
1,674 Views
safiullah_hussa
Contributor III

Ok so I fixed the "unable to program" issue and the original issue. Let run down the steps I took for each.

So for the "unable to program" issue. After a lot of googling I found https://community.nxp.com/thread/389040 and this https://community.nxp.com/thread/389112

The key line to look for was the:

Wire Ack Fault

in the console window.

So I did the ISP reset debug by holding down the ISP reset push button on my board, and then clicking the GUI Flash tool. Pressing run erased the chip successfully. Once done I released the ISP Reset button.

Once I regained control of the chip, I saw the sample for match interrupt and I realized that they left the first element blank so I recalculated the index of the capture 1 and rewrote this line to:

ctimer_callback_t g_ctimer_callback[] = {NULL, NULL, NULL, NULL, NULL, NULL, ctimer_capture_callback, NULL};

The callback is now at the 6 index position (when starting from 0). This fixed the problem for me.

View solution in original post

0 Kudos
9 Replies
1,675 Views
safiullah_hussa
Contributor III

Ok so I fixed the "unable to program" issue and the original issue. Let run down the steps I took for each.

So for the "unable to program" issue. After a lot of googling I found https://community.nxp.com/thread/389040 and this https://community.nxp.com/thread/389112

The key line to look for was the:

Wire Ack Fault

in the console window.

So I did the ISP reset debug by holding down the ISP reset push button on my board, and then clicking the GUI Flash tool. Pressing run erased the chip successfully. Once done I released the ISP Reset button.

Once I regained control of the chip, I saw the sample for match interrupt and I realized that they left the first element blank so I recalculated the index of the capture 1 and rewrote this line to:

ctimer_callback_t g_ctimer_callback[] = {NULL, NULL, NULL, NULL, NULL, NULL, ctimer_capture_callback, NULL};

The callback is now at the 6 index position (when starting from 0). This fixed the problem for me.

0 Kudos
1,674 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hi Safi,

I'm glad you were able to resolve both issues. If you have any other questions please dont hesitate to ask.

Best Regards,

Sabina

0 Kudos
1,674 Views
safiullah_hussa
Contributor III

Thanks! will do!

0 Kudos
1,674 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hi Safi,

I've been trying with different combinations to see which do work and which don't. So to answer the following question:

So Single Callback will always be at the "0" index position of the s_ctimerCallback.

That is correct if you state a single callback, you should put your callback in position 0. However if you use the single callback I would recommend to leave it like this to reduce errors ctimer_callback_t g_ctimer_callback[] = {ctimer_capture_callback};

or you can also state a Multiple Callback and leave it how you have it originally since the order you have it is correct as per the manual for capture channel 1.

pastedImage_3.png

So far I've not been able to replicate the behavior you are experincing.

Is it possible for you to attach your project? This way I can see excatly what you are seeing and I can better assist you.

Also note that LPCOpen and the SDK are completly different, so I wouldn't recommend to compare the two.

Thank you,

Sabina

0 Kudos
1,674 Views
safiullah_hussa
Contributor III

I think by chip is busted. Now I programmed the board (no modifications to the code) and now the chip wont respond. I tried erasing the flash and I get this.

Executing flash operation 'Erase' (Erase flash) - Sun Jun 23 14:03:24 PKT 2019
Checking MCU info...
Scanning for targets...
Executing flash action...
MCUXpresso IDE RedlinkMulti Driver v10.3 (Feb  7 2019 22:50:02 - crt_emu_cm_redlink.exe build 760)
(  0) Reading remote configuration
Wc(03). No cache support.
Found chip XML file in C:/Users/safiu/Documents/MCUXpressoIDE_10.3.1_2233/workspace/LPC55S69_Project/Debug\LPC55S69.xml
(  5) Remote configuration complete
Reconnected to existing link server
Connecting to probe 1 core 0 (using server started externally) gave 'Ee(42). Could not connect to core.'
Connecting to probe 1 core 0 (using server started externally) gave 'Ee(42). Could not connect to core.'
Connecting to probe 1 core 0 (using server started externally) gave 'Ee(42). Could not connect to core.'
Server OK but no connection to probe 1 core 0 (after 3 attempts) - Ee(42). Could not connect to core.
Failed on connect: Ee(42). Could not connect to core.
No connection to chip's debug port
(100) Target Connection Failed
Unable to perform operation!
Command failed with exit code 1
0 Kudos
1,674 Views
safiullah_hussa
Contributor III

I can't  over an open forum, even though it's a fairly basic code.

Please email me at safiullah(dot)hussaini(at)gmail(dot)com and I can attach it in reply. Or if you have any alternative mechanism for sharing, please let me know.

Regards,

Safi

Thanks in advance!

0 Kudos
1,674 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello Safiullah,

So far I've noticed that your RegisterCallback is stating  kCTIMER_SingleCallback. This is when you only have one callback for the timer, but in your array you have {NULL, NULL, NULL, NULL, NULL, ctimer_capture_callback, NULL, NULL}; This means that there are multiple callbacks available for your timer, regardless that the rest are set as NULL.

Can you please try to change your RegisterCallback to  kCTIMER_MultipleCallback and check if your breakpoint works.

Also can you please let me know the microcontroller that you are working with in case you have further questions. 

Let me know your results,

Sabina

0 Kudos
1,674 Views
safiullah_hussa
Contributor III

Hi Sabrina,

I also notice that the bit in the IABR0 (NVIC->IABR[0]) bit 10 does not go high, however the CR1 (CTIMER0->CR[1]) seems to get loaded at the positive edge.

I checked by varying the pulse width of the input pulse on CT_INP3/P1_26, and the CR1 value changes correspondingly.

This is very weird.

Regards,

Safi

0 Kudos
1,674 Views
safiullah_hussa
Contributor III

Sorry, in my excitement I believe I forgot to mention the chip. I am using the LPC55S69 on the EVK.

So Single Callback will always be at the "0" index position of the s_ctimerCallback.

If I intend to use the single callback for capture, how would that work? Similar to LPCOpen?

But to check, I also placed a breakpoint at the start of CTIMER_GenericIRQHandler() as well. I think it too is not being invoked.

And please call me Safi.

Regards,

Safi

0 Kudos