I am using an LPC1850 running at 180 MHz via the internal oscillator. According to the datasheet, the oscillator has a frequency tolerance range of 1.5%.
I have the system tick timer configured to interrupt at 1 ms intervals. Sometimes I use the interrupts to measure elapsed time. Given the tolerance of the internal oscillator, my time calculations become less accurate as the duration increases.
I also have a 32 kHz crystal that drives the internal RTC. The crystal has a frequency tolerance of 20 ppm, which is much more accurate than the internal system clock. I realize that for longer periods of time, I can just use the RTC to measure elapsed time. However, what about using the 32 kHz crystal to make the system tick timer more accurate??
Here's what I'm thinking:
Aside from being an interesting exercise, is this ever done in practice? Is it a terrible idea?
Hi, Rawsewage,
Regarding your question, if you want to calibrate the systick module, I suppose that you'd better use hardware capture solution in order to increase the accuracy.
But the systick module has not output pin, it has not capture function either. In other words, I do not think your solution is feasible. If you use software solution, for example have the systick generate an interrupt, in the ISR, you can read the Timer counter value, but because the ISR latency is not fixed and difficult to estimate, so software solution is not feasible.
I think what you calibrate is the clock source accuracy instead of Timer module itself, you can use the external 32KHz crystal clock to calibrate the internal 12MHz with Timer.
As you know that the Ctimer and SCT modules have hardware capture function, you can use one module for example MCPWM to counts the internal 12MHz which functions as a tick. You can use the CTimer to count the 32KHz crystal clock, which can be a standard clock source. You can use the MCPWM signal as capture signal and connect it to CTimer capture pin, when the rising edge of capture signal is detected, the CTimer counter value is loaded to capture register immediately, in this way, you can calibrate the 12MHz clock with the 32Khz crystal clock. This is the basic idea.
After you calibrate the 12MHz internal clock, you can write the correct value to systick module.
Hope it can help you
BR
XiangJun Rong
Hi XiangJun Rong,
Thank you for taking the time to respond. Your information is very helpful. I have a follow-up question for you.
You mention calibrating the 12MHz internal clock. Is there a setting or register in the LPC1850 that allows me to calibrate the internal clock? I've looked but I don't see anything, perhaps I missed it. Or are you referring to some type of hardware calibration?
Thanks again.
Hi, rawsewage,
You are right, the 12MHz IRC can not be trimmed by user. I suppose that you can output the 12MHz IRC to an output pin and use a frequency meter to test the actual frequency, this is the direct method.
Hope it can help you
BR
XiangJun Rong