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
Solved! Go to Solution.
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:
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
Hello @Transidico,
The SDK (version 24.12) provides some examples with the propose of show the RTC functionality, as shown the next image:
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:
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:
Also, if you experience any issue, do not hesitate to let me know.
BR
Habib
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:
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
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
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
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!
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
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