-
• #2
It sounds a lot like you're still working off the internal oscillator... That kind of accuracy is what you'd expect from it.
Can you try copying and pasting this into the console?
["NONE","LSE","LSI","HSE"][((peek32(0x40021020)&768)>>8)]
If the watch crystal is working properly, it should return 'LSE', but if not it'd return 'LSI'.
The fading shouldn't interfere with the RTC at all... You're using setInterval there, which should be absolutely fine - but you can now actually use the Date class and clock module if you want to. It means that you don't have to keep track of time every second if you don't want to, and you get the day of the week/etc too:
var Clock = require("clock").Clock; var clk=new Clock("Jun 23, 2014 12:18:02"); // every time the button is pressed, print the current time.. setInterval(function() { var d=clk.getDate(); // you can then use d.getHours() and g.getMinutes() }, 10000/*or whatever*/);
As far as the non-linear fading, I'm not sure. Is it not just that the light you're using is itself non-linear? For instance I believe that if you have an LED, pulsing it at 10% duty cycle will probably generate more than 10% of the light that you'd get by running it at 100% duty cycle.
You might also find that specifying a frequency when using
analogWrite
would help out with that:analogWrite(port.pin,port.brightness,{freq:500});
-
• #3
Hi Gordon,
Thanks for the answer, I'll test this as soon as I have time!
Regards.
Alex
-
• #4
(on a sidenote, the forum isn't remembering notify by email?)
-
• #5
Hi Gordon,
It's returning LSE, also I clocked it again, 8 seconds on 3 minutes. There's also a HM-10 on these espruino's, would that matter? Its only a serial connection right?
Regards,
Alex
-
• #6
Ok, that's good then. Hm10 won't be an issue.
Can you check the value from getTime and see if that wanders off, or whether it's just setInterval?
-
• #7
Just wondering, is it possible that the crystal you're using is 32000hz and not 32768hz? I just assumed that all 32khz crystals were the latter (because of how they'd be used), but maybe not...
8 secs in 3 minutes is very close to the difference between the two crystals. If it's accurately losing that much time you could just correct it in the value you give to setInterval.
-
• #8
Hi Gordon,
I'm yet to test the getTime function but I ordered these crystals:
http://nl.farnell.com/jsp/search/productdetail.jsp?SKU=1652573Unless they gave me the wrong ones It should be 32768hz..
-
• #9
Yes, those look perfect. It'd definitely be interesting to see whether
getTime
has problems too.Does it seem like Espruino's internal clock is running too quickly, or too slowly?
-
• #10
Hi Gordon,
I tried getTime with one of them. Here are the results:
Running onInit()... 22 27 1 8.89654541015 22 27 2 9.87362384796 22 27 3 10.85043907165 >["NONE","LSE","LSI","HSE"][((peek32(0x40021020)&768)>>8)] ="LSE" 22 27 4 11.82781124114 22 27 5 12.80497169494 22 27 6 13.78127479553 22 27 7 14.75885581970 22 27 8 15.73618793487 22 27 9 16.71329021453 22 27 10 17.68983268737 22 27 11 18.66729640960 22 27 12 19.64469623565 22 27 13 20.62130546569 22 27 14 21.59873771667 22 27 15 22.57538700103 22 27 16 23.55257987976 22 27 17 24.52955722808 22 27 18 25.50629901885 22 27 19 26.48370838165 22 27 20 27.46107578277 22 27 21 28.43755435943 22 27 22 29.41496467590 22 27 23 30.39203929901 22 27 24 31.36863899230 22 27 25 32.34608268737 22 27 26 33.32317829132 22 27 27 34.30036544799 22 27 28 35.27692508697 22 27 29 36.25446891784 22 27 30 37.23196983337 22 27 31 38.20841407775 22 27 32 39.17696094512 22 27 33 40.14436244964 22 27 34 41.11141586303 22 27 35 42.07813072204 22 27 36 43.04565048217 22 27 37 44.01294136047 22 27 38 44.97966384887 22 27 39 45.94723033905 22 27 40 46.91443347930 22 27 41 47.88146877288 22 27 42 48.84821319580 22 27 43 49.81562614440 22 27 44 50.78271198272 22 27 45 51.74902725219 22 27 46 52.71672534942 22 27 47 53.68405914306 22 27 48 54.65052795410 22 27 49 55.61753273010 22 27 50 56.58525753021 22 27 51 57.55184650421 22 27 52 58.51905536651 22 27 53 59.48586845397 22 27 54 60.45320510864 22 27 55 61.42058277130 22 27 56 62.38734245300 22 27 57 63.35481452941 22 27 58 64.32194614410 22 27 59 65.28926372528 22 28 0 66.25617694854 22 28 1 67.22333431243 22 28 2 68.19010353088 22 28 3 69.15674114227 22 28 4 70.12435626983 22 28 5 71.09159755706 22 28 6 72.05858993530 22 28 7 73.02545547485 22 28 8 73.99303150177 22 28 9 74.95989799499 22 28 10 75.92654418945 22 28 11 76.89402294158 22 28 12 77.86119842529 22 28 13 78.82830810546 22 28 14 79.79456424713 22 28 15 80.76237297058 22 28 16 81.72950744628 22 28 17 82.69598865509 22 28 18 83.66352081298 22 28 19 84.63085842132 22 28 20 85.59737682342 22 28 21 86.56439304351 22 28 22 87.53121662139 22 28 23 88.49844074249 22 28 24 89.46592426300 22 28 25 90.43259620666 22 28 26 91.40005779266 22 28 27 92.36719226837 22 28 28 93.33396911621 22 28 29 94.30138015747 22 28 30 95.26851844787 22 28 31 96.23584556579 22 28 32 97.20260143280 22 28 33 98.17017459869 22 28 34 99.13756942749 22 28 35 100.10418987274 22 28 36 101.07176780700 22 28 37 102.03902435302 22 28 38 103.00602912902 22 28 39 103.97282505035 22 28 40 104.94040489196 22 28 41 105.90770339965 22 28 42 106.87440109252 22 28 43 107.84176254272 22 28 44 108.80907344818 22 28 45 109.77622699737 22 28 46 110.74252700805 22 28 47 111.71034812927 22 28 48 112.67763710021 22 28 49 113.64414405822 22 28 50 114.61173534393 22 28 51 115.57839584350 22 28 52 116.54544925689 22 28 53 117.51273441314 22 28 54 118.47938537597 22 28 55 119.44679546356 22 28 56 120.41403484344 22 28 57 121.38079738616 22 28 58 122.34818935394 22 28 59 123.31535625457 22 29 0 124.28244972229 22 29 1 125.24951934814 22 29 2 126.21704196929 22 29 3 127.18405437469 22 29 4 128.15081787109 22 29 5 129.11840724945 22 29 6 130.08529472351 22 29 7 131.05198574066 22 29 8 132.01952838897 22 29 9 132.98675060272 22 29 10 133.95380210876 22 29 11 134.92061901092 22 29 12 135.88815116882 22 29 13 136.85531616210 22 29 14 137.82149314880 22 29 15 138.78920650482 22 29 16 139.75653076171 22 29 17 140.72360706329 22 29 18 141.69012451171 22 29 19 142.65779495239 22 29 20 143.62495136260 22 29 21 144.59137916564 22 29 22 145.55818462371 22 29 23 146.52558612823 22 29 24 147.49297714233 22 29 25 148.45994281768 22 29 26 149.42677593231 22 29 27 150.39429092407 22 29 28 151.36148071289 22 29 29 152.32823085784 22 29 30 153.29566287994 22 29 31 154.26294803619 22 29 32 155.22980785369 22 29 33 156.19702720642 22 29 34 157.16458511352 22 29 35 158.13157749176 22 29 36 159.09837818145 22 29 37 160.06590938568 22 29 38 161.03356742858 22 29 39 162.00023937225 22 29 40 162.96779060363 22 29 41 163.93502902984 22 29 42 164.90207576751 22 29 43 165.86882972717 22 29 44 166.83629417419 22 29 45 167.80352115631 22 29 46 168.76992511749 22 29 47 169.73762893676 22 29 48 170.70493888854 22 29 49 171.67143344879 22 29 50 172.63846778869 22 29 51 173.60614681243 22 29 52 174.57280635833 22 29 53 175.53966617584 22 29 54 176.50644588470 22 29 55 177.47377395629 22 29 56 178.44114017486 22 29 57 179.40784454345 22 29 58 180.37530517578 22 29 59 181.34243965148 22 30 0 182.30955028533 22 30 1 183.27625942230 22 30 2 184.24385643005 22 30 3 185.21126842498 22 30 4 186.17786598205 22 30 5 187.14545059204 22 30 6 188.11270713806 22 30 7 189.07970333099 22 30 8 190.04650974273 22 30 9 191.01412582397 22 30 10 191.98157882690 22 30 11 192.94823455810 22 30 12 193.91568279266 22 30 13 194.88286590576 22 30 14 195.84993267059 22 30 15 196.81623935699 22 30 16 197.78408527374 22 30 17 198.75120639801 22 30 18 199.71769332885 22 30 19 200.68547439575 22 30 20 201.65268230438 22 30 21 202.61917877197 22 30 22 203.58617210388 22 30 23 204.55388450622 22 30 24 205.52055644989 22 30 25 206.48801231384 22 30 26 207.45453739166 22 30 27 208.42182731628 22 30 28 209.38918209075 22 30 29 210.35595798492 22 30 30 211.32342720031 22 30 31 212.29054927825 22 30 32 213.25790596008 22 30 33 214.22473812103 22 30 34 215.19185161590 22 30 35 216.15999317169 22 30 36 217.12664890289 22 30 37 218.09422779083 22 30 38 219.06140232086 22 30 39 220.02842235565 22 30 40 220.99529457092 22 30 41 221.96289157867 22 30 42 222.93021774291 22 30 43 223.89696311950 22 30 44 224.86442661285 22 30 45 225.83157253265 22 30 46 226.79866313934 22 30 47 227.76496028900 22 30 48 228.73280620574 22 30 49 229.70020866394 22 30 50 230.66671943664 22 30 51 231.63428211212 22 30 52 232.60087776184 22 30 53 233.56793117523 22 30 54 234.53498554229 22 30 55 235.50187206268 22 30 56 236.46923542022 22 30 57 237.43669700622 22 30 58 238.40335559844 22 30 59 239.37069702148 22 31 0 240.33797454833 22 31 1 241.30460739135 22 31 2 242.27206420898 22 31 3 243.23953437805 22 31 4 244.20658493041 22 31 5 245.17336845397 22 31 6 246.14100742340 22 31 7 247.10786342620 22 31 8 248.07446098327 22 31 9 249.04199314117 22 31 10 250.00922775268
In case its not clear: HH-mm-ss getTime().
getTime() does seem to be OK, 4 minutes take 232 seconds, which is what the getTime() tells us and what I clocked on a stopwatch.
I soldered on a new crystal (same batch) with these results. I'll check the other espruino..
-
• #11
Here is the other one, v1.65
Running onInit()... 22 27 1 21.6793498992919921875 22 27 2 22.6577320098876953125 22 27 3 23.63539981842041015625 22 27 4 24.6135311126708984375 22 27 5 25.59200000762939453125 22 27 6 26.56999301910400390625 22 27 7 27.54819965362548828125 22 27 8 28.5260028839111328125 22 27 9 29.504459381103515625 22 27 10 30.48296642303466796875 22 27 11 31.460605621337890625 22 27 12 32.4389801025390625 22 27 13 33.4174594879150390625 22 27 14 34.39554691314697265625 22 27 15 35.373382568359375 22 27 16 36.35190486907958984375 22 27 17 37.33017826080322265625 >["NONE","LSE","LSI","HSE"][((peek32(0x40021020)&768)>>8)] ="LSE" 22 27 18 38.30799102783203125 22 27 19 39.28640842437744140625 22 27 20 40.26471233367919921875 22 27 21 41.24311065673828125 22 27 22 42.220947265625 22 27 23 43.19915866851806640625 22 27 24 44.17764949798583984375 22 27 25 45.1553211212158203125 22 27 26 46.13389301300048828125 22 27 27 47.1121234893798828125 22 27 28 48.09015178680419921875 22 27 29 49.06807708740234375 22 27 30 50.04666805267333984375 22 27 31 51.024890899658203125 22 27 32 51.99732208251953125 22 27 33 52.96969318389892578125 22 27 34 53.9417438507080078125 22 27 35 54.91380405426025390625 22 27 36 55.88543605804443359375 22 27 37 56.85776805877685546875 22 27 38 57.8298473358154296875 22 27 39 58.8011150360107421875 22 27 40 59.7736797332763671875 22 27 41 60.7458362579345703125 22 27 42 61.7172794342041015625 22 27 43 62.68971729278564453125 22 27 44 63.66189670562744140625 22 27 45 64.63356304168701171875 22 27 46 65.6055278778076171875 22 27 47 66.57803249359130859375 22 27 48 67.5496959686279296875 22 27 49 68.52170467376708984375 22 27 50 69.493465423583984375 22 27 51 70.46565341949462890625 22 27 52 71.4378414154052734375 22 27 53 72.40976047515869140625 22 27 54 73.38159942626953125 22 27 55 74.3539581298828125 22 27 56 75.32599544525146484375 22 27 57 76.29769992828369140625 22 27 58 77.26997280120849609375 22 27 59 78.24228382110595703125 22 28 0 79.2143840789794921875 22 28 1 80.1859912872314453125 22 28 2 81.15838527679443359375 22 28 3 82.13042449951171875 22 28 4 83.10216045379638671875 22 28 5 84.07446765899658203125 22 28 6 85.04660129547119140625 22 28 7 86.0183620452880859375 22 28 8 86.99079799652099609375 22 28 9 87.96288013458251953125 22 28 10 88.93489551544189453125 22 28 11 89.9065151214599609375 22 28 12 90.87888813018798828125 22 28 13 91.85096645355224609375 22 28 14 92.822284698486328125 22 28 15 93.794811248779296875 22 28 16 94.76702117919921875 22 28 17 95.73899173736572265625 22 28 18 96.71039485931396484375 22 28 19 97.6830501556396484375 22 28 20 98.6552276611328125 22 28 21 99.62683391571044921875 22 28 22 100.59920978546142578125 22 28 23 101.5708065032958984375 22 28 24 102.54278850555419921875 22 28 25 103.5148906707763671875 22 28 26 104.48648929595947265625 22 28 27 105.4586944580078125 22 28 28 106.43090152740478515625 22 28 29 107.402645111083984375 22 28 30 108.374965667724609375 22 28 31 109.3471012115478515625 22 28 32 110.31902313232421875 22 28 33 111.2907810211181640625 22 28 34 112.263031005859375 22 28 35 113.23541259765625 22 28 36 114.20707225799560546875 22 28 37 115.179164886474609375 22 28 38 116.15148448944091796875 22 28 39 117.123111724853515625 22 28 40 118.09561920166015625 22 28 41 119.067718505859375 22 28 42 120.03966426849365234375 22 28 43 121.01142406463623046875 22 28 44 121.9838428497314453125 22 28 45 122.95589733123779296875 22 28 46 123.92756175994873046875 22 28 47 124.89993381500244140625 22 28 48 125.871959686279296875 22 28 49 126.843891143798828125 22 28 50 127.81539154052734375 22 28 51 128.7880573272705078125 22 28 52 129.7601871490478515625 22 28 53 130.73161220550537109375 22 28 54 131.70409107208251953125 22 28 55 132.676342010498046875 22 28 56 133.647891998291015625 22 28 57 134.6198272705078125 22 28 58 135.59224605560302734375 22 28 59 136.56395053863525390625 22 29 0 137.5361194610595703125 22 29 1 138.50775909423828125 22 29 2 139.4799404144287109375 22 29 3 140.45213985443115234375 22 29 4 141.42403125762939453125 22 29 5 142.39580821990966796875 22 29 6 143.36806964874267578125 22 29 7 144.34004116058349609375 22 29 8 145.31172847747802734375 22 29 9 146.283924102783203125 22 29 10 147.25627994537353515625
Also not correct, yet it shows in the getTime(), same as my stopwatch.
The first espruino is v1.67.It seems to be much worse after I upload the code and type save(). If I just upload the code and manually call onInit() it it better. Here is the manually called onInit of the 1.67:
22 27 1 62.04144763946 22 27 2 63.01845932006 22 27 3 63.99542236328 22 27 4 64.97240543365 22 27 5 65.94935226440 22 27 6 66.92637348175 22 27 7 67.90332508087 22 27 8 68.88040161132 22 27 9 69.85738754272 22 27 10 70.83437252044 22 27 11 71.81145000457 22 27 12 72.78848361968 22 27 13 73.76540756225 22 27 14 74.74249744415 22 27 15 75.71944808959 22 27 16 76.69649982452 22 27 17 77.67348861694 22 27 18 78.65042209625 22 27 19 79.62742900848 22 27 20 80.60446739196 22 27 21 81.58142375946 22 27 22 82.55840396881 22 27 23 83.53532123565 22 27 24 84.51234245300 22 27 25 85.48942184448 22 27 26 86.46641731262 22 27 27 87.44345855712 22 27 28 88.42042732238 22 27 29 89.39747524261 22 27 30 90.37452411651 22 27 31 91.35165119171 22 27 32 92.31992244720 22 27 33 93.28700923919 22 27 34 94.25407695770 22 27 35 95.22115898132 22 27 36 96.18831157684 22 27 37 97.15537548065 22 27 38 98.12246131896 22 27 39 99.08957481384 22 27 40 100.05665969848 22 27 41 101.02373504638 22 27 42 101.99077320098 22 27 43 102.95787715911 22 27 44 103.92503166198 22 27 45 104.89206600189 22 27 46 105.85916900634 22 27 47 106.82629871368 22 27 48 107.79339790344 22 27 49 108.76051902770 22 27 50 109.72761917114 22 27 51 110.69474792480 22 27 52 111.66183185577 22 27 53 112.62894058227 22 27 54 113.59606552124 22 27 55 114.56319427490 22 27 56 115.53030586242 22 27 57 116.49734687805 22 27 58 117.46439456939 22 27 59 118.43156623840 22 28 0 119.39883327484 22 28 1 120.36578750610 22 28 2 121.33287811279 22 28 3 122.30000400543 22 28 4 123.26710796356 22 28 5 124.23418426513 22 28 6 125.20124530792 22 28 7 126.16832637786 22 28 8 127.13538837432 22 28 9 128.10246276855 22 28 10 129.06960964202 22 28 11 130.03668880462 22 28 12 131.00378131866 22 28 13 131.97083473205 22 28 14 132.93795204162 22 28 15 133.90508079528 22 28 16 134.87220001220 22 28 17 135.83931541442 22 28 18 136.80638217926 22 28 19 137.77352046966 22 28 20 138.74057006835 22 28 21 139.70764160156 22 28 22 140.67482089996 22 28 23 141.64192008972 22 28 24 142.60910320281 22 28 25 143.57615947723 22 28 26 144.54324245452 22 28 27 145.51032924652 22 28 28 146.47754764556 22 28 29 147.44473648071 22 28 30 148.41178321838 22 28 31 149.37881755828 22 28 32 150.34591579437 22 28 33 151.31318759918 >["NONE","LSE","LSI","HSE"][((peek32(0x40021020)&768)>>8)] ="LSI" 22 28 34 152.28048610687 >["NONE","LSE","LSI","HSE"][((peek32(0x40021020)&768)>>8)] ="LSI" 22 28 35 153.24770450592 22 28 36 154.21473979949 22 28 37 155.18192100524 22 28 38 156.14902687072 22 28 39 157.11621379852 22 28 40 158.08322429656 22 28 41 159.05019569396 22 28 42 160.01736259460 22 28 43 160.98453330993 22 28 44 161.95175552368 22 28 45 162.91889667510 22 28 46 163.88599586486 22 28 47 164.85312747955 22 28 48 165.82012844085 22 28 49 166.78721332550 22 28 50 167.75431919097 22 28 51 168.72135639190 22 28 52 169.68845653533 22 28 53 170.65542411804 22 28 54 171.62252998352 22 28 55 172.58959102630 22 28 56 173.55673122406 22 28 57 174.52383327484 22 28 58 175.49096393585 22 28 59 176.45804309844 22 29 0 177.42534351348 22 29 1 178.39237117767 22 29 2 179.35943412780 22 29 3 180.32653617858 22 29 4 181.29371166229 22 29 5 182.26078987121 22 29 6 183.22798061370 22 29 7 184.19512653350 22 29 8 185.16219806671 22 29 9 186.12931823730 22 29 10 187.09645080566
This one is LSI again, I don't know why... Time is spot - on though!
-
• #12
It seems to sometimes forget it is LSE. Sometimes when I plug it in, it says LSI, then I reset it (with the button) and it is LSE again. When it was LSI the timing was correct. Any ideas? Either I'm a sucky (though very consistent :)) solderer or something somewhere is wrong...
-
• #13
I think it can take a few seconds to switch over to LSE - the oscillator takes a while to stabilise and Espruino runs off of LSI until it has. If it fails to start the oscillator (note that you can't use C15 for anything as that is an oscillator pin) then it'll stay with LSI, so that could be what's happening in some cases?
So you're saying that the time from
getTime
is always correct, but it's just the interval that isn't working properly? If so it'll be some issue with the Espruino firmware itself. -
• #14
This is definitely some issue with Espruino... My guess is that when the intervals changed (with the 32 bit switch) something got messed up. I'll look into it and should hopefully get a fix in for the 1v68 version.
-
• #15
Ok, fixed. You can try out a pre-release build (once it has built) in an hour or so at:
http://www.espruino.com/binaries/git/commits/b7e330060a3c0d7ff1fe56583cd0e57caa749849
Just go there, copy the link address of the binary, and paste it into the 'advanced flasher' text box in the Web IDE's settings page.
-
• #16
Hi Gordon,
Thanks for the fix! I'll wait for 1.68 before trying it out since I'll be on holidays anyway. Glad you found it so quickly!
Regards
Hi All,
I have two espruino's both with:
http://www.espruino.com/Clocks
The 32Khz Watch Crystal soldered onto it. I tried the clock example from that page as well as my own implementation and there is quite a big drift: depending on which espruino I use, 1 - 3 seconds on the minute.
Did anyone else notice this?
The program I want to use this for is a simple light switch. On in the morning, off in the afternoon.
Would the fading interfere with the clock?
Regards,
Alex
PS. also the fading isn't linear.. it seems to be faster and slower during the fading cycle.