Close

Exact Delays

A project log for limited-code hacks/ideas

When you're running out of code-space... sometimes yah's gots to hack. Here are some ideas.

eric-hertzEric Hertz 11/25/2016 at 07:330 Comments

One way to create an exact delay is to use NOPs...

Say you're working with a processor/microcontroller which has an external memory bus used for both its RAM and its ROM... capable of addressing 64KB of external memory (16 address bits). E.G., maybe, the 8051.

Now, say your external RAM/ROM chips fit within only the first 32KB of address-space...

Now... say you've numerous cases where you need an *exact* delay of anywhere from 8 to 32768 instruction-cycles... (including intermediates, like 9, 35, or 32754).


----------

Now, let's say your processor's NOP is 0xff... And its "return" (from a call/jump) is 0x81...

So...

Tie some pull-up resistors to the data-bus... (creating a NOP whenever an address doesn't select the RAM/ROM).

Use some glue-logic to detect when address 0xffff is selected (a 16-input NAND gate?)

Tie that NAND gate's output to a 74244/245's /OE input (Output-Enable, active-low), and tie the '244's inputs to 0x81 (return).

-----

A tiny bit of precalculation would tell you *which* address to jump to, outside the RAM/ROM (in "pull-resistor-space"), to get your exact-delay...

Don't forget to keep in mind the number of instruction-cycles to calculate that jump-point and execute the jump (which is why I arbitrarily threw in '8' as a minimum) and the number of instruction-cycles it takes to return.

(inspired by: https://hackaday.io/contest/18215-the-1kb-challenge/discussion-70338)

Discussions