How to get the red led to work using pwm tpmo channel 0 on the kl25z board using keil ide

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

How to get the red led to work using pwm tpmo channel 0 on the kl25z board using keil ide

314 Views
oc989
Contributor I

I was wondering why my code isnt working to turn the red led on using tpmo channel 0 with pwm. the code i have is:

SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK;
SIM->SCGC6 |= SIM_SCGC6_TPM0_MASK;

PORTB->PCR[18] &=~PORT_PCR_MUX_MASK;
PORTB->PCR[18] |=PORT_PCR_MUX(3);


SIM->SOPT2 &= ~SIM_SOPT2_PLLFLLSEL_MASK;
SIM->SOPT2 |= SIM_SOPT2_TPMSRC(1);


TPM0->MOD = pwm_period-1;

TPM0->SC= TPM_SC_PS(0);
TPM0->CONF |= TPM_CONF_DBGMODE(3);

TPM0->CONTROLS[0].CnSC = TPM_CnSC_ELSA_MASK;


TPM0->CONTROLS[0].CnV = 0;

 

 

while(1)
{


TPM2->CONTROLS[0].CnV = 30;


}

Any help on what i need to change would help as i am new and still learning things

 

0 Kudos
1 Reply

300 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi 

Please download the SDK_2.2.0_FRDM-KL25Z from MCUXpresso SDK Builder.

The simple_pwm example in SDK_2.2.0_FRDM-KL25Z will show you how to light LEDRGB_GREEN(PTB19) TPM2_CH1. (The example is located at ...\SDK_2_2_0_FRDM-KL25Z\boards\frdmkl25z\driver_examples\tpm\simple_pwm\mdk)

simple_pwm MDK.png

The red led LEDRGB_RED is connect to PTB18 which is TPM2_CH0, please enable the clock gate of TPM2 instead of TPM0.

The Schematics of FRDM-KL25Z can be found here: Freedom Development Platform for Kinetis® KL14, KL15, KL24, KL25 MCUs


Best Regards,
Robin
-------------------------------------------------------------------------------
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