AnsweredAssumed Answered

KL27Z64VFM4 PWM duty pulse reversed

Question asked by Albert Zhou on Jun 20, 2019
Latest reply on Jun 24, 2019 by Albert Zhou

Hi, 

I configured PORTA1 as TPM2-CH(0) as the PWM pulse output and find a problem. The duty pulse level is reversed and I could not figure out what is going wrong.  I expected duty pulse 600 counts would be high and the rest time 6000 counts should be low but the real pulse out is reversed. 

 

Here is my code. Could some body help me to solve the problem? 

 

void PWM_init(void) //added by Albert 2019.06.17
{
CLOCK_EnableClock(kCLOCK_Tpm2);
SIM->SOPT2 = ((SIM->SOPT2 & ~SIM_SOPT2_TPMSRC_MASK) | SIM_SOPT2_TPMSRC(1U)); //=1=48MHz

PORTA->PCR[1] =BIT8+BIT9;
TPM2->SC &=~(BIT3+BIT4); //disable timer
TPM2->SC = TPM_SC_PS(0);//prescale =1 TPM2-SC=1 ,disable the counter
TPM2->CNT =0U; //clear counter value
TPM2->MOD =6600U; //Modulo, PWM=400Hz set PWM period 60K =400Hz
TPM2->CONTROLS[0].CnSC =BIT3+BIT5; //BIT3+BIT5=Edge Aligned duty cycle output; BIT2+BIT4 =50% toggle on match
TPM2->CONTROLS[0].CnV =600U; //duty pulse
TPM2->CONF =TPM_CONF_TRGSEL(0);
TPM2->SC |=BIT3; //Start timer
}
int main(void) {
/* Init board hardware. */
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();

// initialize the system
system_manager_init(&s_sensor);
PWM_init();
while(1) {
// and off we go...
// GPIOC->PTOR |=BIT4;//RS485_TX_ON;
system_manager_process(&s_sensor);
}
}

Outcomes