Need a clock for building a lab timer - Page 1
Forum section: electronics / projects

author: ballsystemlord
author_rank: Frequent Contributor
timestamp: September 08, 2025, 07:05:13 pm
content: Hello,So you may recall that a month or so ago Dave showed off his lab timer. I decided I needed one and I set out to design one myself. As an aside, unbeknownst to me, Dave also embarked on the project (and AFAIK we're not competing or anything as our designs are rather different).Well, I'm stuck now. I've been looking at RTCs, but I cannot find one with millisecond timing. Granted, I don't need to time something over the course of days with millisecond precision, but I can see projects where I'd want to time things at the millisecond level.I'm thinking that people would normally use their uC to time things at the millisecond level, but I'm uncertain and so I'm asking for advice.How do you time things with millisecond precision? Is there a dedicated timer chip for that or what?Thanks!

author: PCB.Wiz
author_rank: Super Contributor
timestamp: September 08, 2025, 07:38:17 pm
content: There are many questions here.RTC’s clock at 32768, so that gives a ~30us granularity, which is one peg in the sand.Many RTC can drive a pin at some divided rate, to clock something external, but one detail to watch is tcxo rtc’s may not apply the correction to all higher frequency choices.RTC are not great at capture, so that is why MCU are a more common choice if you want timing captures.If you want to capture to 1ms LSB, that's 32.768 cycles of a RTC clk, which is relatively easy to manage in software, as the fractional 0.768 = 96/125Or you can capture to the ~ 30us edge rate, and decide later what precision you want.The best fit low power MCU would be one that allows capture from a timer clocked from the LF Xtal, but if power is no concern pretty much any modern MCU can interrupt at 32768Hzlcsc have some interesting 32Khz oscillators that are actually faster xtals divided, so their temperature curves are far better that the poor parabolic tuning forks.

author: themadhippy
author_rank: Super Contributor
timestamp: September 08, 2025, 07:58:18 pm
content: 1 millisecond is rather pedestrian, ya can get that sorta time out a 555 without breaking a sweat,getting it accurately is were the fun starts.

author: ledtester
author_rank: Super Contributor
timestamp: September 09, 2025, 12:18:07 am
content: You might want to look at this clock which displays the time with millisecond precision:https://mitxela.com/projects/precision_clock_mk_iv

author: thm_w
author_rank: Super Contributor
timestamp: September 09, 2025, 12:59:54 am
content: I don't see why you'd even need an RTC unless you care about storing the date and time for long periods of time (weeks, months).If its just a timer all you'd need is a crystal/xtal/tcxo/etc with whatever accuracy you require, and the MCU.edit: the design linked above uses a TCXO

author: shabaz
author_rank: Frequent Contributor
timestamp: September 09, 2025, 01:42:59 am
content: I don't know if this is useful info or not, but a frequency counter might be useful, they shouldn't be too expensive used on ebay theoretically (but a lot are overpriced it seems, I don't know why; personally I wouldn't pay more than $100-$150 for the very old ones on ebay from time to time, but often they are listed at several times that price).The attached one is low-cost on aliexpress, but I've no idea if it's any good or not (plus import duty issues).It does mention period measurement in the text (usually that should mean either from the front panel, or trigger from the BNC as desired, often with some configurable start/stop options). Or if you meant start/stop just from a push-button, then this is overkill.I don't know if it's relevant to you since you may prefer to DIY and maybe have different features, but maybe it helps others (please don't blame me if it isn't any good; I've not seen any review of it, just randomly saw it on Aliexpress).EDIT: 30-sec video of it here, but it doesn't explain anything, just shows what it looks like powered up.

author: themadhippy
author_rank: Super Contributor
timestamp: September 09, 2025, 01:59:16 am
content: QuoteOr if yer a bit of a masochist a few counters ,gates ect, now were did i put them 74390's and 7447's

author: PCB.Wiz
author_rank: Super Contributor
timestamp: September 09, 2025, 03:51:27 am
content: Quote from: ballsystemlord on September 08, 2025, 07:05:13 pmThe TI SN74LV8154 is maybe close, it can do counting and capture, but still needs parts to get that info to a user, and costs more than small MCUsQuote from: ballsystemlord on September 08, 2025, 07:05:13 pmA modest MCU is the 'obvious' and 'low power' solution, but for fun I thought what about the less obvious and less 'low power' ?What about a Desktop PC ?Turns out, the answer is 'Yes, you can'I recall the micro frame rate for HS-USB is 125us so it seems that ballpark may be achievable with some relatively simple PC software and aHS-USB Uartwith a handshake line.Summary: The CH347 looks the cheapest solution, the FT232H is more costly, but works well too, and the CH9111 seems 'chunkier' in the timing, but still well inside the OP's 1ms LSB target.On this PC, average timing tick looks to be a surprising ~ 5ppm over an 80 second frame check on a GPS 1pps.First test was to write and readback and check how fast that can beCode:// CH9111 =// Time for 6000 loops, 2546 average(ms) : 4.24333333333333333339E-0001// Set.Clear pair, Min dT(us) 312 Avge dT(us)= 423 Max dT(us) 596 looks roughly 125us granular ?// Set.Clear pair, Min dT(us) 350 Avge dT(us)= 422 Max dT(us) 660// CH347// Set.Clear pair, Min dT(us) 115 Avge dT(us)= 249 Max dT(us) 354 Counter says 4.067kHz// Set.Clear pair, Min dT(us) 156 Avge dT(us)= 249 Max dT(us) 352// Set.Clear pair, Min dT(us) 114 Avge dT(us)= 249 Max dT(us) 349// Set.Clear pair, Min dT(us) 134 Avge dT(us)= 249 Max dT(us) 313// Set.Clear pair, Min dT(us) 82 Avge dT(us) = 249 Max dT(us) 368 quite stable Ctr at 4.000053kHz// Ser.Connect : 535us Ser.Config : 123us// Set.Clear pair, Min dT(us) 130 Avge dT(us)= 249 Max dT(us) 469// Ser.Connect : 326us Ser.Config : 126us// Set.Clear pair, Min dT(us) 92 Avge dT(us)= 249 Max dT(us) 372// FT232H// Set.Clear pair, Min dT(us) 74 Avge dT(us)= 108 Max dT(us) 243 <- WOW faster ? or is it not reading back the latest value ?// Set.Clear pair, Min dT(us) 75 Avge dT(us)= 109 Max dT(us) 338 for 6000// Set.Clear pair, Min dT(us) 73 Avge dT(us)= 106 Max dT(us) 251 for 20000 Ctr says 9.337kHz, so confirms the PC reported times.Seems promising, so now we just poll the CTS pin driven here from aGPS 1pps, and time edges using QueryPerformanceCounter() calls which can give sub microsecond LSB's (100ns on this PC)Code:// CH347 Wch 9MBd HS-USB// PollCTS no timeout// PWus 244281 PERus = 194// PWus 900129 PERus = 344281// PWus 899995 PERus = 1000130// PWus 900002 PERus = 999993// PWus 899994 PERus = 1000003// PWus 900002 PERus = 999994// PWus 899996 PERus = 1000000// PWus 899999 PERus = 999991// PWus 899998 PERus = 1000003// PWus 899996 PERus = 999998// PWus 899993 PERus = 1000002// PWus 899999 PERus = 999991// PWus 900019 PERus = 999977// PWus 899975 PERus = 1000018 << - 125us// PWus 900002 PERus = 999998// PWus 899969 PERus = 1000005// PWus 899990 PERus = 999999// PWus 900127 PERus = 999996 << + 125us// PWus 900004 PERus = 1000121// PWus 900003 PERus = 999997// -10+1+1+35-27+54-52+3+1+0+4-2+8-3+6+3-123-1+4-1+6+0+45-41+8+1+3-3+5-1+7-8-113-2+8-4+4+2+1 = -181// 181/40M = -4.525ppm// FT232H FTDI 12Mbd HS-USB// PWus 358372 PERus = 5// PWus 900001 PERus = 458351// PWus 900014 PERus = 999998// PWus 900004 PERus = 1000012// PWus 899991 PERus = 1000008// PWus 900023 PERus = 999993// PWus 899998 PERus = 1000019// PWus 900017 PERus = 1000001// PWus 900024 PERus = 999996// PWus 899966 PERus = 1000017// PWus 900015 PERus = 999999// PWus 899994 PERus = 1000024// PWus 899966 PERus = 999992// PWus 900013 PERus = 1000003// PWus 899988 PERus = 1000020// PWus 900002 PERus = 1000007// PWus 900062 PERus = 999960// PWus 900008 PERus = 1000044// PWus 900000 PERus = 999996// PWus 900013 PERus = 1000002// +24-18+7-1-20+3-20+1+1-22+10+28-14-28-38+21+2-18-2-17+2-3-13+2-5-14+4-20+3+6-23+2+5-23+6-20+1-30+14-1-19+30-24-23+6-23+6+3-16-2+4-16// -6+7-17-2+10-25+2-22+7-2-13-3-12+25-30-14+33-28-18-1+34-48+3-16+0-1 = -419/80M = -5.2375ppm// -22+3-2-21+13-23+2+15-3+3+4-19-38-9+4-15-6+36-51+3+1-21+3+6-24+10-24+5-3-17+6+0-24+37-46+1+3-24+7-21+6-2-20+10-4-17+32-50+29-24-15// -5-13-1+7-23+5-2-21+8-1-24+9+22-38+0-19+0-17+1+0-23+35-31-9+48-42-26 = -466 /80M = -5.825ppn// -13+6-5+2-24+43-39-14-1+2+12-50+44-35-20+1+4+26-40-21+1+56-71+0-127+111-11+15-21+6-23+9-3-20+5+4+3-25+5-28+10+27-24-43+10-3-21+8// +32-52+0-15-3-19-2+10+5-20-1-17+51-51-29-4+8+2+2-19+1-20+0-6-6-3-11-5+4-18-2 = -460/80M = -5.75ppm// 3rd 80s run does have a 127 quanta appear// CH9111 WCH 15MBd HS-USB// PWus 900075 PERus = 98662// PWus 899988 PERus = 1000119// PWus 899900 PERus = 999995// PWus 900024 PERus = 1000007// PWus 900005 PERus = 1000075// PWus 899913 PERus = 1000027// PWus 900011 PERus = 999985// PWus 899897 PERus = 1000037// PWus 899929 PERus = 999963// PWus 899957 PERus = 999946// PWus 899993 PERus = 999976// PWus 899940 PERus = 1000048// PWus 899997 PERus = 999933// PWus 900114 PERus = 1000009// PWus 899941 PERus = 1000060// PWus 900062 PERus = 999983// PWus 899883 PERus = 1000053// PWus 900106 PERus = 999871// PWus 900007 PERus = 1000103// PWus 900140 PERus = 999962// -34+67+25-45-7-71+12+119-124-110+43+28+0+10+22-57+61-78+70+40-8-25-5+1+9-112-41-101+124-89+106-30+20-93+106-134+10+100 = -191// 40 seconds is -191/40M = -4.775ppm not bad, will be PC based error.// +77-89+127-110-135+33+89-38-76+70-41+61-58+48-70+25+110-101-31-111+75-11-1+59-13-56+83-17-3+32-54+32+25+12-28-218+16+51+45-40// +58-135+48+15-17+71+32+5-54+37-21-190-25+67-31+88-13+25+11-70+5-25+8-13+29+102-15-165+13-101+119+10-36+56-30-88-9+26 = -444// /80M = -5.55ppm - larger peaks on CH9111, 218 and 190 seen