I have tried the below code and it is working, it does not need to keep writing to the CNV register. I used IAR.
#include "common.h"
#include "sysinit.h"
#include "FTM_test.h"
#include "lpt.h"
#define PulseWTicks 100
unsigned int newtv;
volatile int i;
int main()
{
printf("Hello World!\n");
//led_blink_tower();
// ungate Flextimer
CCM->CCGR1 |= CCM_CCGR1_CG9(0x3);
// use "external" Fast OSC clock/2
CCM->CSCMR2 = (CCM->CSCMR2 & CCM_CSCMR2_FTM1_EXT_CLK_SEL_MASK) | CCM_CSCMR2_FTM1_EXT_CLK_SEL(2);
CCM->CSCDR1 |= CCM_CSCDR1_FTM1_CLK_EN_MASK;
FTM1->SC = (3<<3) // "ext" clock
| 7; // 1/128 divider
FTM1->CONTROLS[0].CnSC = 0x18; //output compare, set pin low on match
FTM1->CONTROLS[0].CnSC &= ~FTM_CnSC_CHF_MASK; // clear flag
newtv= FTM1->CONTROLS[0].CnV + PulseWTicks;
newtv &= 0xFFFF;
i = 0;
// do
// {
FTM1->CONTROLS[0].CnV = newtv;
i++;
/*}*/while(newtv != FTM1->CONTROLS[0].CnV);
FTM1->CONTROLS[0].CnV = newtv + 1;
i++;
/*}*/while(newtv + 1 != FTM1->CONTROLS[0].CnV);
return 0;
}
/* Blink LEDs on TWR-VF600 */
void led_blink_tower()
{
//Setup GPIO output on LED pins (PTB0-PTB3)
IOMUXC->SINGLE.PTB0 = IOMUXC_PTB0_DSE(0x1)| IOMUXC_PTB0_OBE_MASK; //enable GPIO output for PTB0
IOMUXC->SINGLE.PTB1 = IOMUXC_PTB1_DSE(0x1)| IOMUXC_PTB1_OBE_MASK; //enable GPIO output for PTB1
IOMUXC->SINGLE.PTB2 = IOMUXC_PTB2_DSE(0x1)| IOMUXC_PTB2_OBE_MASK; //enable GPIO output for PTB2
IOMUXC->SINGLE.PTB3 = IOMUXC_PTB3_DSE(0x1)| IOMUXC_PTB3_OBE_MASK; //enable GPIO output for PTB3
//Flash on and off LED's
while(1)
{
//Turn on LED's by driving 0 (active low)
GPIO0->PDOR=~(PIN(22)|PIN(23)|PIN(24)|PIN(25)); //corresponds with PTB0-PTB3
//Delay
time_delay_ms(1000);
//Turn off LED's by driving 1
GPIO0->PDOR=PIN(22)|PIN(23)|PIN(24)|PIN(25); //corresponds with PTB0-PTB3
//Delay
time_delay_ms(1000);
}
}