This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Part Number: MSP430F5529
I am developing a data logger that is designed to take a measurements from two different sensors (A and B) and store them. Sensor "A" records at 1 Hz and sensor "B" at 64Hz. The values are not tagged, they are simply stored as it is collected in a repeating pattern"ABBB...ABBB... etc.), so in order to decode the data the pattern must repeat without fail. The code uses the RT1PSIFG to generate the 64Hz interrupts for the data collection and storage. The timing for the 64Hz sensor is tight, but it works most of the time (see below).
The logger is designed to run for months at a time and the accuracy of the clock is a concern. So the 32768 Hz watch crystal is calibrated against a reference. The crystals generally run about 32 ppm slowly, so to compensate RTCALS is set to 0 and RTCCAL is set to 4 (+32 ppm of adjustment per the erratasheet). The accuracy is about right. No issue there.
The problem is that every 64 minutes, without fail, there is a glitch in the data where the 64Hz data is bad and it looks like one or more of the 64Hz measurements from sensor B is missing. The RTC Calibration is the #1 suspect because it is the only event that occurs on a 64 minute interval. I have read and re-read the user guide to understand the issue and try to find a solution but I don't quite understand and I need some help. The relevant section of the user guide reads:
Calibration is accomplished by periodically adjusting the RT1PS counter based on the RTCCALS andRTCCALx settings. In calendar mode, the RT0PS divides the nominial 37268-Hz low-frequency (LF)crystal clock input by 256. A 64-minute period has 32768 cycles/sec × 60 sec/min × 64 min = 125829120cycles. Therefore a –2-ppm reduction in frequency (down calibration) approximately equates to adding anadditional 256 cycles every 125829120 cycles (256/125829120 = 2.035 ppm). This is accomplished byholding the RT1PS counter for one additional clock of the RT0PS output within a 64-minute period.Similary, a +4-ppm increase in frequency (up calibration) approximately equates to removing 512 cyclesevery 125829120 cycle (512/125829120 = 4.069 ppm). This is accomplished by incrementing the RT1PScounter for two additional clocks of the RT0PS output within a 64-minute period. Each RTCCALxcalibration bit causes either 256 LF crystal clock cycles to be added every 64 minutes or 512 LF crystalclock cycles to be subtracted every 64 minutes, giving a frequency adjustment of approximately –2 ppm or+4 ppm, respectively.
If I understand this correctly, RT0PS is feeding the RT1PS at 128Hz, so the 64Hz interrupt is triggering for every 2 counts out of RT0PS. To adjust the clock, every 64 minutes, the RT1PS is either held for a number of RT0PS counts (creating a long "1/64th" of a second or it is pre-loaded with a value greater than 0 to speed up the clock (creating a short "1/64th" or a second). In my case, with a nominal crystal of that is 32 ppm slow, the RT1PS would be need to be preloaded with a value of 4 (or is it 8?) and that would then result in 2 missed interrupts. Or to put it another way, the "64Hz RT1PS interrupt" would only trigger 62 times during the "calibration second"? Is this interpretation correct? If not, what am I missing?
The minimum adjustment is -4/+8 ppm. So even if the 32768 crystal was exactly on target, there would still be a timing glitch every 64 minutes. Right? Is there any work around to assure that there are 64 interrupts in each and every second?
Thank you for the assistance.
We are glad that we were able to resolve this issue, and will now proceed to close this thread.
If you have further questions related to this thread, you may click "Ask a related question" below. The newly created question will be automatically linked to this question.
In reply to Jeff Hastings:
In reply to Nick Lowell1:
yep, you've got it unless I myself have been mistaken on how this works (possible). 'leap cycle(s)' can and will be added or subtracted unless the cal data registers are zero.
By reading your previous posts and referencing Katie's posts in another similar e2e thread, it does sound like the root cause of missing one or more sensor readings every 64 minutes is from the calibration module holding the RT1PS counter for one or more clocks of the RT0PS output.
The purpose of the calibration module is to allow a user, only in Calendar Mode, to perfectly calibrate the RTC input to accurately measure seconds, minutes, hours, etc. over time. In your case, you want to accurately time interrupts that trigger every n seconds on the RTxPS interrupt flag without having to worry about the calibration module affecting those interrupts. This sounds like a perfect application for the RTC in counter-mode.
Your best bet is to clear the RTCMODE bit to put the RTC in counter mode that way the calibration module is deactivated and you would not have to worry about it affecting the Prescale interrupt timing. Since you are not tagging the sensor data and only need to decode the repeating data pattern, this configuration of the RTC peripheral should work for your implementation.
In reply to Matthew Calvo74:
It does look like this specific problem could be solved by using the RTC in counter mode. But that would be a big change and would have several negative side effects. Specifically:
1. The clock will no longer be accurate over time. This is a particular issue because typically multiple data loggers are typically deployed for months at a time and the data should be reasonable synchronized. We have added temperature compensation to the calibration values. Without the RTC compensation, the clock drift between any two data loggers would exceed our target.
2. The data logger has several operating modes and does not always record continuously. The calendar mode is useful for setting a wake up time and maintaining low power operation between measurements.
3. While the data file is stored in a repeating pattern, the logger still needs to keep track of the time for other reasons, such as communicating with other devices, that are beyond the scope of this discussion.
So there are several reasons that I am not ready to give up on RTC Calendar mode. Furthermore, I still have hope that there is a work around that provides the best of both worlds.
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.