Z80 interrupt management [message #8788] |
Wed, 07 July 2021 04:07  |
lynchaj
Messages: 1080 Registered: June 2016
|
Senior Member |
|
|
Hi
Has any adapted an Intel 8259 PIC circuit to work with a Z80? It seems to me that adding a PIC would make interrupt management a lot easier. Implement per data sheet and I think it supports up to 256 unique interrupts or something like that if I recall correctly. I know the IBM PC implementation was not the best but maybe it's enough? Even handling 8 unique interrupts would probably be sufficient for most Z80 type systems. How many interrupts do we need? The current approach of daisy-chain interrupts on the backplane is less-than-great and I am not aware of anyone who has actually implemented it even though the original Z80 SBC ECB backplane supported it from day it was first released.
Like to hear others thoughts on this topic
Thanks, Andrew Lynch
[Updated on: Wed, 07 July 2021 04:08] Report message to a moderator
|
|
|
|
|
|
Re: Z80 interrupt management [message #8794 is a reply to message #8789] |
Wed, 07 July 2021 12:06   |
 |
Wayne W
Messages: 385 Registered: October 2015 Location: Fallbrook, California, US...
|
Senior Member |
|
|
etchedpixels wrote on Wed, 07 July 2021 05:30You can simply run the interrupts into a Z80 PIO. That gives you bit level masking and interrupt control as well as telling you what interrupts are present with a single IN. See "mode 3" and the interrupt control word - you can mask/unmask each line individually. If you have 8 lines used for that I think you've still got enough to add a bitbang SD card (even in QSPI mode) or a printer port as well ;-)
You can use a Z80 and 8259 together but you have to add a lot of glue or use the 8259 in poll mode (so you get an interrupt and then read the PIC to find out what is going on), as it can't cope with the Z80 interrupt pattern. There's a modern S100 card that does it here:
http://www.s100computers.com/My%20System%20Pages/PIC&RTC %20Board/My%20PIC%20Board.htm
One other thing I was looking at was your banking model. You are going to need to disable interrupts around your ROM/RAM switching so you don't get an IRQ mid switch when there is nothing mapped low.
Alan
Interesting. I want to check my understanding of this approach. The Z80 PIO would be the one and only driver of the /INT signal into the Z80, right? So, no IEI or IEO chain, right? Additionally, the Z80 PIO could invoke a Z80 mode 2 interrupt, right? The PIO interrupt handler would then use the PIO channel bits to determine what is causing the actual interrupt, right?
If I have understood correctly, this would work nicely. It does mean that there would need to be individual interrupt lines for the modules (fly wires or dedicated interrupt lines on the bus). But an 8259 would have the same requirement.
Thanks,
Wayne
|
|
|
|
Re: Z80 interrupt management [message #8796 is a reply to message #8795] |
Wed, 07 July 2021 18:48   |
Sergey
Messages: 236 Registered: October 2015 Location: Portland, OR
|
Senior Member |
|
|
Intel 8259 PIC, depending on the mode, needs three cycles to issue either a CALL instruction (8080) or two cycle to issue INT instruction (8086/88). Z80 CPU issues only one INTA cycle. So you can't simply interface one to another.
This page https://lkesteloot.github.io/alice/alice2/cpu_board.html has a description of a circuit that generates INTA instead of the usual RD, until either a write (likely to save PC on the stack) or a reset happen.
Also to implement 256 interrupts, you are going to need 9 PICs. But this is probably an overkill anyway. You could use 2 PICs in a cascade configuration as IBM AT does for 15 interrupts.
If you need only up to 4 interrupts, you can use Z80 CTC, as I've done in Zeta SBC V2. See "Programming CTC as an Interrupt Controller" here: http://www.malinov.com/Home/sergeys-projects/zeta-sbc-v2
[Updated on: Wed, 07 July 2021 18:54] Report message to a moderator
|
|
|
Re: Z80 interrupt management [message #8797 is a reply to message #8794] |
Wed, 07 July 2021 19:14   |
Sergey
Messages: 236 Registered: October 2015 Location: Portland, OR
|
Senior Member |
|
|
Wayne W wrote on Wed, 07 July 2021 12:06
Interesting. I want to check my understanding of this approach. The Z80 PIO would be the one and only driver of the /INT signal into the Z80, right? So, no IEI or IEO chain, right? Additionally, the Z80 PIO could invoke a Z80 mode 2 interrupt, right? The PIO interrupt handler would then use the PIO channel bits to determine what is causing the actual interrupt, right?
In this case (interrupt mode 2) you can chain multiple Z80 peripherals together using IEI/IEO. All of the peripheral chips will be wire-ORed to /INT signal. /INT pins are open drain/open collector, so all that's needed is a pull up resistor, which is likely already present on CPU's /INT pin.
PIO has only one interrupt vector, and as you stated, the interrupt handler will need to read PIO ports to figure out the source.
This approach of using PIO has several drawbacks:
1. Additional operations required to figure out the interrupt source, and jump to the interrupt service routine accordingly. This adds interrupt latency and increases software complexity
2. No priority handling between different interrupts by PIO. The prioritization theoretically can be done in software, but again, increases the complexity
3. PIO doesn't latch the inputs. If an interrupt pulse had occurred, but the input went back to inactive state before Z80 CPU was able to read PIO port, it wouldn't be possible to determine the source
As I've described in my previous reply, if 4 or less interrupts are needed, Z80 CTC can be used as simple interrupt mode 2 controller. It wouldn't have any of these drawbacks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Z80 interrupt management [message #9122 is a reply to message #8807] |
Mon, 13 September 2021 15:22   |
 |
Wayne W
Messages: 385 Registered: October 2015 Location: Fallbrook, California, US...
|
Senior Member |
|
|
Hi Folks,
Andrew has implemented Bill's IM2 circuit below in his latest version of the MBC CPU board. I am now trying to get it to work and I seem to be stumped. The /INT signal is firing just fine (I can run the whole thing in IM1 with no trouble). However, under IM2, my system seems to jump to an unexpected location. The code handles the first 16 IM2 vectors and is known to work well on several other platforms.
I have attached a logic analyzer snapshot below. S0-S2 correspond to A0-A2 in the schematic (inputs to '373). D1-D3 are the outputs of the '373. During /INTA, D1-D3 do not seem to follow S0-S2 as I would expect. Hard to tell with a logic analyzer, but I suspect the outputs are floating and causing the vector read by the CPU to be something totally unexpected.
Anyone have any ideas on this?
Thanks!
Wayne

wsm wrote on Thu, 08 July 2021 09:34I think the simplest solution is to just have a hardware IM2 vector generator and there's no need for any software except for the vector table and interrupt handlers. There's also no need for IEI / IEO chains and their associated delays.

The '148 generates the INT* signal and during the response the M1* sugnal latches the highest priority interrupt since it occurs before IORQ*. The actual vector is placed on the data bus during the interrupt acknowledge read.
INT7* is the highest priority and if there is any chance of spurious interrupt signals then the INT0* handler needs to verify it's processing a real interrupt. Just to be safe, even if various INT inputs are not used, their vector should probably point to an EI / RETI sequence.
-
Attachment: Capture.PNG
(Size: 37.90KB, Downloaded 1735 times)
|
|
|
|
|
|
|
|
Re: Z80 interrupt management [message #9128 is a reply to message #9127] |
Wed, 15 September 2021 08:35   |
lynchaj
Messages: 1080 Registered: June 2016
|
Senior Member |
|
|
Hi
Based on our testing of the IM2 circuit on the updated Z80 processor V2 board, I'm making some improvements to the design to better accommodate interrupts. Please see the attached schematic. There are two main changes; first, an update to the data bus transceiver (74ls245) to change direction based on either RD# or INTA# to bring backplane data bus info into the CPU. Second, a further qualification to the 74ls373 output enable to only respond to INTA# and INT-IM2# (IM2 interrupts from the 74ls148).
The purpose of these changes is to place all the IM2 vectors (or IM0 op codes) on the backplane data bus and so the bus transceiver gate to allow those into the CPU. Also eliminate bus contention from the 74ls373 by limiting it's output to only respond to interrupts it receives through the external connector and 74ls148.
One thing I am concerned about is to prevent the IM2 circuit from interfering with DMA cycles. I added a pull up resistor to IORQ# to keep it high during it's tristate phase while DMA is active. M1# does not tristate so it *should* be either high or low at all times and high during DMA cycles. Regardless, INTA# should not be active during DMA cycles but if you detect any interference with the interrupt during DMA please let me know.
Comments, questions, all appreciated. Thanks, Andrew Lynch
PS, one thing I really like about the IM2 circuit is it gives non-Zilog peripherals like the 16C550 UART to use IM2 mode. That's really handy because you can have multiple devices using interrupts without the post-interrupt polling you'd need if using multiple devices in IM1 mode. A much simpler and quicker interrupt response since when it arrives you know what sent it immediately.
[Updated on: Wed, 15 September 2021 08:39] Report message to a moderator
|
|
|
Re: Z80 interrupt management [message #9129 is a reply to message #9128] |
Thu, 16 September 2021 11:56  |
lynchaj
Messages: 1080 Registered: June 2016
|
Senior Member |
|
|
Hi, regarding the above schematic, the plan is to support IM1 and IM2 for certain but is there anything else needed to support IM0? IM0 = Interrupt along with instruction op code pushed onto the data bus. Since the Z80 processor V3 won't support IM0 intrinsically although in theory a board on the backplane bus could use IM0 and I would like this board to also keep that possibility open. Thanks, Andrew Lynch
|
|
|