Hacker News new | ask | show | jobs
by raverbashing 46 days ago
"Trivial" But then you realize you forgot to account for a 32 bit counter wrapping up. Or potential failures in the power supply or other capacitors
2 comments

That 10c microcontroller has 15 32 bit registers, allowing you to make up to a 480 bit counter. That ought to be enough until long after the heat death of the universe.

It also has 2k (16384 bits) of SRAM, allowing even larger counters.

It runs off 2.8V - 5.5V DC, so supplying power is pretty trivial. Doesn't need a crystal, though of course adding one will improve the timing accuracy.

somewhere else they were discussing how to use a 555 to time 55 years, and how for such a long period you'd need impractical resistance and capacitance values. easy workaround would be to set a more reasonable period, say, 1 sec, and use a counter to know when you hit 55 years. coincidentally, 55 years is 2 ** 30.7 seconds, so it'd just fit in a 32 bit register.

though i take you were thinking about counting clock cycles or something in which case surely your register would overflow

The size of a register is not the largest value you can conveniently count on a computer. You can use multiple registers.

Old computers often had a "carry flag" specifically to make this easier e.g.on Arm:

    add r0,r0,#1
    adc r1,r1,#0
But even on RISC-V, often criticised for not having a carry flag, it's not hard:

    addi  a0,a0,1
    sltiu t1,a0,1 # set to 1 if a0 wrapped back to 0
    add   a1,a1,t1