IMX8MN - GPT - Wrong Frequency ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IMX8MN - GPT - Wrong Frequency ?

Jump to solution
775 Views
Cupcake
Contributor II

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.

  • The GPT is configured to use kGPT_ClockSource_Periph, so ipg_clk.
  • When I check the frequency of kCLOCK_IpgClk (using CLOCK_GetFreq()), it returns 66.666666Mhz
  • But something strange is that by experience it seems that the frequency is not 66Mhz but 24Mhz and I have to configure my code using 24Mhz for the divider calculations and ticks>us conversion

 

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

  • 66666666/67 = 1us
  • 24000000/24 = 1us

 

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 ? 

Labels (1)
0 Kudos
Reply
1 Solution
723 Views
JorgeCas
NXP TechSupport
NXP TechSupport

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)". 

Jorge7u7_0-1684241902470.png

I hope this information helps you.

Best regards.

Jorge.

View solution in original post

0 Kudos
Reply
4 Replies
743 Views
JorgeCas
NXP TechSupport
NXP TechSupport

Hello,

Could you please confirm me the value of GPT Control Register (GPT1_CR) at address 0x302D0000?

Best regards.

Jorge.

0 Kudos
Reply
729 Views
Cupcake
Contributor II

Hello,

To help you to reproduce I made a better code, that use GPT1 in output mode

The register CR contains 0x0040006B:

  • CLK_src=Peripheral Clock (ipg_clk)

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

 

 

 

0 Kudos
Reply
726 Views
Cupcake
Contributor II
For me there is something very strange.

I think the GPT is NOT using the ipg_clk clock OR the frequency returned by CLOCK_GetFreq(kCLOCK_IpgClk) is wrong.

What do you think ?
724 Views
JorgeCas
NXP TechSupport
NXP TechSupport

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)". 

Jorge7u7_0-1684241902470.png

I hope this information helps you.

Best regards.

Jorge.

0 Kudos
Reply