Problem resetting FTM timers, what is the correct way to do it?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Problem resetting FTM timers, what is the correct way to do it?

跳至解决方案
1,387 次查看
zeal
Contributor II

I am using the ftm timer to measure rtos performance, I'm not using systick because it is reserved for the rtos.

 

The FTM timer is setup to use the core clock but the counter will overflow if performing multiple tests or doing stuff between tests. Therefore I want to reset it between tests.

 

If the clock overflows the counter stops, why doesn't it start over from 0?

If I try to reset the counter by using reset_ftm_timer() it stops.

If i run setup_ftm_timer twice, the counter stops.

 

What am I doing wrong?

 

 

 

#include "MK60N512MD100.h"

 

void setup_ftm_timer()
{

    SIM->SCGC6 |= SIM_SCGC6_FTM0_MASK;  
    FTM0->SC = 0x0;
    FTM0->MODE |= FTM_MODE_WPDIS_MASK;
    FTM0->MODE |= FTM_MODE_FTMEN_MASK;
    FTM0->CNT = 0x0;
    FTM0->CNTIN = 0;
    FTM0->SC = FTM_SC_CLKS(1);
}

 

void reset_ftm_timer() {
    FTM0->CNT = 0x0;
}

 

All input and feedback is appreciated

//Zeal

0 项奖励
回复
1 解答
1,041 次查看
zeal
Contributor II

 FTM0->MOD has to be set, I wrongly assumed leaving it to 0 would behave as setting it to 0xFFFF letting the 16 bit registers overflow..

在原帖中查看解决方案

0 项奖励
回复
1 回复
1,042 次查看
zeal
Contributor II

 FTM0->MOD has to be set, I wrongly assumed leaving it to 0 would behave as setting it to 0xFFFF letting the 16 bit registers overflow..

0 项奖励
回复