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