Using Ctimer with callback

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

Using Ctimer with callback

2,454 Views
angiey0017
Contributor III

Hi,

If we are using Ctimer match0 callback, should we use IRQ handler, to invoke

interrupt? It's really confusing to use both, and in the callback there

is no priority to define, in the sdk sample codes they have given callbacks,

but when implemented for the application won't get the result as expected,

kindly advice on using callbacks, and to invoke interrupt in Ctimer.

Thank you

Labels (1)
7 Replies

2,169 Views
jeremyzhou
NXP Employee
NXP Employee

Hi angiey y,

Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
1) If we are using Ctimer match0 callback, should we use IRQ handler, to invoke interrupt?
-- Yes, when Ctimer match interrupt happens, it will enter the CTIMERn_DriverIRQHandler() function at first, then trigger the CTIMER_GenericIRQHandler() function, next will call the corresponded callback function, hope the clarification helps.

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

2,169 Views
angiey0017
Contributor III

Hi,

Thanks for the response.

Yes it's clarified that need to use Ctimer IRQ handler to invoke interrupt, but for my application

I have used CTIMER_GenericIRQHandler() function, but interrupt is not invoking, 

can you share any reference links or sample code of using callback function in IRQ handler,

it will help to understand and implement the process.

Thank you

0 Kudos

2,169 Views
jeremyzhou
NXP Employee
NXP Employee

Hi angiey y,

Thanks for your reply.
There's a simple_match_interrupt demo in the SDK library, and the demo demonstrates usage of the SDK CTimer driver with interrupt callback functions, so please refer to it for details.

SDK library:

https://mcuxpresso.nxp.com/en/welcome

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

2,169 Views
angiey0017
Contributor III

Hi,

I tried the above sample code, and there is only register callback function in it,

so by referring MRT sample code, added IRQ handler and added the process

for enabling interrupts, but when the enable interrupts and driver IRQ handler function

called, if this interrupt register[in Ctimer] not used also the ctimer bit[P0.28] port pin keeps on toggling,

means in the code the interrupt is still not invoked.

Similarly I tested for SCtimer where only callbacks given in the demo code, and interrupt

enable register not used, so after adding it, only when the interrupt is enabled the port pin

is toggling[for testing purpose used inside the IRQ] , so in this interrupt is invoked.

I need to run 2 interrupts concurrently, one for PWM and one for timer, for timer i'm using MRT

and it works fine, but for PWM i'm getting the individually frequency required, but for to develop

further for my application , I require the interrupt to be invoked in Ctimer, which is not happening,

kindly suggest on how to invoke the interrupt in ctimer, in match interrupt demo only register callback function

is there, but not given how to enable interrupts, kindly suggest on this.

Thank you

0 Kudos

2,169 Views
jeremyzhou
NXP Employee
NXP Employee

Hi angiey y,

Thanks for your reply.

After running the simple_match_interrupt demo, when Ctimer match interrupt happens, it will enter the CTIMERn_DriverIRQHandler() function at first, then trigger the CTIMER_GenericIRQHandler() function, next will call the corresponded callback function.
The Ctimer interrupt definitely would be invoked, so I'm not clear with your statement " in match interrupt demo only register callback function is there".
Maybe you can try to refer to the code bundle library which is easier to understand versus the SDK.

pastedImage_2.png

Have a great day,
TIC

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

2,169 Views
angiey0017
Contributor III

Thank you for the response.

Referring to the match interrupt demo, below are the functions implemented to enable

interrupt,i.e., after Ctimer_RegisterCallback function as given below:

 1.   CTIMER_RegisterCallBack(CTIMER, &ctimer_callback_table[0], kCTIMER_MultipleCallback);

 2.   CTIMER_EnableInterrupts(CTIMER,kCTIMER_Match0InterruptEnable);//added this line
 3.   EnableIRQ(CTIMER0_IRQn);//Added this line
 4.   CTIMER_StartTimer(CTIMER);

Above is the part of the code, where I have added line 2 and 3 to enable interrupts, but if it's not used

also pwm is generating, and is it fine if we use--> void pwm_match_callback(uint32_t flags)..

Since after calling Register callback function, and making toggling of led inside the pwm_match_callback

function, only ON_board led will toggle[Red, green ON BOARD LED'S], external port pin connected and other

parameters passed inside the function won't work, tried after changing in PIN_MUX.c and PIN_MUX.h library file.

And in code bundle library initially I tried developing our application using code bundle library codes,

but only led_demo sample worked, and not got expected result from the other demo codes.

As I checked again with Ctimer demo sample[code bundle library], after flashing the code to MCU and resetting

the MCU, the pwm wont toggle on the OUT_PORT bit P0.25.

Is the process i'm working on using SDK demo for ctimer i.e., I have mentioned in the callback function is correct?

0 Kudos

2,169 Views
jeremyzhou
NXP Employee
NXP Employee

Hi angiey y,

Thanks for your reply.
1) Is the process i'm working on using SDK demo for ctimer i.e., I have mentioned in the callback function is correct?
-- Yes, and you can refer to simple_pwm_interrupt to learn how the register the pwm_match_callback() correctly.


Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------