Config timer RTC frdm-mcuxc242

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

Config timer RTC frdm-mcuxc242

Jump to solution
2,201 Views
Transidico
Contributor II

Good morning,
i am new and a beginner, i would like to carry out a project using an rtc in interrupt as a timer every second.
Reading the manual I have to set the following registers: RTC Time Seconds Register (RTC_TSR)
RTC Time Prescaler Register (RTC_TPR)
RTC Time Alarm Register (RTC_TAR)
RTC Time Compensation Register (RTC_TCR)
RTC Control Register (RTC_CR)
RTC Status Register (RTC_SR)
RTC Lock Register (RTC_LR)
RTC Interrupt Enable Register (RTC_IER)
But unfortunately when I try to set them via code, I get the semihost_hardfoult.

I was wondering if you had anything I could build on.

Thank you

Tags (1)
0 Kudos
Reply
1 Solution
2,052 Views
Habib_MS
NXP Employee
NXP Employee

Hello @Transidico,
unfortunately, the RTC only provides a second timer, as mentioned the chapter 29.2.1 called features in the RM, however you can use the periodic interrupt timer (PIT) to make it.
The SDK (version 24.12) offers an example of this peripheral that could be helpful:

Habib_MS_0-1739309229310.png

About the PIT code, you can change the PIT frequency with the function called "PIT_SetTimerPeriod". Also, I highly recommend see the Readme of the example to know how it works.

BR
Habib

View solution in original post

0 Kudos
Reply
8 Replies
2,181 Views
Habib_MS
NXP Employee
NXP Employee

Hello @Transidico,
The SDK (version 24.12) provides some examples with the propose of show the RTC functionality, as shown the next image:

Habib_MS_0-1737658848406.png

Where you can download the SDK through SDK builder.

At the same time, you can download the SDK inside MCUxpresso IDE clicking the next button:

Habib_MS_1-1737658905682.png

Inside to the window called "Download and install SDK" you can search the MCXC242 in the filter, where it will be showing the available SDK, as shown in the next image:

Habib_MS_2-1737658939491.png

Also, if you experience any issue, do not hesitate to let me know.
BR
Habib

0 Kudos
Reply
2,062 Views
Transidico
Contributor II

Thank you for your reply,
I looked at the sdk pointed out to me and created my code. The 1 second RTC timer works correctly, but I would like to modify it to create a 1ms timer, could you give me some tips by seeing the attached code?

0 Kudos
Reply
2,053 Views
Habib_MS
NXP Employee
NXP Employee

Hello @Transidico,
unfortunately, the RTC only provides a second timer, as mentioned the chapter 29.2.1 called features in the RM, however you can use the periodic interrupt timer (PIT) to make it.
The SDK (version 24.12) offers an example of this peripheral that could be helpful:

Habib_MS_0-1739309229310.png

About the PIT code, you can change the PIT frequency with the function called "PIT_SetTimerPeriod". Also, I highly recommend see the Readme of the example to know how it works.

BR
Habib

0 Kudos
Reply
1,996 Views
Transidico
Contributor II

Good morning,
thanks for your reply, I tried to set the timer pit by 1ms with the following instruction:
PIT_SetTimerPeriod(DEMO_PIT_BASEADDR, DEMO_PIT_CHANNEL, USEC_TO_COUNT(1000000U, PIT_SOURCE_CLOCK));
Unfortunately, I notice that if I set the pit for 1s or 0.5s I see it working quite well, but if I set times less than 10 ms it suffers quite a bit from noise and it lags.
The 1ms one I see that it suffers from about 3/4ms noise, which is a bit too much for good accuracy.
I would need this timer to cadence the adc to take readings every 1ms. Could you recommend something else?


Thank you.

Best Regards

0 Kudos
Reply
1,979 Views
Habib_MS
NXP Employee
NXP Employee

Hello @Transidico,
In order to support you better, can you provide more information?

-How does noise occur in the PIT?

-How are measurements made to detect noise?

BR
Habib 

0 Kudos
Reply
1,943 Views
Transidico
Contributor II

G-day,

1)How does noise occur in the PIT?

I think it occurs because of the noise generated by the usb input that phases out the pit timer   

 

2)How are measurements made to detect noise?

I use the pit sdk and set it to have 1ms interrupt. To check if the interrupt is working properly on VSCODE I enable the print function with clock and notice that printing does not happen every 1ms.

 

I attach the code.

 

Thank you. Best regards!

0 Kudos
Reply
1,933 Views
Habib_MS
NXP Employee
NXP Employee

Hello @Transidico,

In order to try a pinpoint if it solves the issue, can you comment the function called "delay"?

If this does not solve the issue, could you toggle a pin inside the if and see the signal with an oscilloscope?

The pin will toggle with a frequency of 2ms aprox.

BR
Habib

0 Kudos
Reply
1,925 Views
Transidico
Contributor II

Hi,
I tried commenting on the delay, but sometimes the count happens every 1ms and sometimes every 2ms. It is still not very accurate.
This is part of the printout I get:
09:36:00:035 -> PIT counter: 7716
09:36:00:037 -> PIT counter: 7717
09:36:00:039 -> PIT counter: 7718
09:36:00:041 -> PIT counter: 7719
09:36:00:043 -> PIT counter: 7720

I will try with oscilloscope in the near future.

Thank you for your reply.

Regards

0 Kudos
Reply