Zero Instruction Elapsed Timer

A project log for PIC Graphics Demo

Generate 640x480 64-color VGA graphics with an 8-bit PIC and an SRAM framebuffer

Ted YapoTed Yapo 01/06/2017 at 02:048 Comments

Since these images take so long (hours) to generate, I wanted to be able to time them and report exact run-times. But, I didn't want to add any extra instructions to do it, so I decided to use a very simple, low-tech approach.

I found this clock for $3.88 at Walmart. It normally runs off an AA battery. Instead, I'm running it from an unused output line on the PIC:

The resistor and diodes form a crude 1.4 V regulator. The clock wouldn't run with small capacitors - the hand would twitch but not fully advance. The mechanism must need a hefty current pulse to actually advance it.

I was able to set and clear a bit in the code just by changing the constants that get written to the ports, so I didn't increase the code size at all.

To use the timer, you set the clock to 12:00 before a run, then come back and read off the elapsed time after it's done. For very long runs, you just have to check the clock every 12 hours. This would at first appear to violate the Nyquist criterion, since the period of the clock is 12 hours, meaning you have to sample at least every 6 hours, but it doesn't :-)

I probably won't have timing data before the contest deadline, but I'll post it here when I have it.

The ray-tracing took 1 hour and 28 minutes to run:

I'm timing the fractal code now. I think that takes longer...

Technically, I was correct, the fractal code took longer, but not much: 1 hour and 32 minutes. Funny, they're pretty well matched.

I didn't wait around while I was running these things before - I always kicked them off before going to bed, or something like that.


MortenW wrote 01/06/2017 at 13:09 point

Best looking stop-watch I ever saw. Much more humane than inverting the output and hooking up a relay to a big air-horn.

  Are you sure? yes | no

Ted Yapo wrote 01/06/2017 at 13:49 point

I bought one of these on-sale a while back:

I was thinking of a basement water alarm when I bought it, but it just ended up in one of the parts bins.  Now, you've got me thinking...

  Are you sure? yes | no

Yann Guidon / YGDES wrote 01/06/2017 at 05:33 point

That's a hack !!!

  Are you sure? yes | no

SHAOS wrote 01/06/2017 at 02:48 point

Cool :)

  Are you sure? yes | no

esot.eric wrote 01/06/2017 at 02:30 point

"appear to violate the Nyquist criterion" LOL

  Are you sure? yes | no

Ted Yapo wrote 01/06/2017 at 02:41 point

My conclusion was that you get away with it because reading the time is a direct phase measurement, not amplitude.

  Are you sure? yes | no

esot.eric wrote 01/06/2017 at 03:50 point

Take That, Nyquist!

  Are you sure? yes | no

Ted Yapo wrote 01/06/2017 at 03:53 point

@esot.eric I almost fell out of my chair laughing when I read that...

  Are you sure? yes | no