Let's say you have a SBC with a variable clock frequency. Let's also say you have a (not so perfect) RTC, in the form of a 6526 with its TOD registers, so you can measure time with 0.1s precision.
You also have 4 16 bit timers (2 on the 6526, 2 on the 6522). Unfortunately, there's no easy way to chain both devices, although there may be a way if needed. Still, with a 32bit counter, we can count up to 4Billion PHI2 ticks.
Now, there are some delays I need to program in my firmware, and until now, I'm stuck at 1MHz so I can have this delay to be pretty much constant, no need to adjust for different speeds.
I'd like to be able to measure the clock speed, so I can tune this delay to the current speed.
The first thing that comes into my mind... Set TOD to a known value, start a 32 bit counter combining 2 of the timers. Set a TOD alarm n seconds later and, depending on the value of the counter/timer, we can infer the clock speed.
It seems doable, but this may be the most complicated thing I've ever tried on assembly... Mostly because I haven't tried many things of course.
I'm going to start working on it this weekend, so I'm not looking for a solution, but I wanted to hear other people's approaches to this problem.
Oh! One last thing. Yes, a real 6526 won't go too fast anyway. All the spares I have are not even the 6526A rated for 2Mhz, but I hope this will
Cheers!