Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Picomite RTC verification tool
Author | Message | ||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4234 |
This is a small program for the picomite to adjust the DS1307 Real Time Clock crystal oscillator for best performance. Essence is to connect a frequency standard (i.e. GPS receiver) 1Hz output output to GP0 of the picomite. Program the DS1307 (register 7 value &h10) to output 1Hz to GP1 of the picomite. Add a pullup to 3.3V (the SQ pin is open drain). The program measures the period (in microseconds) of both clock signals and shows the ratio in ppm (parts per million). The program uses the PIO to measure the period. Because the ratio of the 2 periods is shown, the accuracy of the PIO clock (the pico clock) can be inaccurate without affecting the adjustment. Adjust the DS1307 as close as possible to 0 ppm, and your real time clock is as accurate as possible. 'GP0/GP1 Dual period compare using PIO 'pio program measure pause and pulse time from GP0 in us and push both to FIFO '0 E020 'set X=0 '1 A029 'X -> fffffff '2 00C4 'jmp (pin=1) to loop2 '3 0042 'count loop1 '4 0045 'count loop2 '5 00C4 'jmp (pin=1) in loop2 '6 A0C9 'mov -X to ISR '7 8000 'push noblock '8 0000 'jmp 0 (rest is filled with 0 = jmp->0) Dim a%(7)=(&h004200C4A029E020,&h8000A0C900C40045,0,0,0,0,0,0) f=2e6'63e6 '2MHz gives 1us per count resolution 'configure pio1 e0=Pio(execctrl 0,0,&h1f) 'use gp0 for PIN e1=Pio(execctrl 1,0,&h1f) 'use gp1 for PIN 's=Peek(word &h503000d0) 'use old value p=0 'no GPxx pins for PIO 'program pio1 and start PIO program 1,a%() PIO init machine 1,0,f,p,e0,,0 'start pio 1,0 from adress 0 PIO init machine 1,1,f,p,e1,,0 'start pio 1,1 from adress 0 PIO start 1,0 PIO start 1,1 'measure time and convert to frequency Dim cnt%(4) Do PIO read 1,0,5,cnt%() 'read fifo pio 1 seq 0 period1% = cnt%(4)+3 'correction for push and loop PIO read 1,1,5,cnt%() 'read fifo pio 1 seq 1 period2% = cnt%(4)+3 'correction for push and loop err=(1-(period1%/period2%))*1e6 Print "difference = ";err;" ppm" ' freq=f/(2*period1%) 'calc freq ' err=Int((1-freq)*1e6) 'pico clock error (ppm) ' Print period%;" counts "; freq;" Hz ";err;" ppm pico clock err" Pause 200 Loop While Inkey$="" PIO stop 1,0 PIO stop 1,1 End To keep the program simple, no effort is made to protect or limit or monkey proof it. When both GP0 and GP1 have a (1Hz) signal the readout is correct. In case one of both is missing, all kinds of readouts are possible.... Increased accuracy is possible by making the PIO run at 63MHz (in stead of 2MHz). But 2MHz already gives you +/-1ppm accuracy, which is far less that the typical adjust value of the DS1307. Volhout P.S. to adjust the crystal on the DS1307 you add a variable capacitor 1-6pF to the crystal pins. Edited 2022-09-07 23:31 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
pwillard Senior Member Joined: 07/06/2022 Location: United StatesPosts: 292 |
Well Done! Thanks for this. |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3802 |
That's so cool!! John |
||||
Rickard5 Guru Joined: 31/03/2022 Location: United StatesPosts: 463 |
WOW That's pretty cool, I mean proving the calibration of the RTC, Only Problem is it flew over my head so fast it was like trying to catch CONCORD somewhere 1/2 way to London :) I may be Vulgar, but , while I'm poor, I'm Industrious, Honest, and trustworthy! I Know my Place |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4234 |
Calculating the accuracy of the picomite crystal oscillator compared to a GPS clock. This picomite board is particulary accurate..... PicomiteVGA PETSCII ROBOTS |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2135 |
@Volhout Thanks for for this very useful calibration tool. DS1307 error was 27 to 30ppm now 0 to 2ppm with 6.6pF added. Would have taken weeks of trial and error to get the same result. |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4234 |
Youre welcome. Volhout PicomiteVGA PETSCII ROBOTS |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2135 |
The DS1307 is a bit fussy about the extra capacitor. While the Pico is powered up it keeps perfect time with 6.6pF but when on its own battery (3.01 V) looses almost 1 min / hour! Now trial & error to find the max. value for reliable operation. 5.6pF also too much. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6792 |
The old valve blokes used to use bits of solid core insulated wire twisted together to make tiny variable trimmers. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4234 |
Hi Phil, Did you connect the crystal can to ground? I soldered a small spring wire to the ground pad clamping the crystal to ground. The can on my crystal could not be soldered. When the can is not connected to ground the tolerance on my DS1307 varied a lot (maybe the crystal is picking up noise). Volhout P.S. Mick, that is exactly how I tuned mine. Just 2 isolated wires (2.5cm long) and twist them together to get the right capacitance. Then cut the excess part away, and twist the rest a bit tighter. Don't try to fixate with hotglue, since that detunes again. Simply take wire that is mechanically rigid enough to hold position without hotglue. Edited 2022-09-16 18:38 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2135 |
Thanks both for the info. Yes the first thing I tried was grounding the can, no change. Reduced the cap to 2.2pF, no change. Currently trying without a cap to see if that gets it back to normal. If not I guess the heat of soldering has affected something. Next will be another crystal, a couple in the junk box salvaged from dead stuff. Will use the twisted wire trimmer for the next attempt. Edit No cap and it has kept time for an hour with no power, so back to square one. Bed time. Edit 2 Added a twisted wire cap, adjustment is indeed much easier but same problem. Replaced the crystal, error with no cap is 22 to 23ppm and with 3.3pF over shoots to -18 to -20ppm. However it now keeps time when the power is off. Edit 3 Replaced the 3.3pF with twisted wire cap but found it to be quite temperamental. Removed it expecting it to go back to 22ppm but now it is -3ppm. What the...? Tried heating and cooling it. It's a thermal yoyo! As this crystal is better than the original it may as well stay as it is, perfection just isn't possible. Edited 2022-09-17 13:34 by phil99 |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2135 |
While awaiting the arrival of some DS3231 modules brought the DS1307 out if retirement and found it had lost 2 weeks. The CR2032 cell still reads 3.02V yet it does not loose time when powered from 3.3V. The module doesn't have any decoupling capacitors so perhaps the internal resistance of the cell is the issue. Added a 1ĀµF ceramic SMD to the cell supply a few days ago and so far it has gained just 2S. Much better! Perhaps all the instability noted in the posts above are due to this simple omission. The cap is mounted on the top of the board from the 3V plated-through pad to the ground pad under the crystal. |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4234 |
Hi phill, I did put the capacitor at location R4 on the circuit board (years ago). Volhout PicomiteVGA PETSCII ROBOTS |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2135 |
After keeping within a couple of seconds for the past 3 days it lost almost Ā½ hour today so shifted the cap to R4 as you did. It seems demented. |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4234 |
Hi Phil, Are you testing this on a PicoMite that you power OFF and ON ? Maybe try the same module on a micromite ? Or some other (less intelligent) platform. I am still not sure there could be something in the picomite code that could influence this on the DS1307. Maybe it is the OPTION RTC AUTO that is checking the time on the RTC at the moment you power down the pico (I2C corrupted). I have not experienced this "time drift" on my DS1307's, but I have seen various occasions of complete time loss (00:00:00), and the battery on this 1307 is definitely okay. Volhout PicomiteVGA PETSCII ROBOTS |
||||
JanVolk Senior Member Joined: 28/01/2023 Location: NetherlandsPosts: 144 |
phil99 and Volhout For DS1307 Take a look at the datasheet at Supply Voltage Vcc Min=4.5V Typ=5.0V Max=5.5V Nice day |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2135 |
This particular DS1307 keeps time with good accuracy (after replacing the crystal) when powered from 3.3V, but becomes unpredictable when unpowered, running on it's coin cell. It will keep time for days then abruptly loose a big lump. With Volhout's mod. (1ĀµF across R4) it remained within 1S overnight unpowered. Will experiment with unplugging the module before powering down the Pico. That should prevent I2C errors affecting it. Also removed RTC AUTO ENABLE. Edit. Having been prompted to re-examine the data sheet the min/max Vbat is 2.0/3.5V. Measuring Vbat with a 10MĪ© meter gives 2.1V which is a bit close to min., allowing for meter loading. I suspect the original version of this circuit used a 3 cell NiCd battery which could be up to 4.5V on charge. Hence the voltage divider. I will remove R4 and the charging resistor to see if that helps. A little less drain on the cell as a bonus. Edit 2. After removing R4 Vbat is now 2.8V but it now won't run at 3.3V so now powering from 4.8V Vsys with S. diodes from the I2C pins to 3.3V. Edited 2024-01-13 14:04 by phil99 |
||||
JanVolk Senior Member Joined: 28/01/2023 Location: NetherlandsPosts: 144 |
phil99 For DS1307 Take a look at the datasheet at Supply Voltage Vcc: Min=4.5V Typ=5.0V Max=5.5V Vbat: Min=2.0V Typ=3.0V Max=3.5V Make sure that the SDA and SCL pullup resistors are not connected to 5V. (With Raspberry Pi Pico) Make sure that the diode does not have too much voltage drop when charging at 3V3, otherwise use a 5V charging scheme or a separate 3V CR2032 button cell. For example, I had a Raspberry Pi RTC clock module where the yellow button cell was defective. Removed this button cell and disabled the SCL charging resistor by unsoldering pin 14 of the chip and connecting a wire to the loose NC pin to which I attached a loose 3V CR2032 button cell. And I have the impression that this makes the DS3231's clock run more accurately. Nice day |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2135 |
In practice most DS1307 chips will run with Vcc = 3.3V and this one had done so for several years, though the accuracy was much less than a DS3231, until the crystal was replaced. That improved it quite a bit. The main issue was unreliability when running on it's battery. The circuit is the same as in Volhout's post. It has a charging diode and resistor yet is fitted with a non-rechargeable 3V CR2032 cell. This didn't matter when powered from 3.3V. The 200Ī© resistor has now been removed. It also has a voltage divider between the battery and Vbat, this is not needed for a 3V cell and was reducing Vbat close to the minimum. Now that I am running Vcc from 4.8V to protect the Pico I2C pins Schottky diodes have been added from them to 3.3V. In practice, the Pico pins can tolerate pullup resistors going to 5.0V. The RP2040 datasheet is conservative. So far it has kept time with these mods but because of it's unpredictability I will need to wait at least a week. |
||||
Print this page |