Hi,
Now I am working on FRDM-K64F to implement frequency measurement. I have tried different method ( single edge capture mode, dual edge capture mode, and GPIO interrupt) , but all the results are not satisfactory.
One of my implementation is :
base on my understanding, GPIO use system clock - 120MHz which could response faster interrupt.
but now I am facing an issue for this implementation. FTM interrupt can not be received once GPIO input signal frequency exceed 2.4MHz.
I think that because GPIO make system busy, so I change GPIO interrupt priority to 2 and set FTM interrupt priority to 1. In my opinion, GPIO interrupt should be preempted by FTM interrupt ( because FTM set to higher frequency). But the result is same as before : FTM interrupt still can not be received once GPIO input signal frequency exceed 2.4MHz.
Then I have set GPIO interrupt to lower frequency -> 256, but the result no different.
It seems like, whole system has been occupied by GPIO interrupt once the input frequency higher than 2.4MHz, but it doesn't make sense....
Does anyone can give me a help ?
Thanks & Best Regards
Joshua
Hello @Joshua_ZXR ,
Ok is good to understand better your application, I would rather suggest to use Callback functions instead of the IRQ Handler for both cases GPIO and FTM, this could help us to optimize.
Hello @Joshua_ZXR ,
I have a couple question regarding your case, I will appreciate if you could answer them.
Hi @nxf77486
Thank you for your fast response.
1) yes, FTM counter start after the first GPIO rising edge interrupt. In order to reduce ISR code size, a while loop has been used in the main thread to check counter value
GPIO IRQ handler :
void BOARD_SW_IRQ_HANDLER(void)
{
BOARD_INPUT_SIGNAL_PORT->ISFR = (1U << BOARD_INPUT_SIGNAL_PIN);
//FTM_StartTimer(FTM_BASEADDR, kFTM_SystemClock);
u32_cnt++;
}
main thread start FTM
while (0 == u32_cnt)
{
}
FTM_StartTimer(FTM_BASEADDR, kFTM_SystemClock);
is that because GPIO IRQ interrupt too frequent to stuck system in GPIO IRQ handler ? according to this understanding I have tried to start FTM in GPIO IRQ. But it will trigger hard fault ( bus fault) when function " FTM_StartTimer " be invoked in IRQ handler ...
2) Yes, the implementation working properly when input frequency <= 2.3MHz, and not working when input frequency >= 2.4MHz
Thanks & Best Regards
Joshua