XOSC32K running slow on avr64db32? #302
Replies: 8 comments 1 reply
-
And in further testing I added a tune of +1 to the internal oscillator. After 4h54m16s I have reached the somewhat infuriating conclusion that the internal oscillator which is specified to be +/- 1% has 22.71ppm error and the crystal which is specified as +/-20ppm has -1585.88 ppm of error. I suppose a more fair comparison would be to apply the tune to the rtc as well which would subtract 127 ppm for 1458.87 but its not a big enough improvement to warrant the prescaler. Mental note not to use the "auto-tune" setting. facepalm |
Beta Was this translation helpful? Give feedback.
-
I have been less than impressed with the oscillator circuits on these new parts, in general. I haven't noticed accuracy issues, though I haven't measured that with all that much care - I've used it as a timebase to cal th internal oscillator on tinyAVRs from, and it was definitely pretty damned close - I couldn't see a difference on the 'scope's frequency counter with an attiny between theoretical and observed. but that was on a 2-series. Have you tried tricks like not using exactly the same load capacitance on the crystal? unbalanced loading caps have more of a frequency pulling effect. Also, uh, what exactly is the formula for the loading caps you are "supposed" to use? I have seen 2 formulas, neither of which gives a value that causes the crystal to oscillate... and sometimes the stray capacitance is enough to made the bloody things work. Though note that i've mostly played with HF xtals for system clock (mainly for overclocking - DB will run at 40 MHz from a crystal. At least one non-extended temp range one would almost work at 48 from an external clock. but not quite, but when I moved the external clock to a board with an extended temp range DB, I could run a sketch that printed out millis for at least a half an hour without millis suddenly changing. (the usual failure mode of modern AVRs when overclocked is that they get the wrong answers to arithmetic and logical operations, most often 1's coming out as zeros,. |
Beta Was this translation helpful? Give feedback.
-
So in a tinyAVRs calibration world (warning: the modern tinyAVRs use the X32K_1v8_5v5_ULP oscillator module, the DX use OSC_LP_V10, DS00002648D-page 15) the 1600ppm error is still hugely better than the internal oscillator and is a great reference to tune the internal (1600 ppm = 0.16%). But I noticed I was getting large discrepancies between the RTC's timekeeping over the course of days and the time coming out of my GPS so I started investigating what I assumed was just wrong loading caps when I started down this rabbit-hole. I initially used "divide the sum of the pin capacitance, the external caps, and the parasitic by 2" which seems to produce identical results to the more complex equation 3-5 in: But following the advice in that app note I was trying to accurately measure the frequency to figure out if I got the caps right since I distrust my measurement of the parasitic capacitance (my LCR meter with kelvin-connected tweezer probe reads 1.5pf with the tweezers nearly closed and 2.5pf with those nearly closed tweezers touching the cap pads on an unpopulated board, ergo my best guess for parasitic is 1pf). So according to that formula, assuming 1pf parasitic (per pad), 4pf pin (per pin) you need 9pf external to have a load capacitance of 7pf and the 6pf external I started with should have already been pulling it faster but it was running slow. Assuming I have no idea what the actual parasitic is I kept dropping the capacitance until it wouldn't start (2pf) then backed it off to 2.7 which seemed to run and was still mega slow. But since it wouldn't start with any less I definitely didn't have too much. I have not tried unbalanced caps for greater pulling, I was attempting to measure frequency to verify I wasn't inadvertently pulling it off and discovered it was way off regardless of how I loaded it. In theory the crystal when loaded correctly should be in spec, I want to leverage the 20ppm crystal spec not abuse it to try to drag it around by 1000+ppm by violating the loading spec. I am pretty sure my board that uses a crystal on an attiny1614 has the same problem as I also noticed it losing what seemed like way more than 20ppm on its timekeeping. But since it doesn't have a GPS with PPS connected natively I started doing the investigation on the DB board. |
Beta Was this translation helpful? Give feedback.
-
and yes equation 3-5 does in fact simplify to "divide the per-pin total by 2" when the load capacitance is the same on both pins: |
Beta Was this translation helpful? Give feedback.
-
I think I found the problem. After repeating the testing with a crystal on the manufacturer recommended list and getting the same result and assembling a different design to make sure it wasn't a layout issue I became convinced this was not possible. I went ahead and moved the serial.print out of the ISR and am now getting 8192-8193/second (running slightly fast, as expected with intentionally low load capacitance). Sigh. I knew better when I wrote it but yes an overly slow PIT ISR was causing 1500PPM of missing interrupts. For added hilarity, the reason it was taking a few minutes to "settle" in which it slowed from 8183 to 8180 is the numbers increase in size at the beginning which means an increasing amount is getting printed. |
Beta Was this translation helpful? Give feedback.
-
Wow. How often was the pit triggering? It would have to be somehow spending
enough time be busy for a whole interrupt cycle.either thst or the
transmission is was playing a role
…____________
Spence Konde
Azzy’S Electronics
New products! Check them out at tindie.com/stores/DrAzzy
GitHub: github.com/SpenceKonde
ATTinyCore: Arduino support for almost every ATTiny microcontroller
Contact: ***@***.***
On Mon, Jul 25, 2022, 22:47 ObviousInRetrospect ***@***.***> wrote:
I think I found the problem. After repeating the testing with a crystal on
the manufacturer recommended list and getting the same result and
assembling a different design to make sure it wasn't a layout issue I
became convinced this was not possible.
I went ahead and moved the serial.print out of the ISR and am now getting
8192-8193/second (running slightly fast, as expected with intentionally low
load capacitance). Sigh. I knew better when I wrote it but yes an overly
slow PIT ISR was causing 1500PPM of missing interrupts.
—
Reply to this email directly, view it on GitHub
<#302 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTXEWY5KX2LUHRA6L2XE5DVV5GTJANCNFSM54H74RLQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
The PIT was supposed to be triggering at 8192hz. It was triggering at 8180hz. I was running the PIT as fast as it will go because you can't CLKO the 32K clock (afaik) unless you use it as the main clock. The oscilloscope measurements were a pin toggled from the PIT so they were of no help. Did a bit more testing. The initial numbers with the 6pf caps (a 7pf crystal with 5.5pf applied low) were +116ppm. Just to get a sense of how much it would change I installed 8.2pf caps (6.6pf load) and got +32 ppm. That means a change of 0.4pf of load (for this crystal) produced a swing of +35.8ppm so with +/-0.25pf tolerance caps 9pf is essentially dead on. after replacing the 9pf caps (with new ones, 0402 caps are not worth saving) I get -1.03ppm error. repeating the experiment on one of the other boards (different layout, same crystal model & caps) I get -0.7ppm. And the third board (with CM8V-T1A-32.768KHZ-6PF-20PPM-TA-QC) -30ppm. Things I and others can learn from this:
|
Beta Was this translation helpful? Give feedback.
-
And overnight testing (post-washing) confirms that the results seen in a couple minutes hold (and provides much higher precision, beyond what is useful). The better of the two tested was -0.3062ppm. the "worse" was -1.4697ppm (untuned). When I went to extend my prior scheme of USERSIG.write(0,CLKCTRL_OSC20MCALIBA) (from megatinycore) to also store RTC.CALIB I seem to be getting strange results from the USERSIG library on DxCore:
produces: My understanding of the docs say that if write() returns 1 there is no need to call flush (and I wasn't originally). Did I miss something or Is this a USERSIG bug on DB? the simpler test (where I started):
always prints 255 |
Beta Was this translation helpful? Give feedback.
-
[edit: solved, was losing about 10/8192 pit interrupts due to a print in the pit.]
So on several samples I've been seeing XOSC32K losing hugely out of spec amounts of time (2 minutes per day). I figured I was just being sloppy with the loading capacitors but I finally sat down and did some more rigorous testing across 2 samples with 3 different crystal types and several permutations of loading caps per crystal. Surprisingly all were slow by similar amounts.
Any ideas what I am doing wrong (besides using crystals with similar specs to ones on the approved list instead of ones on the approved list - waiting for one of those to arrive)?
I've used a couple methods. Mostly via a GPS (both the 1 pulse per second signal and the time output). But my oscilloscope matches (on a pin toggled from the PIT ISR running at 8192hz) within its more limited precision.
All rigorous testing was done at 2.8v. But I originally noticed the problem of losing about 2m per day on a third board running 3.3v.
(yes, in theory I could read the rtc counter value instead of using the pit for 2 more bits of precision. I wish I had it accurate enough for those 2 bits to be useful. I figured the synchronization time might make that a bit harder to reason about.)
In short tests, a 6pf crystal https://www.digikey.com/en/products/detail/micro-crystal-ag/CM8V-T1A-32-768KHZ-6PF-20PPM-TA-QC/10499094 with the minimum caps I could get to start (2.7pf = 2.7/2+4/2+1/2 = 2.85pf load) was slightly better than either correct-ish caps (6pf/2=3+4/2+1/2 5.5 load ) or too-large caps (12pf caps = 12/2+4/2+1/2 = 8.5pf load)
Additionally, the crystals all seem to take about 90-120 seconds to stabilize during which they get worse and go from ~8184 to 8181ish and then seem to further slow over a couple hours to 8180.3ish.
The best results were with the undersized caps (which would pull it faster) so I ran that overnight. In 29082 seconds (wall clock measured by GPS) I had 237927797 ticks, for a rate of 8180.9922291373Hz and a loss of 39 seconds. If I discard the first 10k seconds it gets worse: 8180.62395090222hz or a loss of 26.47/19064 seconds.
These are all 2-layer PCBs, ground plane under the crystal which is right next to the MCU, 0402 loading caps.
In short tests (minutes), a 6pf crystal https://www.digikey.com/en/products/detail/micro-crystal-ag/CM8V-T1A-32-768KHZ-6PF-20PPM-TA-QC/10499094 with the minimum caps I could get to start (2.7pf = 2.7/2+4/2+1/2 = 2.85pf load) was slightly better than either correct-ish caps (6pf/2=3+4/2+1/2 5.5 load ) or too-large caps (12pf caps = 12/2+4/2+1/2 = 8.5pf load). (4pf, 9pf) were not meaningfully different.
This was repeated against a couple capacitor variations with a second copy of the same crystal type on a second board with functionally identical results.
I also tried both:
Q13FC1350000200 (needed 6pf loading caps to start)
and
Q13FC1350000400 (similar between 6, 12, and 18pf loading caps)
Here is the test code (omitted configuration of gps + pin setup)
I initialize the crystal:
Here is a short snippet of the output:
Beta Was this translation helpful? Give feedback.
All reactions