FTM Multi-channel capture of pwm input will cause code unstable?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

FTM Multi-channel capture of pwm input will cause code unstable?

1,255件の閲覧回数
erichsu
Contributor I

FTM0 channel pair 0 uses channels 0 and 1, channel pair 1 uses channels 2 and 3, but  capture of pwm input will cause program instability. Is the way to enable and disable interrupts incorrect?

erichsu_0-1619092967531.png

 

0 件の賞賛
5 返答(返信)

1,216件の閲覧回数
FelipeGarcia
NXP Employee
NXP Employee

Hi Eric,

Could you please let us know what is the part number you are using?

Best regards,

Felipe

0 件の賞賛

1,207件の閲覧回数
erichsu
Contributor I

FRDM-KV11Z

pin configuration:

erichsu_0-1619538131077.png

 

0 件の賞賛

1,194件の閲覧回数
FelipeGarcia
NXP Employee
NXP Employee

Hi Eric,

Thank you for your reply. I see you are using ftm_dual_edge_capture example from the SDK as a starting point. Is there an issue if you run example code with no modifications? Could you please provide what did you modify in the example? This will help us narrow down where the issue could be.

Additionally, could you please let me know what specific line of your code is the MCU halting?

Best regards,

Felipe

0 件の賞賛

1,177件の閲覧回数
erichsu
Contributor I

I see you are using ftm_dual_edge_capture example from the SDK as a starting point. Is there an issue if you run example code with no modifications? 

Ans: no problem

Could you please provide what did you modify in the example?

Ans: Modify in the exapmle

erichsu_0-1619964913036.png

erichsu_1-1619964946292.png

