MCXN547: how to enable iRTC subSecond function ?

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

MCXN547: how to enable iRTC subSecond function ?

Jump to solution
410 Views
jimmyli
Contributor IV

Hi NXP,

      I find that MCXN547 has subsecond function register for iRTC, and I consider using this function to record millisecond.

      According to official SDK (SDK_2.x_FRDM-MCXN947), I import the iRTC driver example and add the code to test this function, but failed.

      Can you help to check and provide some tips ?

      Thanks;

 

1>subSecond register in MCXN reference manual

jimmyli_0-1759989461232.png

 

2>test code

based on example: frdmmcxn947_irtc_cm33_core0

hardware: FRDM-MCXN947

IRTC_EnableSubsecondCounter(RTC,true);

uint32_t subSecond_cnt = 0;

while(1){

subSecond_cnt = IRTC_GetSubsecondCount(RTC);

PRINTF("subSecond Counter is %d.\r\n",subSecond_cnt);

 

//intervals time

uint32_t i,j;

for(i=0;i<6534;i++)

for(j=0;j<6232;j++){

__NOP();

}

}

jimmyli_1-1759989578566.png

 

3>test result

    the parameter "subSecond_cnt" is still 0.

 

Labels (1)
0 Kudos
Reply
1 Solution
248 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @jimmyli 

I have tested again.

By default, the RTC Clock select 

/* 16.384kHz clock is selected */
config->clockSelect = kIRTC_Clk16K;

So the count should less than 16384

You just need to change 

RTC->CTRL |= RTC_CTRL_CLKOUT((uint16_t)kIRTC_ClkoutFine1Hz);

to 

IRTC_ConfigClockOut(RTC, kIRTC_ClkoutCoarse1Hz);

It can work.

Harry_Zhang_0-1760515151613.png

BR

Harry

View solution in original post

0 Kudos
Reply
8 Replies
228 Views
lucindaschatz
Contributor I

yes thanks

0 Kudos
Reply
379 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @jimmyli 

The Subsecond counter  use these register, not RTC_TEST2. 

Harry_Zhang_0-1760064450831.png

If you want to use is,

Please refer to  chapter 56.3.2 Subsecond counter

Harry_Zhang_1-1760064593090.png

You can try.

BR

Harry

0 Kudos
Reply
376 Views
jimmyli
Contributor IV

Hi Harry,

       Yes, you are right, the subsecond function has its own register.

       But, I called the static inline void IRTC_EnableSubsecondCounter(RTC_Type *base, bool enable) and static inline uint32_t IRTC_GetSubsecondCount(RTC_Type *base) APIs in fsl_irtc.h to enable and read the subsecond counter, but failed.

       Do you have any tips to help to enable this function ?

       Thanks very much.

0 Kudos
Reply
359 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @jimmyli 

I just tested it on my end.

It can work.

According to the RM.

There are two important points to note.

1. You must independently enable the field by writing 1 to SUBSECOND_CTRL[SUB_SECOND_CNT_EN] after enabling RTC.CTRL[CLKOUT] (see chip-specific RTC_SUBSYSTEM for more information) to select the 1 Hz clock output.

2.In RTC.CTRL[CLKO_DIS]  you should select The selected clock is output to other peripherals. 0b

This is my test code.

    IRTC_GetDefaultConfig(&irtcConfig);
    irtcConfig.disableClockOutput = false;
    if (IRTC_Init(RTC, &irtcConfig) == kStatus_Fail)
    {
        return 1;
    }
    
    PRINTF("RTC Example START:\r\n");

    RTC->CTRL &= (uint16_t)(~RTC_CTRL_CLKOUT_MASK);

    RTC->CTRL |= RTC_CTRL_CLKOUT((uint16_t)kIRTC_ClkoutFine1Hz);

    IRTC_EnableSubsecondCounter(RTC, true);

    uint32_t subSecond_cnt = 0;

    while(1){

    subSecond_cnt = IRTC_GetSubsecondCount(RTC);

    PRINTF("subSecond Counter is %d.\r\n",subSecond_cnt);


    //intervals time

    uint32_t i,j;

    for(i=0;i<6534;i++)

    for(j=0;j<6232;j++){

    __NOP();

    }
    }
    for (;;)
    {
    }

 

Harry_Zhang_0-1760082383619.png

BR

Harry

 

 

0 Kudos
Reply
355 Views
jimmyli
Contributor IV

Hi Harry,

      Thanks very much for your help!

      I have checked with your code, and subsecond can work now.

 

      But I have a question that when I convert subsecond counter to minisecond, the value seems wrong.

      Eg: 1>default clock source for subsecond counter is 32KHz;

           2>Minisecond Value = ( 1 / 32KHz ) * subsecond counter = 1/32000 x 53479 = 1.67 (s) > 1(s)

      Do I calculate it wrongly ?

 

jimmyli_0-1760086905182.png

 

0 Kudos
Reply
249 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @jimmyli 

I have tested again.

By default, the RTC Clock select 

/* 16.384kHz clock is selected */
config->clockSelect = kIRTC_Clk16K;

So the count should less than 16384

You just need to change 

RTC->CTRL |= RTC_CTRL_CLKOUT((uint16_t)kIRTC_ClkoutFine1Hz);

to 

IRTC_ConfigClockOut(RTC, kIRTC_ClkoutCoarse1Hz);

It can work.

Harry_Zhang_0-1760515151613.png

BR

Harry

0 Kudos
Reply
237 Views
jimmyli
Contributor IV

Hi Harry,

      Got it.

      Thanks very much.

Tags (1)
0 Kudos
Reply
265 Views
Harry_Zhang
NXP Employee
NXP Employee

Hi @jimmyli 

I think your calculation method is correct,

So i need to confirm with the internal team.

BR

Harry

0 Kudos
Reply