Use FTM0_CH0 to generate Pulse (Stepper Motor): Strange interrupt

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

Use FTM0_CH0 to generate Pulse (Stepper Motor): Strange interrupt

跳至解决方案
1,650 次查看
arnogir
Senior Contributor II

Hi,

I'm prototyping a Stepper command.

To do this, I'm using the  TWRK60 : K60N512VMD100

I created a simple bareboard project with Kds 2.0.0.

At this stage, I have an infinite loop which increment a counter i.

This work correctly!

Then I insert my own code to drive the FTM.

To do this, I want start to generate a pulse. Out = 1 when Timer CNT is between 1 to 100, when CNTIN = 0 and MOD = 0xFFFF

Then I'm using Combine Mode on FTM0 CH0/CH1 -> on FTM0_CH0 (PTC1 in Mux 4)

Bellow is the code I written to do this:

SIM->SCGC6 |= SIM_SCGC6_FTM0_MASK; FTM0->MODE = FTM_MODE_WPDIS_MASK | FTM_MODE_INIT_MASK ; FTM0->MODE |= FTM_MODE_FTMEN_MASK;  /* FTMEN bit is write protected. Can be written only when WPDIS = 1 */ FTM0->SC = (uint32_t)0x00UL;  /* Clear status and control register */ FTM0->CNTIN= (uint32_t)0x00UL;  /* Clear counter initial register */ FTM0->CNT = (uint32_t)0x00UL;  /* Reset counter register */ FTM0->CONTROLS[0].CnSC = (uint32_t)0x00UL;  /* Clear channel status and control register */ FTM0->CONTROLS[1].CnSC = (uint32_t)0x00UL;  /* Clear channel status and control register */ FTM0->MOD = 65535/* Set up modulo register */ FTM0->CONTROLS[0].CnSC = FTM_CnSC_ELSB_MASK;  FTM0->CONTROLS[1].CnSC = 0; //FTM_CnSC_CHIE_MASK;  FTM0->CONTROLS[0].CnV= 1;  FTM0->CONTROLS[1].CnV = 100; //debug AG//2;  // PORTC->PCR[1]= PORT_PCR_MUX(4); FTM0->OUTMASK |= FTM_OUTMASK_CH0OM_MASK; //debug AG | FTM_OUTMASK_CH1OM_MASK;   FTM0->COMBINE = FTM_COMBINE_COMBINE0_MASK; FTM0->SC= (uint32_t)(FTM_SC_CLKS(1) | FTM_SC_PS(0));

for (;;) { i++; }

 

When I comment line 24, the code is executed and loop in the infinite loop with I++.

If I uncomment line 24, Code will loop in startup_MK60D10.S:

  .size Default_Handler, . - Default_Handler

Than  I can't observe my signal on Pin PTC1!

Do you see any problem in my FTM initialization?

1 解答
1,422 次查看
arnogir
Senior Contributor II

Ok,

Just need to delete following line!

FTM0->OUTMASK |= FTM_OUTMASK_CH0OM_MASK; //debug AG | FTM_OUTMASK_CH1OM_MASK;

:smileyhappy:

在原帖中查看解决方案

3 回复数
1,422 次查看
santiago_gonzal
NXP Employee
NXP Employee

Hello,

Probably you need to enable clock to Port C.

Have a look at register "System Clock Gating Control Register 5" (SIM_SCGC5) in the chapter 12.2.12 of the Reference Manual to see what bit you need to enable in order to allow the clock to reach Port C.

Regards,

Santiago

1,422 次查看
arnogir
Senior Contributor II

Thank!

We never think to the simple port activation when starting from bareboard!

So I activate SCGC5 on PortC, but FTM0_CH0 pin never change  state!

Do you see any problem in the FTM0 initialization?

0 项奖励
回复
1,423 次查看
arnogir
Senior Contributor II

Ok,

Just need to delete following line!

FTM0->OUTMASK |= FTM_OUTMASK_CH0OM_MASK; //debug AG | FTM_OUTMASK_CH1OM_MASK;

:smileyhappy: