Writing TPM Registers During Interrupt - KL03 Freedom Board

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

Writing TPM Registers During Interrupt - KL03 Freedom Board

Jump to solution
971 Views
aeroengineer1
Contributor II

I have been playing with doing interrupts on my KL03 Freedom board.  I have it set up such that as it gets an interrupt on the PTB5 pin (not set in NMI mode) that it should change the duty cycle of the PWM to the Tri-Color LED.  This is shown in the code snippet below.

/*PORTB_IRQHandler*/

void PORTB_IRQHandler()

{

    unsigned int delay;

    unsigned long delayMax = 6500000;

    TPM0_C0V = 65000;

    TPM0_C1V = 500;

    TPM1_C0V = 500;

    for(delay = 0; delay <= delayMax; delay++);

    PORTB_ISFR=0xFFFFFFFF;

}

I initially thought that it was not getting into the ISR as I was not seeing a change in the LED color, though when running in debug mode, I could see that it was actually entering into the ISR.  As I stepped through lines 7-9, it was not changing the register value for these, I would have expected that the LED would change color through each step from 7-9, but it did not do that either.

Is there something that I am missing?

While I am at it, I notice that these pins seem to have an IRQ number listed next to them.  In the case of PTB5, the IRQ that is shown in the schematics is IRQ_12.  From what I can gather in the Reference Manual for the KL03, it seems that these are not so much as that they have their own ability to generate an interrupt on their own, but that it will set a flag specific for that pin, and that with the Port interrupt set, then I can go and search for this bit flag to determine which pin generated the interrupt even if the event that generated the interrupt was transient and is no longer present.  Is this a correct understanding?

​Adam

Tags (4)
0 Kudos
1 Solution
709 Views
DavidS
NXP Employee
NXP Employee

Hi Adam,

Can you post your project?

Typically you want to keep ISR as short as possible and not have long for loops inside it.

What is your TPM TPMx_CONF[DBGMODE] set too?

Regards,

David

View solution in original post

0 Kudos
3 Replies
710 Views
DavidS
NXP Employee
NXP Employee

Hi Adam,

Can you post your project?

Typically you want to keep ISR as short as possible and not have long for loops inside it.

What is your TPM TPMx_CONF[DBGMODE] set too?

Regards,

David

0 Kudos
709 Views
aeroengineer1
Contributor II

David,

I did check the setting that you recommended to check, and it was not set to the recommended setting.  I did change that.  It showed that the registers were updating after that, though oddly enough, when stepping through the code in debug mode it did change the color of the LED.

So before posting the code, I stripped it down to just basic code to ensure that there were no other issues.  I was able after that to update the TPM counter registers within the ISR loop.  I cannot say for certain what was causing the issue before.  Now that I have something that works, I might go back after it, but it was just some testing code to try and get various features of the device to work, so it was not critical to have that explicit piece of code working, only that I could figure out how to update the TPM counter registers within an ISR.

Adam

0 Kudos
709 Views
aeroengineer1
Contributor II

I will upload the project when I get home.  As for the long, poor "for" loop in the ISR, that was just there to do some debugging without having to actually run the debugger in KDS.  This should have changed the color of the LED for long enough that I should have been able to see it. 

When it was not happening, I went to the debugger to see what was happening in the registers, only to see that as I stepped through the code that these registers were not updating.  I will go and check that configuration you mentioned here in about an hour or so.

0 Kudos