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
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();
}
}
3>test result
the parameter "subSecond_cnt" is still 0.
Solved! Go to Solution.
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.
BR
Harry
yes thanks
Hi @jimmyli
The Subsecond counter use these register, not RTC_TEST2.
If you want to use is,
Please refer to chapter 56.3.2 Subsecond counter
You can try.
BR
Harry
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.
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 (;;)
{
}
BR
Harry
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 ?
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.
BR
Harry
Hi @jimmyli
I think your calculation method is correct,
So i need to confirm with the internal team.
BR
Harry