Hello Jorge,
I get your point.
In the conventional PWM, with a 50% duty cycle. There is a high for 25uSecs,interrupt, PWM low for 25uSecs,PWM high for 25uSecs,interrupt and so on and so forth.
So, measuring the relevant data during the low part of the PWM should not be a problem as the pwm low starts after the interrupt.
This is true if I select the following -
1) Edge-aligned PWM.
2) High-true pulses (clear Output on match, set Output on reload).
Hope this is clear.
I added this code -
TPM0_C0SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSA_MASK); // PWM - edge ,...etc for centre alligned mode //
TPM0_C2SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSA_MASK); // PWM - edge ,...etc for centre alligned mode //
TPM0_C4SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSA_MASK);
SO it should give me the needed thingy. But the pin is always high.
But this code -
TPM0_C0SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK); // PWM - edge ,...etc for centre alligned mode //
TPM0_C2SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK); // PWM - edge ,...etc for centre alligned mode //
TPM0_C4SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK);
works with PWM
The ISR is -
void FTM0_IRQHandler(void){
uint8_t rough = 0;
// added for wait of ADC //
// GPIOB_PSOR |= 0x00000018;
counterAdc++;
TPM0_SC &= ~TPM_SC_CMOD_MASK;
if((TPM0_SC & TPM_SC_TOF_MASK) == TPM_SC_TOF_MASK){
TPM0_SC |= TPM_SC_TOF_MASK;
}
adcFlag = 1;
TPM0_SC |= 8;
//adcChannel = "W";
// pitStart(2); //issue - probably 5 is not 5 us.
// commutationFlag = 1;
//pitStart(2);
}

Consider the above image.
The blue is the PWM. At each interrupt of the TPM0 I am making a pin high and low(the yellow pin).
TPM0_C0SC |= 0x28;
TPM0_C2SC |= 0x28;
TPM0_C4SC |= 0x28;
The code is for " Edge-aligned PWM High-true pulses (clear Output on match, set Output on reload)"
This is as per the datasheet and correct to my understanding. But the yellow toggle is done done properly. It
should rather be done at the end of the PWM on (so its a delay of 25uSecs). How is this so.
But, in case I change the code to
TPM0_C0SC |= 0x24;
TPM0_C2SC |= 0x24;
TPM0_C4SC |= 0x24;
I get the following image. The PWM never has a low period. Though it does do the interrupt action . Pls see the image below.

The blue is always high. The yellow (diagnostic) is manipulated in the ISR as expected. Strange behavior :smileyhappy:
The pwm initialisation code is as stated-
static void pwmInit(void)
{
// PWM //
//timer0 - PWM //
SIM_SOPT2 |= SIM_SOPT2_TPMSRC(1); // clk source for TPM0 and TPM1 as well
SIM_SCGC6 |= SIM_SCGC6_TPM0_MASK; // clk gated for TPM0
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK; // clk gated for PORTA
SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK; // clk gated for PORTB
TPM0_SC |= 3; // 8 prescale factor
SIM_SCGC5 |= 0x00000400; // gating of clock for PORTA/B //
// port settings //
PORTB_PCR7 &= PORT_PCR_MUX_MASK; // U1+
PORTA_PCR6 &= PORT_PCR_MUX_MASK; // V1+
PORTB_PCR11 &= PORT_PCR_MUX_MASK; // W1+
PORTB_PCR7 |= PORT_PCR_MUX(2); // U1+
PORTA_PCR6 |= PORT_PCR_MUX(2); // V1+
PORTB_PCR11 |= PORT_PCR_MUX(2); // W1+
// added 040412014 //
TPM0_SC &= ~(TPM_SC_CMOD_MASK); // timer off //
TPM0_CNT = 0; // counter value. NOTE :- when debug is aactive
TPM0_CNT = 0; // counter value. NOTE :- when debug is aactive
TPM0_CONF |= 192; // counter runs in debug mode as well //
TPM0_MOD = 131;
TPM0_SC |= TPM_SC_TOIE_MASK; // INTERRUPT ENABLED //
// -- add ends -- //
//timer0//
TPM0_CNT = 0; // counter value. NOTE :- when debug is aactive
TPM0_CONF |= 192; // counter runs in debug mode as well //
//Pins of PWM //
//--- alternate selection (all PWM are ALT2)---//
// TPM0_SC |= TPM_SC_CPWMS_MASK; // edge/centre alligned mode //
// TPM0_C0SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK); // PWM - edge ,...etc for centre alligned mode //
// TPM0_C2SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK); // PWM - edge ,...etc for centre alligned mode //
// TPM0_C4SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK);
TPM0_C0SC |= 0x24;
TPM0_C2SC |= 0x24;
TPM0_C4SC |= 0x24;
// TPM0_C0SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSA_MASK); // PWM - edge ,...etc for centre alligned mode //
// TPM0_C2SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSA_MASK); // PWM - edge ,...etc for centre alligned mode //
// TPM0_C4SC |= (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSA_MASK);
// TPM0_SC -- turn on timer //
}
Vinod.