AnsweredAssumed Answered

Simple PWM pulse string on KEA128

Question asked by TOM SPARKS on Apr 9, 2020
Latest reply on May 27, 2020 by TOM SPARKS

I'm having an issue getting this to work on a FRDM-KEAZ1284Q80 evaluation board.
I'm attempting to make a simple unending pulse train of square waves at 1kHz.
It does make pulses but in an odd pattern. 

It also will not produce a complementary pulse train on channel 0, only channel 1.
Here is the code I'm using:

/* START CODE HERE:*/


/* SET UP CLOCKS, GPIO, AND FTM TO MAKE A SIMPLE PULSE TRAIN*/


#include "derivative.h" // include KEA128 declarations

 

int main(void)
{

GPIOC_PIDR |= 0x030000; // PTC0 and PTC1 are NOT inputs
GPIOC_PDDR |= 0x030000; // PTC0 and PTC1 ARE outputs
/*--------------------------------------------------------------*/
SIM_PINSEL1 &= ~(0x0F); // [FTM2PS1] [FTM2PS0] Output to PTC1 AND PTC0
SIM_SCGC |= 0x80; // [FTM2] Provide system clock to FTM2
/*--------------------------------------------------------------*/
FTM2_MODE |= (0x04); // [WPDIS] Disable write-protect
/*--------------------------------------------------------------*/
FTM2_MODE &= ~(0x01); // [FTMEN] Make sure TPM is selected
FTM2_MODE |= 0x02; // [INIT] Initialize output
FTM2_SC |= 0x0F; // [CLKS] [PS] Clock Select PreScaler set to divide by 128
FTM2_CONF |= 0x0C0; // [BDMMODE] Run in debug mode
FTM2_CNTIN |= 0x00; // [INIT] Initial Value Of The FTM Counter
FTM2_CNT |= 0x01; // [COUNT] Initialize CNTIN
FTM2_OUTINIT |= 0x03; // [CH0OI](0) [CH1OI](1) Set initial values in channels
FTM2_MOD |= 0x0FFFF; // [MOD] Modulo value beyond match value so no flag set
FTM2_C0SC|= 0x2F; // [MSB] [MSA] [ELSB] [ELSA] CH0
FTM2_C1SC |= 0x2F; // [MSB] [MSA] [ELSB] [ELSA] CH1
FTM2_C0V |= 0x0177; // [VAL] Match value
FTM2_C1V |= 0x0177; // [VAL] Match value
/*--------------------------------------------------------------*/
FTM2_FMS |= 0x40; // [WPEN] Re-enable write-protect

for(;;) {} // Infinite loop

return 0;
}


/* END CODE HERE*/

 

I've tried many variations upon what you see here with only slightly different results.

 

I've tried commenting out all code that did not significantly change the result. Nothing different happened. 

 

It seems like I'm missing something pretty fundamental about the KE/KEA or the FTM/TPM, but I've searched all over the Reference Manual and I can't figure out what it is.  Does anyone see anything wrong here? 

 

Thank you for reading.

Outcomes