AnsweredAssumed Answered

KL03 PWM bare copper code not working

Question asked by Steven Garfinkel on Mar 27, 2016
Latest reply on Mar 29, 2016 by Steven Garfinkel

I am adding a pwm function to my code and it compiles but no PWM comes out of the pin.  I previously used the pin for GPIO so I know the hardware is functional.

Here is the code for initialization, which in this version leaves the outputs on at 50% dutycycle:

 

void PWM_init ()

{

  //Select time clock source

  //Select 48 MHz clock

  SIM->SOPT2 |= SIM_SOPT2_TPMSRC(1);

 

  //Enable the Clock to the timer Modules

  SIM_SCGC6 |= SIM_SCGC6_TPM0_MASK;

  SIM_SCGC6 |= SIM_SCGC6_TPM1_MASK;

 

  //Set pins to timer outputs

//PHA_LO = 7, PHB_LO = 10, PHC_LO = 11

  PORTB->PCR[B_PHALO] = PORT_PCR_MUX(2);

  PORTB->PCR[B_PHBLO] = PORT_PCR_MUX(2);

  PORTB->PCR[B_PHCLO] = PORT_PCR_MUX(2);

 

  //Enable clock, divide by 1

  TPM0_SC = 4;

  TPM1_SC = 4;

 

  //pwm frequency to 48MHz/20kHz = 2400;

  TPM0_MOD = 2400;

  TPM0_C0SC = 20; //Edge PWM

  TPM0_C0V = 1200;

  //PHC_LO

  TPM0_C1SC = 20;

  TPM0_C1V = 1200;

  //PHB_LO

  TPM1_MOD = 2400;

  TPM1_C0SC = 20;

  TPM1_C0V = 1200;

  //PHA_LO

}

 

I would greatly appreciate it if someone would point me to what I am not doing correctly.

 

Thanks so much!

Outcomes