while(1)
{
// while (ftmFirstChannelInterruptFlag_PITCH != true)
//{
//}

// while (ftmSecondChannelInterruptFlag_PITCH != true)
// {
// }
#if 1
if ((ftmFirstChannelInterruptFlag_PITCH == true) && (ftmSecondChannelInterruptFlag_PITCH == true))
{
ftmFirstChannelInterruptFlag_PITCH = false;
ftmSecondChannelInterruptFlag_PITCH = false;

/* Clear first channel interrupt flag after the second edge is detected.*/
FTM_ClearStatusFlags(DEMO_FTM_BASEADDR, FTM_FIRST_CHANNEL_PITCH_FLAG);

/* Clear overflow interrupt flag.*/
FTM_ClearStatusFlags(DEMO_FTM_BASEADDR, kFTM_TimeOverflowFlag);
/* Disable overflow interrupt.*/
FTM_DisableInterrupts(DEMO_FTM_BASEADDR, kFTM_TimeOverflowInterruptEnable);

capture1Val_pitch = DEMO_FTM_BASEADDR->CONTROLS[BOARD_FTM_INPUT_CAPTURE_CHANNEL_PAIR_PITCH * 2].CnV;
capture2Val_pitch = DEMO_FTM_BASEADDR->CONTROLS[(BOARD_FTM_INPUT_CAPTURE_CHANNEL_PAIR_PITCH * 2) + 1].CnV;


/* FTM clock source is not prescaled and is
* divided by 1000000 as the output is printed in microseconds
*/
if(capture2Val_pitch > capture1Val_pitch)
{
//PRINTF("\r\nCapture value PITCH C(n)V=%x\r\n", capture1Val_pitch);
//PRINTF("\r\nCapture value PITCH C(n+1)V=%x\r\n", capture2Val_pitch);
pulseWidth_pitch =
(float)(((g_secondChannelOverflowCount_PITCH - g_firstChannelOverflowCount_PITCH) * 65536 + capture2Val_pitch - capture1Val_pitch) +
1) /
((float)FTM_SOURCE_CLOCK / 1000000);
//PRINTF("\r\nInput signals frequency = %f hz\r\n", 1/(pulseWidth_pitch*2)*1000000);
PRINTF("\r\nInput signals PITCH pulse width = %f us\r\n", pulseWidth_pitch);
}
g_secondChannelOverflowCount_PITCH = 0;
g_firstChannelOverflowCount_PITCH = 0;

/* Enable first channel interrupt */
FTM_EnableInterrupts(DEMO_FTM_BASEADDR, FTM_FIRST_CHANNEL_INTERRUPT_ENABLE_PITCH);

/* Enable second channel interrupt when the second edge is detected */
FTM_EnableInterrupts(DEMO_FTM_BASEADDR, FTM_SECOND_CHANNEL_INTERRUPT_ENABLE_PITCH);

/* Enable overflow interrupt */
FTM_EnableInterrupts(DEMO_FTM_BASEADDR, kFTM_TimeOverflowInterruptEnable);
}
#endif
if ((ftmFirstChannelInterruptFlag_YAW == true) && (ftmSecondChannelInterruptFlag_YAW == true))
{
ftmFirstChannelInterruptFlag_YAW = false;
ftmSecondChannelInterruptFlag_YAW = false;

/* Clear first channel interrupt flag after the second edge is detected.*/
FTM_ClearStatusFlags(DEMO_FTM_BASEADDR, FTM_FIRST_CHANNEL_YAW_FLAG);

/* Clear overflow interrupt flag.*/
FTM_ClearStatusFlags(DEMO_FTM_BASEADDR, kFTM_TimeOverflowFlag);
/* Disable overflow interrupt.*/
FTM_DisableInterrupts(DEMO_FTM_BASEADDR, kFTM_TimeOverflowInterruptEnable);

capture1Val_yaw = DEMO_FTM_BASEADDR->CONTROLS[BOARD_FTM_INPUT_CAPTURE_CHANNEL_PAIR_YAW * 2].CnV;
capture2Val_yaw = DEMO_FTM_BASEADDR->CONTROLS[(BOARD_FTM_INPUT_CAPTURE_CHANNEL_PAIR_YAW * 2) + 1].CnV;


/* FTM clock source is not prescaled and is
* divided by 1000000 as the output is printed in microseconds
*/
if(capture2Val_yaw > capture1Val_yaw)
{
//PRINTF("\r\nCapture value YAW C(n)V=%x\r\n", capture1Val_yaw);
//PRINTF("\r\nCapture value YAW C(n+1)V=%x\r\n", capture2Val_yaw);
pulseWidth_yaw =
(float)(((g_secondChannelOverflowCount_YAW - g_firstChannelOverflowCount_YAW) * 65536 + capture2Val_yaw - capture1Val_yaw) +
1) /
((float)FTM_SOURCE_CLOCK / 1000000);
//PRINTF("\r\nInput signals frequency = %f hz\r\n", 1/(pulseWidth_pitch*2)*1000000);
PRINTF("\r\nInput signals YAW pulse width = %f us\r\n", pulseWidth_yaw);
}
g_secondChannelOverflowCount_YAW = 0;
g_firstChannelOverflowCount_YAW = 0;

/* Enable first channel interrupt */
FTM_EnableInterrupts(DEMO_FTM_BASEADDR, FTM_FIRST_CHANNEL_INTERRUPT_ENABLE_YAW);

/* Enable second channel interrupt when the second edge is detected */
FTM_EnableInterrupts(DEMO_FTM_BASEADDR, FTM_SECOND_CHANNEL_INTERRUPT_ENABLE_YAW);

/* Enable overflow interrupt */
FTM_EnableInterrupts(DEMO_FTM_BASEADDR, kFTM_TimeOverflowInterruptEnable);
}
}

 

 

Additionally, could you please let me know what specific line of your code is the MCU halting?

Ans: Halting

erichsu_2-1619965272034.png

 

 

0 件の賞賛

1,117件の閲覧回数
FelipeGarcia
NXP Employee
NXP Employee

Hi Eric,

I would recommend to try to implement this step by step, have you tried to change the example to use channel 0 and 1 before incrementing to 4 channels? If this work then it could be an issue of interrupt management, if this does not work then it could be a configuration issue.

Best regards,

Felipe

0 件の賞賛