![]() |
Forum Index : Microcontroller and PC projects : Time$ very inaccurate
Page 1 of 2 ![]() ![]() |
|||||
Author | Message | ||||
atmega8![]() Guru ![]() Joined: 19/11/2013 Location: GermanyPosts: 724 |
Hello, my pic 150F 128B with mmbasic 4.5D is "very inaccurate". It is approx. 5 seconds faster per hour, compared to a DCF77 Clock (Atomic Clock). It this a normal beaviour within expected variance? Do i have a chance to calibrate the internal PIC clock? I plan to sync the Time$ with a external RTC DS3231, but if i sync for example every hour i will have time jumps of some seconds. This can be a problem for programs that rely on a monotonous function of time. THX for your comments |
||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
I have experienced this also. The ds3231 has become my favorite way to easily keep the time thing at bay. Thanks to the great code from forum members, I seem to be using this for almost all my projects. It just works and it can be very cost effective. I cant wait to try the rtc in the fram that seems to be able to be tweeked to a high degree of accuracy. |
||||
plasma Guru ![]() Joined: 08/04/2012 Location: GermanyPosts: 437 |
using a realtime clock or get the time from a server helps a lot. |
||||
atmega8![]() Guru ![]() Joined: 19/11/2013 Location: GermanyPosts: 724 |
Hi viscomjim, thanks 1) How often do you update time$ with the ds3231? 2) What kind of apllication is that "fram" ? |
||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
Hi atmega8, Typically for most of my projects i update once an hour or so, sometimes more sometimes less. As it takes very little time to do this, you can do it several times a minute if you are so inclined. Here is most of what i know about fram. Take a look, i believe jman posted some code to adjust accuracy. |
||||
BobD![]() Guru ![]() Joined: 07/12/2011 Location: AustraliaPosts: 935 |
Jim You already have an RTC that can be tweaked if needed. See page 14 of the DS3231 datasheet - Aging Offset register. Register 16 (&H10) can be used to adjust the DS3231 by increments of + or - 0.1 ppm with a maximum possible deviation of approx. + or - 12 ppm. The technique is read that register, adjust the read value and write it back. A positive increment will slow the RTC. If I had an RTC that needed the maximum adjustment I would throw it away. Have you found your DS3231 in regular need of adjustment? The main reason for inaccurate MicroMite timing is that it does not use an external crystal to clock the PIC. Using the internal oscillator allows easy adjustment of the MicroMite processing speed. Convenience has its problems. Bob |
||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
Bob D, i have really never had an issue with the ds3231, however, both the ds1307 and the one that mmbasic has a library for (mobile right now, cant look it up) have had a bit more drift than i like. Even the cheap ebay 3231 modules that come with the little ram chip and a battery have worked very very well for me. Anything i built that needed depenability, i would use the adafruit chronodot instead of cheapy modules just in case, but no failures yet with cheapy ones... |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1573 |
Hi Jim, just because I want to get more information. Is this only your "feeling" (a higher price gives better quality), or do you have solid information about the difference? (chronodot vs china ds3231 modules.) I can only see a smaller battery. I only got the schematics for china modules. @atmega8 Have you ever considered using a (dynamical) correction factor? One could adjust this factor every hour after reading the ds3231. This should - theoretical - give very exact results. Regards Michael causality ≠correlation ≠coincidence |
||||
BobD![]() Guru ![]() Joined: 07/12/2011 Location: AustraliaPosts: 935 |
Jim, unless the Chinese are making fake DS3231s (another story maybe) then the chip you get from China is the same one you get on the Chronodot except the Chinese are putting rechargeable batteries in their circuit modules and they are rectangular instead of circular PC boards. My experience with the DS3231 (sourced from China) has been that even after several months the drift on the couple I have checked, has been hard to measure unless you are setting it and checking it programmatically with the timing from a GPS. After that I didn't bother. Bob |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6269 |
The internal oscillator on the micromite is an RC oscillator, not a Chrystal. From the manual: I found that for an interrupt every 5 minutes, I could tweek the timing by using SETTICK 300020 instead of SETTICK 300000 The timing will vary with temperature so you could spend a lot of time trying to get it right for a particular chip. If you have a RTC, you will have to decide how often you need to reset the micromite internal timer. That will depend on your application. Jim VK7JH MMedit |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6269 |
I like the PCF8563. Even though it is not the most accurate RTC available, the interrupt makes it very easy to use for timed events. This code is part of a data-logger. I have removed the irrelevant code, leaving the RTC parts. If you use another RTC, you will have to write your own code for setting the micromite's clock. The interrupt pin on the RTC is connected to pin 5 if the micromite with a 10k pullup resistor to 3.3V ' PCF8563 RTC used as a timed interrupt
' TassyJim 12 OCT 2014 DIM RTCbuffer(16) PCF8563address = &h51 ' r = setRTC() ' only do this if the MicroMite clock has been set first RTC GETTIME PRINT "Startup at ";TIME$;" ";DATE$ I2C OPEN 400, 200 ' Enable I2C. use slow speeds for long leads PAUSE 20 'r=setRTCint(10,2) ' set RTC to interrupt every 10 seconds r=setRTCint(1,3) ' set RTC to interrupt every 1 minutes 'r=setRTCalarm(16,01) ' set the once a day alarm SETPIN 5, INTL, doread ' set the interupt routine doread ' do an initial reading DO k$=INKEY$ 'if k$="C" or k$="c" then r = setRTC() LOOP UNTIL k$=CHR$(27) END SUB doread r= clearRTCalarm() 'do all your routines RTC GETTIME ' keep the MicroMite time correct PRINT TIME$;" etc" END SUB FUNCTION setRTCint(count,scale) ' scale: 2 = seconds, 3 = minutes LOCAL t_ctrl t_ctrl = 128 + scale I2C WRITE PCF8563address,0,1, &H00 ' set the starting address for a read I2C READ PCF8563address,0,16,RTCbuffer(0) I2C WRITE PCF8563address,0,2, &H01, &H11 I2C WRITE PCF8563address,0,3, &H0E, t_ctrl, count' timer control register setRTCint=RTCbuffer(1) END FUNCTION FUNCTION setRTCalarm(hour, minute,day,WkDay) LOCAL alarmH,alarmM,alarmD,alarmWD alarmH=INT(hour/10)*16+(hour MOD 10) 'alarmH=128 ' not used (once an hour) alarmM=INT(minute/10)*16+(minute MOD 10) 'alarmD=int(day/10)*16+(day mod 10) alarmD=128 ' not used (every day) 'alarmWD=WkDay alarmWD=128 ' not used (every day) I2C WRITE PCF8563address,0,1, &H00 I2C READ PCF8563address,0,16,RTCbuffer(0) I2C WRITE PCF8563address,0,2, &H01, &H12 I2C WRITE PCF8563address,0,5, &H09, alarmM, alarmH,alarmD, alarmWD setRTCint=RTCbuffer(1) END FUNCTION FUNCTION setRTC() ' set the RTC to MicroMite time LOCAL newtime$, year, month, day, hour, min, sec newtime$= TIME$ ' make a copy to stop time changing while we set the clock year = VAL(MID$(DATE$,9)) month = VAL(MID$(DATE$,4,2)) day = VAL(MID$(DATE$,1,2)) hour = VAL(MID$(newtime$,1,2)) min = VAL(MID$(newtime$,4,2)) sec = VAL(MID$(newtime$,7,2)) RTC SETTIME year,month,day,hour,min,sec END FUNCTION FUNCTION clearRTCalarm() ' two bits indicate if alarm or timer triggered the interupt ' we clear them both LOCAL x I2C WRITE PCF8563address,0,1, &H00 I2C READ PCF8563address,0,2,RTCbuffer(0) x = (RTCbuffer(1) AND &H13) I2C WRITE PCF8563address,0,2, &H01, x clearRTCalarm=RTCbuffer(1) AND &H0C ' 8 = alarm and 4 = timer END FUNCTION I would like the option to 'fine tune' the micromite's internal clock but I am not sure if it is feasible and too many users will spend all their spare time tweaking' instead of coding. Jim VK7JH MMedit |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9589 |
[quote]I would like the option to 'fine tune' the micromite's internal clock but I am not sure if it is feasible and too many users will spend all their spare time tweaking' instead of coding. [/quote] Nicely put. ![]() To me, 5 seconds in an hour is nothing to worry about, but then this is ME! ![]() In a nutshell - if you NEED to-the-second accuracy, then you really must use an external accurate RTC such as the 3231 or 3232. These things really are very, very accurate indeed, and you would be able to recoup your 5 second per-hour loss, if you use one of those. The only downside is cost - the 3232(not the cheap 3231 module) is about 5x the price of the PIC32 chip, but then, if you NEED that accuracy..... Be careful with the cheap modules. I bought a few in, and one of them just stopped responding after a week or so. It ran fine up till then, but then would not respond to any I2C commands anymore. The EEPROM could still be addressed. Removing a replacing battery did not help - I binned it. For the price that they are, I'm inclined to think that something has to give..... The 3232's I have I got from Element 14. While much more expensive then the cheap modules, at least it will be the genuine part - I suspect the cheap eBay ones have to be clones to be able to sell them at the price they do. ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
hitsware Guru ![]() Joined: 23/11/2012 Location: United StatesPosts: 535 |
http://www.picaxe.com/BASIC-Commands/Advanced-PICAXE-Configu ration/calibfreq/ |
||||
viscomjim Guru ![]() Joined: 08/01/2014 Location: United StatesPosts: 925 |
Is this only your "feeling" (a higher price gives better quality), or do you have solid information about the difference? My customers have the "feeling" and are willing to pay for premium components. After reading many a post about actual experiences with the cheap chinese boards, I can't justify "feelings" to my paying customers. My hobby projects "feel" better the cheaper they are. |
||||
atmega8![]() Guru ![]() Joined: 19/11/2013 Location: GermanyPosts: 724 |
Hi Hitsware, this is interesting, the AVR controllers also have this option and i was wondering if the Pics have not... I think it would be a good feature if Geoff can integrate this calibration feature. It will not supersede an external RTC, but can help to give better accurancy. What do the others think? Geoff? THX |
||||
jman![]() Guru ![]() Joined: 12/06/2011 Location: New ZealandPosts: 711 |
Did you run them on 3.3v or 5V ? as I had this issue and with them running on 5V them seem to be fine Jman |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3282 |
As it happens, this is already on my ToDo list for investigation. It should be easy so I cannot see any problem with implementing it. It will be something like: OPTION CLOCK +/-nn Geoff Geoff Graham - http://geoffg.net |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1573 |
@Jim thx for clarifying! ---------------------- About DS3231 Jman wrote: that's also my opinion. But I don't know the influence of (jumper) cables (at 3,3V). No issues were encountered at 5V. Michael causality ≠correlation ≠coincidence |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
Oh; that old debate about cheap Chinese modules YET again!!! Let me put this to you all - there are 'cheap' GPS modules from FleaBay that will give you a very accurate time reference (location accuracy may not be too good mind!). So RTCs can be replaced to save the 'hassle' of 'tweaking' which may anyway then eventually 'drift' with varying temperatures/voltages/silicon, etc. So these (cheap) GPS modules are a very suitable solution for time keeping. Yes they may draw a lot more current compared to an RTC but why not wake them periodically and then set the TIME$ and DATE$ strings based on the values received from the GPS. Low cost (fake) GPS units can be below $10 but they require ZERO calibration. Better still, buy a decent GPS unit such as a UBLOX 7/8 or a GENUINE EM40x from a recognised supplier. I have a GPS clock that has been running for several months (UBLOX 7) and is with 1 second accuracy (daylight saving coming up in the next couple of weeks to test auto adjustment). Moral of this post - cheap has its place 'sometimes' but for convenience I would only recommend GENUINE. WW |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9589 |
I just dug up the PCB design that was using these modules, and I was feeding them 5v from a regulated(1703-50) and decoupled supply(100uF and 100n). As I say - it worked just fine for about a week, maybe two, then it just stopped responding. I removed the module and breadboarded it to isolate a potential PCB problem or PSU issue, but it remained totally dead - I binned it. After a little digging around in my partz, I found a static sheild bag with about 10 DS3232's in them, with Element 14 sticker, so these would be the genuine DS part. As I have stock of these, I won't bother with the cheaper modules. The main issue I have with the dirt-cheap stuff, is reliablility. Cloned stuff is much cheaper, but tends to be cheaper for a reason. ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
Page 1 of 2 ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |