Hi,
We are using an iMX8MN board with CM7 co-processor.
We have a radio chip connected to the GPT Input Capture 1 pin,
The signal from the radio chip is a pulse wave with a unknown and variable frequency.
We need to process the signal to get an array with the duration of each 0 and 1 transition
My idea was to use the GPT 1 in input capture mode configured to trigger an interrupt for both rising and falling edge and in the interrupt, get the duration of the bit (0/1) and store it in an array. (Should be made with DMA later..)
But I have some questions:
1. If we configure the GPT to trigger an interrupt for both rising/falling edge, how to know if the interrupt is triggered by a falling or rising edge ? (The SR register just contains "Input capture 1 Flag")
2. Is it normal that when the GPT is configured in restart mode the counter is not restarted when the "Input Capture event" is triggered ? (So to measure the duration of a bit we need to store the previous value ?)
3. Someone know where is defined/set the kCLOCK_IpgClk frequency ? I have something like 66666666Hz, i don't know where this value is set.
Here some example of code:
/* Freescale includes. */
#include "board.h"
#include "clock_config.h"
#include "fsl_debug_console.h"
#include "fsl_device_registers.h"
#include "fsl_gpio.h"
#include "fsl_clock.h"
#include "fsl_gpt.h"
#include "pin_mux.h"
volatile bool gptIsrFlag = false;
void GPT1_IRQHandler(void) {
/* Clear interrupt flag.*/
GPT_ClearStatusFlags(GPT1, kGPT_InputCapture1Flag);
gptIsrFlag = true;
/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F, Cortex-M7, Cortex-M7F Store immediate overlapping
exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U || __CORTEX_M == 7U)
__DSB();
#endif
}
void main(void) {
/* Init board hardware. */
/* M7 has its local cache and enabled by default,
* need to set smart subsystems (0x28000000 ~ 0x3FFFFFFF)
* non-cacheable before accessing this address region */
BOARD_InitMemory();
/* Board specific RDC settings */
BOARD_RdcInit();
BOARD_InitBootPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
uint32_t previousCapture = 0;
uint32_t captureVal = 0;
uint32_t currentCount = 0;
gpt_config_t gptConfig;
gptConfig.divider = 4095;
GPT_GetDefaultConfig(&gptConfig);
GPT_Init(GPT1, &gptConfig);
GPT_SetInputOperationMode(GPT1, kGPT_InputCapture_Channel1, kGPT_InputOperation_BothEdge);
GPT_EnableInterrupts(GPT1, kGPT_InputCapture1InterruptEnable);
EnableIRQ(GPT1_IRQn);
GPT_StartTimer(GPT1);
PRINTF("kCLOCK_IpgClk = %d Hz\n", CLOCK_GetFreq(kCLOCK_IpgClk));
PRINTF("kCLOCK_PerClk = %d Hz\n", CLOCK_GetFreq(kCLOCK_PerClk));
while (true) {
/* Check whether occur interupt */
if (true == gptIsrFlag) {
captureVal = GPT_GetInputCaptureValue(GPT1, kGPT_InputCapture_Channel1);
currentCount = GPT_GetCurrentTimerCount(GPT1);
PRINTF("Capture value = %d, currentCount = %d, difference: %d\n", captureVal, currentCount, captureVal - previousCapture);
previousCapture = captureVal;
gptIsrFlag = false;
} else {
__WFI();
}
}
}