getTime() Accuracy #6137
Replies: 1 comment
-
Posted at 2015-04-05 by alexanderbrevig You might be looking at a deterministic call time for getTime(). Try
Posted at 2015-04-05 by Pinnchus I´m trying to know how much time expend in getTime() and caught my attention the result, is negative ¿?. Posted at 2015-04-05 by alexanderbrevig timeNow - timeSlightlyAfterNow = negative 1 - 2 = -1 :) Posted at 2015-04-05 by Pinnchus Absolutely right, i'm feeling like an idiot. Thanks Posted at 2015-04-05 by @allObjects LOL... been there, will go there again!... It's just life! Posted at 2015-04-06 by alexanderbrevig Me too. It's the programmer's life; content reminders of how stupid** we all are... **at least when we're compared against an even dumber, but perfectly logical minion - such as a micro-controller. Posted at 2019-01-25 by asez73 Hi @gfwilliams, I revive this old thread mainly because of its title. On a Pico 1v3 with Espruino 2.01, I have a time shift of about 4.5 s per minutes: that is, I used new Date() on the console twice, separated by 4 minutes from my PC own time and got 18 s of difference. The pico was in late by that much. This resist to power on/off and getTime() gives the same results. Any idea of why there is such a difference or could it be that a crystal is required? Thanks for your reading anyway. Posted at 2019-01-28 by @gfwilliams Wow, that's really far off. Do you have more than one Pico and they both experience the same issue? Can you try shorting B3 and B4 and:
Any two pins should work. That'll compare the internal RC oscillator with the high speed oscillator. I just tried on one running 2v01 and it returns numbers roughly around 1.01, so that's 1% off. In a minute you might expect half a second. One fix is definitely to add an external oscillator. I guess the other is a firmware change to ignore the RC oscillator completely, but that would then mean deep sleep doesn't work. Would that be an issue for you? Posted at 2019-01-28 by asez73 Hi @gfwilliams, Yes, this is quite far off. Unfortunately, I expect to use:
Actually, I was testing the setTimeout when I found this problem. So Here are the results of the test you proposed: 0.925 seems to be t a constant value.
Posted at 2019-01-28 by @gfwilliams Wow, ok. I don't think I've seen one so far off. Can you check the VCC line and check it really is 3.3v? The early Picos didn't have a very powerful diode and is was easy to slightly frazzle it if they got shorted - in that case it might not be getting the full voltage needed for 3.3v, which might be affecting the RTC speed? But yes, if you need deep sleep I think using an external low speed oscillator (or a whole external RTC like http://www.espruino.com/DS3231) is probably the only solution. Newer Espruino Originals actually have an RTC crystal on them so that could be a good choice? I think the NucleoF401RE doesn't use the RTC so it wouldn't actually keep time properly with deep sleep at all. Posted at 2019-01-28 by asez73 Powered from USB connector I measured: B0 is shorted by a solder bridge which I intend to use powering the pico from Vbat_in while powering my gps receiver from vbat controlled through the mosfet and b0 one day. My pico came from Kickstarter campaign... Posted at 2019-01-28 by @gfwilliams Ok, your Pico would have had the weaker diode in it if it was from the KickStarter, but looking at the voltage you're fine so that won't be the issue. It looks like the internal RC oscillator is just way off. Looking at the source code it's possible I could add something that allowed you to tweak it for a different speed RTC. I don't know if that's something that would help at all? I've just had a go at it but something isn't working right I'm afraid. I need to look into it in a bit more detail. I think realistically fitting the Abracon ABS06-107 is the best way to get decent accuracy though - even tweaking the RTC won't bring it to the same kind of levels you'd get from a proper crystal. Posted at 2019-01-28 by @gfwilliams Ok, fixed it. If you flash a build from http://www.espruino.com/binaries/travis/36e263aabe91be08ebaf60ef1960807963e2130e then it'll have a function called The default value is 32000 (what ST say the internal clock speed should be) but let's say you're getting
It'll take a few seconds to stabilise, and you might need to do some fiddling to get it a bit more accurate, but that should help you out a lot. If it looks like it's something useful I'll see about getting it into the main branch of Espruino. Posted at 2019-01-28 by asez73 Ok, So I flashed this frimware and restarted tests using my Gps provided time. So apparently, if I do E.setPrescaler(32000) then it will drift (same value as usual), while with E.setRTCPrescaler(29536), it is only once (a time sync I think) and not later. Anyway, nice way to correct potential time shifts as it is now possible to measure the coefficient of shift and apply it automatically. Just to ask more, E.getRTCPrescaler() would be usefull too. :) Posted at 2019-01-29 by asez73 Hi again, Let's get started again with this! Posted at 2019-01-29 by @gfwilliams That's great news! The temperature of the chip will affect the RTC speed a little, but that's still a really promising improvement. I'd be interested to see what others think but that sounds like it would be a good thing to merge into normal Espruino. I'll file an issue for it. There is some potential for working out that value automatically as well - it wouldn't be perfect, but would improve the accuracy a lot from what you were seeing at the start! Posted at 2019-01-29 by asez73 So, the results are really promising with little or no more shift with: Note that those figures are now not really meaningfull: The time granularity on gps time and pico's time are 1 second each... So now, more test, more or less at room's constant temperature with: Finally, there is the prescaler granularity too.. Posted at 2019-02-19 by @gfwilliams Ok, it's now merged into master. I added the ability to auto-calibrate with:
as well. It's not going to be amazing, but it'll be miles better than the ~10% we were getting before! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-04-05 by Pinnchus
There is an strange behavior with the getTime() function, if I execute console.log(getTime()-getTime()), always get -0.00004019642 ¿Why?
Example:
Regards,
Pinnchus
Beta Was this translation helpful? Give feedback.
All reactions