Hi,
As explained here: https://community.nxp.com/t5/i-MX-Processors/IMX8MN-GPT-Capture-Input-mode-Detect-rising-or-falling-...
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
As it is not possible to do it with GPT only (for the reasons explained in the other issue), I am using a GPIO interrupt and in this interrupt i read the CNT register of the GPT to store the timing of each fronts and then calculate the duration of each levels.
I am using the GPT as a simple counter.
Here is my code:
#define RADIO_GPT_CLOCK_HZ (24000000.0)
#define RADIO_GPT_CLOCK_DIV (24.0)
#define US_PER_TICKS ((1.0 / (RADIO_GPT_CLOCK_HZ / RADIO_GPT_CLOCK_DIV)) * 1000.0 * 1000.0)
void gpt_conf(void)
{
gpt_config_t gptConfig;
GPT_GetDefaultConfig(&gptConfig);
gptConfig.clockSource = kGPT_ClockSource_Periph;
gptConfig.divider = RADIO_GPT_CLOCK_DIV;
GPT_Init(RADIO_GPT, &gptConfig);
GPT_StartTimer(RADIO_GPT);
GPT_SetClockSource(RADIO_GPT, kGPT_ClockSource_Periph);
}
My objective is to get a tick of GPT every 1 us
The input signal that I measure is 1200uS at 1 and 18800 at 0
When I test with a reference PWM signal in input, I get the correct durations if in my defines i use:
#define RADIO_GPT_CLOCK_HZ (24000000.0)
#define RADIO_GPT_CLOCK_DIV (24.0)
I <RADIO>: samplesConverted[53]: level: 0, timestamp: 18800
I <RADIO>: samplesConverted[54]: level: 1, timestamp: 1200
I <RADIO>: samplesConverted[55]: level: 0, timestamp: 18799
I <RADIO>: samplesConverted[56]: level: 1, timestamp: 1200
I <RADIO>: samplesConverted[57]: level: 0, timestamp: 18800
I <RADIO>: samplesConverted[58]: level: 1, timestamp: 1200
I <RADIO>: samplesConverted[59]: level: 0, timestamp: 18800
I <RADIO>: samplesConverted[60]: level: 1, timestamp: 1200
I <RADIO>: samplesConverted[61]: level: 0, timestamp: 18800
I <RADIO>: samplesConverted[62]: level: 1, timestamp: 1200
I <RADIO>: samplesConverted[63]: level: 0, timestamp: 18799
But If I put this:
#define RADIO_GPT_CLOCK_HZ (66666666.0)
#define RADIO_GPT_CLOCK_DIV (67.0)
Then I get realy wrong durations, for example I get:
I <RADIO>: samplesConverted[46]: level: 1, timestamp: 432
I <RADIO>: samplesConverted[47]: level: 0, timestamp: 6767
I <RADIO>: samplesConverted[48]: level: 1, timestamp: 432
I <RADIO>: samplesConverted[49]: level: 0, timestamp: 6767
I <RADIO>: samplesConverted[50]: level: 1, timestamp: 432
I <RADIO>: samplesConverted[51]: level: 0, timestamp: 6767
I <RADIO>: samplesConverted[52]: level: 1, timestamp: 432
I <RADIO>: samplesConverted[53]: level: 0, timestamp: 6767
I <RADIO>: samplesConverted[54]: level: 1, timestamp: 432
I <RADIO>: samplesConverted[55]: level: 0, timestamp: 6767
I <RADIO>: samplesConverted[56]: level: 1, timestamp: 432
I <RADIO>: samplesConverted[57]: level: 0, timestamp: 6767
I <RADIO>: samplesConverted[58]: level: 1, timestamp: 432
I <RADIO>: samplesConverted[59]: level: 0, timestamp: 6767
I <RADIO>: samplesConverted[60]: level: 1, timestamp: 432
I <RADIO>: samplesConverted[61]: level: 0, timestamp: 6767
I <RADIO>: samplesConverted[62]: level: 1, timestamp: 432
I <RADIO>: samplesConverted[63]: level: 0, timestamp: 6768
My issue is just to know why in my calculations i have to count with 24Mhz frequency if the GPT is using a clock at 66Mhz ?
Is there a bug somewhere in SDK ?
Solved! Go to Solution.
Hello,
Asking internally, due to errata e50068 AUDIO: Incorrect 24 MHz clock source at Audio Clock Mux input, that affects some i.MX8 family and also affects GPT module. The BSP is configured to use ipg_clk_24M on GPT as source clock.
They suggest select clock source "101b - Crystal oscillator as Reference Clock (ipg_clk_24M)".
I hope this information helps you.
Best regards.
Jorge.
Hello,
Could you please confirm me the value of GPT Control Register (GPT1_CR) at address 0x302D0000?
Best regards.
Jorge.
Hello,
To help you to reproduce I made a better code, that use GPT1 in output mode
The register CR contains 0x0040006B:
In the source code, I set a prescaler of '67', the output frequency is 24Mhz/67 (358Khz) instead of 66.666666Mhz/67
Here is the source code:
/* Freescale includes. */
#include "board.h"
#include "clock_config.h"
#include "fsl_debug_console.h"
#include "fsl_device_registers.h"
#include "fsl_gpt.h"
#include "pin_mux.h"
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();
gpt_config_t gptConfig;
GPT_GetDefaultConfig(&gptConfig);
gptConfig.clockSource = kGPT_ClockSource_Periph;
gptConfig.divider = 67;
GPT_Init(GPT1, &gptConfig);
GPT_SetOutputOperationMode(GPT1, kGPT_OutputCompare_Channel1, kGPT_OutputOperation_Activelow);
GPT_SetOutputCompareValue(GPT1, kGPT_OutputCompare_Channel1, 0);
GPT_StartTimer(GPT1);
PRINTF("kCLOCK_IpgClk = %d Hz\r\n", CLOCK_GetFreq(kCLOCK_IpgClk));
PRINTF("CR = 0x%08x\r\n", GPT1->CR);
while (true) {
__WFI();
}
}
Here how the pin is initialized
IOMUXC_SetPinMux(IOMUXC_SAI3_RXD_GPT1_COMPARE1, 0U);
Here is the output:
kCLOCK_IpgClk = 66666666 Hz
CR = 0x0040006b
Hello,
Asking internally, due to errata e50068 AUDIO: Incorrect 24 MHz clock source at Audio Clock Mux input, that affects some i.MX8 family and also affects GPT module. The BSP is configured to use ipg_clk_24M on GPT as source clock.
They suggest select clock source "101b - Crystal oscillator as Reference Clock (ipg_clk_24M)".
I hope this information helps you.
Best regards.
Jorge.