How to calculate timing for precise 1Hz control action?
Jedi
Posts: 5
Very simple program so hopefully the solution will be as well. Seems there
is some simple math I'm missing.
What this program does is trigger a 500ms pulse at precise 1 minute intervals to
drive a relay that controls a vintage "minute impulse clock" I'm restoring.
Logic would say if I allow 500ms for the logic output pulse, and 59500ms for
the delay that it would add up to a perfect minute. But it doesn't - and I'm
certain it's just simply due to processor cycle time. Using that number the
output pulses lag every so slightly - 4 minutes in 24 hours. I arbitrarily
used 59000 and confirmed it then ran fast by about the same amount.
So what would be the CORRECT number? Or is it just a "guessing game
until you get it" sort of thing, due to variations from one stamp to another?
Or is there a formula that takes code length into account or other factors
to actually calculate the right "real world" timing?
Code below - not that it's needed really but just in case.
Thanks for any help
Jedi
is some simple math I'm missing.
What this program does is trigger a 500ms pulse at precise 1 minute intervals to
drive a relay that controls a vintage "minute impulse clock" I'm restoring.
Logic would say if I allow 500ms for the logic output pulse, and 59500ms for
the delay that it would add up to a perfect minute. But it doesn't - and I'm
certain it's just simply due to processor cycle time. Using that number the
output pulses lag every so slightly - 4 minutes in 24 hours. I arbitrarily
used 59000 and confirmed it then ran fast by about the same amount.
So what would be the CORRECT number? Or is it just a "guessing game
until you get it" sort of thing, due to variations from one stamp to another?
Or is there a formula that takes code length into account or other factors
to actually calculate the right "real world" timing?
Code below - not that it's needed really but just in case.
Thanks for any help
Jedi
Comments
-Phil
Thanks for the prompt reply Phil! That's what I figured - it's going to be more "trial, error, correct"...
likely even after the project is done and hanging on the wall.
There of course will be more to the program - I need a "fast advance button" as well as a "hold time"
button (for "fall back" time correction) - perhaps both run by code as well. Add to that an LED display
for tens of seconds and a few jumbo LEDs flashing seconds - all just for the geeky cool of it.
Thanks for the post.
Oh, and Port Townsend is one of my favorite places anywhere - been going there on holidays for
as long as I can remember and did numerous Centrum camps back in the 1970s in Jr. High and HS
Jedi