I have written a code for blinking LED using PWM. But it is not working. Kindly help me to find the error with this code.
#include "MKL46Z4.h" int main() { // Set multiplexer to connect TPM0 Ch5 to PTD5 (giving chip specific value 3 to mux field) and Set multiplexer to connect TPM0 Ch2 to PTE29 PORTD->PCR[5] |= PORT_PCR_MUX(4); PORTE->PCR[29] |= PORT_PCR_MUX(3); //enabling clock to PORT D and E SIM->SCGC5 |= SIM_SCGC5_PORTD_MASK; SIM->SCGC5 |= SIM_SCGC5_PORTE_MASK;
// select MCGFLLCLK clock or MCGPLLCLK/2 by setting TPMSRC as 1 and among two clocks, //MCGPLLCLK/2 is selected by setting PLLFLL select as 1 SIM->SOPT2 |= SIM_SOPT2_TPMSRC(1) | SIM_SOPT2_PLLFLLSEL_MASK;
//enabling clock to TPM0 SIM->SCGC6 |= SIM_SCGC6_TPM0_MASK; //load mod value to counter (doubt:why this specific value is given) //TPM0->MOD = 60124; TPM0->MOD = 4095; //Select up counting (CPWMS=0) ,divide by 128 prescaler (PS=111) and clock mode is given in such as way that TPM counter increments on every TPM counter clock (CMOD=01) TPM0->SC |= (~TPM_SC_CPWMS_MASK | TPM_SC_CMOD(0) | TPM_SC_PS(7));
// Set channels 5 and 2 to edge-aligned high-true PWM. This is done by setting MSB:MSA as 10 and ELSB:ELSA as 10 TPM0->CONTROLS[5].CnSC= TPM_CnSC_MSB_MASK| TPM_CnSC_ELSB_MASK| TPM_CnSC_ELSA_MASK; TPM0->CONTROLS[2].CnSC= TPM_CnSC_MSB_MASK| TPM_CnSC_ELSB_MASK;
//Set control values for channel 5 and 2 TPM0->CONTROLS[5].CnV=0; TPM0->CONTROLS[2].CnV=0; TPM0->SC |=TPM_SC_CMOD(1); }
I have successfully coded blinking of LED and LCD. I have to generate PWM pulses for some application. To check it, i wrote the above program to blink LED using PWM.
In that case, try to debug the code