Tricky Timing Issue - Polling vs ISR/Interrupt

I'm using an attiny85 to provide a millisecond interrupt clock for a Z80 micro. The clock pulse drives the Z80's /INT pulse triggering a service routine which issues an output instruction to clear the interrupt. The Z80 takes about 30 uS to respond to the interrupt and the pulse it issues is about .5 uS. I need to de-assert the clock pulse inside of 1 uS or so. (A hard day with the timer | olduino)

The logic I'm using in the attiny looks like the following. khz, nkhz, and ntclr are all pins on portB.

	while(1){		//loop
		PORTB=((1<<nkhz);//assert the clock
		while(PINB & (1<<ntclr)); //wait for z80 to clear it **risk getting stuck here**
		PORTB=(1<<khz);//de-assert the clock
		_delay_us(1000);	// 1khz cycle
	}

My main worry is that if i missed the z80's pulse in the third line I would never recover. there's also the loose timing but that's not important.

One alternative would be to use a millisecond timer interrupt to start the pulse and a pin change or external interrupt interrupt to clear it. alternatively I could put a timeout counter on the spin if it didn't risk my missing the pulse.

Oh, I could also just brute force make my pulse short - like 20-25 uS. The Z80 might miss interrupts once in a while but that doesn't matter very much. That actually sounds like a plan.

Thoughts?

Bill Rowe
Olduino - An Arduino For the First of Us

My main worry is that if i missed the z80's pulse in the third line I would never recover.

How could you possibly miss it? The code is doing nothing but staring at the pin, waiting for it to go high.

I do not understand why you want the generating device to be controlled by the slave.

If there is no way to switch the Z80 IRQ to edge detection, a single flip-flop
(set by the generator, reset by the Z80) would work faster and take the polling burden off the Arduino.

PaulS:
How could you possibly miss it? The code is doing nothing but staring at the pin, waiting for it to go high.

The z80's pulse is only .5 uS at 4mhz. If I push up the z80's speed to 8 or 10mhz it gets shorter. Also, sh*t happens, noise, whatever and there's no escaping that loop.

Whandall:
I do not understand why you want the generating device to be controlled by the slave.

If there is no way to switch the Z80 IRQ to edge detection, a single flip-flop
(set by the generator, reset by the Z80) would work faster and take the polling burden off the Arduino.

http://www.allaboutcircuits.com/textbook/digital/chpt-10/edge-triggered-latches-flip-flops/

Yes, I was trying to avoid the extra part. Thanks for the link though, good reference.