I am trying to toggle the red led using TPM0_interrupt on FRDM-KL43Z

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

I am trying to toggle the red led using TPM0_interrupt on FRDM-KL43Z

1,261 Views
priyankavorugan
Contributor II

HI,

I am trying to toggle the red led using TPM0 _interrupt on FRDM-KL43Z board. I selected MCGIRCLK(8MHZ) as TPM clock source.

Since the prescaler is 2, the TPM clock period is 0.25microseconds.I  am loading the TPM_MOD register with 8000 so that the ON and OFF period of led is 2ms .

But the problem is irrespective of the value loaded in the TPM_MOD register the ON and OFF periods are 16.80ms and 16ms respectively. The following is the code .

SIM_SCGC6 |= SIM_SCGC6_TPM0_MASK ; //enable the clock for TPM0 module

SIM_SOPT2        |= SIM_SOPT2_TPMSRC_MASK ; //MCGIRCLK as clock source

TPM0_CONF      |= TPM_CONF_DBGMODE_MASK ; // increment the counter in debug mode

TPM0_SC             |= TPM_SC_PS(1); //PRESCALER IS 2

TPM0_SC             |= TPM_SC_CPWMS_upcounting ; //up counting is selected(0x08u)

TPM0_CNT         |= TPM_CNT_COUNT_MASK ; //clear the counter value

TPM0_MOD       |= TPM_MOD_MOD(8000); // to get a delay of 2msec

TPM0_SC             |= TPM_SC_TOF_MASK ; // clear the interrupt flag

TPM0_SC             |= TPM_SC_TOIE_MASK; //enable the interrupt

TPM0_SC             |= TPM_SC_CMOD(2); //TPM counter increments on every TPM counter clock

5 Replies

741 Views
priyankavorugan
Contributor II

Hi Alice,

I have checked the clock.It is 8MHZ.I tried the same with LPTMR and PIT.It worked well.I am facing problem with TPM.

anyway i will go through it again.

Thankyou.

0 Kudos

741 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Priyanka,

Do you meaning no matter what the MOD register is , the interrupt timer is 16ms,

and you also be sure your code without any problem , maybe the TPM part have some

problem of your chip .

And you also can test my project.

BR

Alice

0 Kudos

741 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello

About "But the problem is irrespective of the value loaded in the TPM_MOD register the ON and OFF periods are 16.80ms and 16ms respectively."  Do you meaning no matter what the TPM_MOD is , the ON time is 16.8ms, the OFF time is 16ms,

or you want set the e ON and OFF periods are 16.80ms and 16ms  ?

Alice

0 Kudos

741 Views
priyankavorugan
Contributor II

since i have loaded the mod reg with 8000 , the ON and OFF period should be 2ms.But when i measure it using DSO i am getting 16.80 ms nd 16ms respectively.

0 Kudos

741 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Priyanka,

I create one TPM project about FRDM-KL43 on KDS refer to your parameter.

If you do not have the KDS IDE, i can show the registers:

selected MCGIRCLK(8MHZ) as TPM clock source;

pastedImage_0.png

pastedImage_1.png

the prescaler is 2;

TPM_MOD register with 8000;

pastedImage_2.png

and it can work well , each 2ms it will enter the interrupt and toggle the PTD5(LED) .

I check the waveform on the scope, it is right :

pastedImage_3.png

I also attached my project , you can use the KDS+KSDK to check it .

And about your code , please be sure whether the MCGIRCLK is 8M.

Hope it helps


Have a great day,
Alice

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