6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Oct 05, 2024 10:28 pm

All times are UTC




Post new topic Reply to topic  [ 68 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
PostPosted: Fri Apr 08, 2016 3:53 am 
Offline

Joined: Thu Mar 31, 2016 1:26 pm
Posts: 60
Location: Austin, Texas
Garth wrote the following here:
Quote:
While most 65-family I/O ICs have open-drain IRQ outputs, WDC's 65C22 VIA (Versatile Interface Adapter) does not. That means that to feed more than one WDC 65C22's IRQ output into the processor's IRQ input, you'll need an AND gate arrangement, so that if any one of the IRQ's goes low, the processor's IRQ input is taken low. The AND gate may make for more parts, but the faster resulting rise time takes care of the potential problem mentioned above, especially with their faster processor speeds of 10MHz and higher.

Do I only need to AND the /IRQ lines from the VIAs or should I AND all /IRQ lines? (I don't plan on anything more than 2MHz if it matters).

_________________
- Billy


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 08, 2016 4:06 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8521
Location: Southern California
What matters is that you not connect totem-pole outputs together such that one is trying to pull down while another one is trying to pull up. The W65C22S has totem-pole IRQ\ and NMI\ outputs for the purpose of making it so the so the output can get yanked back up more quickly when the interrupt condition is cleared, rather than floating up slowly by way of a pull-up resistor. The behavior of this design however requires the AND gate even if you're using a slow clock rate, so the IRQ\ outputs don't fight each other and cause heating, invalid output levels, and other problems. If you have some totem-pole IRQ\ outputs and some open-drain outputs, connect them as I show in this diagram in the interrupts primer.

Image

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 08, 2016 4:19 am 
Offline

Joined: Thu Mar 31, 2016 1:26 pm
Posts: 60
Location: Austin, Texas
Ok, thanks!

_________________
- Billy


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 08, 2016 4:28 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8411
Location: Midwestern USA
Another way to connect the /IRQ output of the W65C22S (the version with a totem-pole output) to the IRQB input of the 65C02 is through a small Schottky diode, with the anode attached to IRQB on the MPU. You can connect any number of W65C22Ses that way if each has its own diode. The IRQ outputs of open drain devices would continue to be directly connected to IRQB on the MPU, as would the pull-up resistor. This method would be most practical if there were more than three of the W65C22S in the circuit, as the number of required inputs on the AND gate would start to become unwieldy.

Assuming you use the AND gate method to drive IRQB, be sure to tie unused gate inputs to Vcc. If you forget to do this and leave one floating, it may pick up noise and generate spurious interrupts. Similarly, if you mistakenly connect one of the AND gate inputs to ground, IRQB will be continuously held low and the MPU will get stuck in an interrupt loop from which there will be no escape.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 08, 2016 5:49 am 
Offline

Joined: Thu Mar 31, 2016 1:26 pm
Posts: 60
Location: Austin, Texas
BDD,
Quote:
Another way to connect the /IRQ output of the W65C22S (the version with a totem-pole output) to the IRQB input of the 65C02 is through a small Schottky diode, with the anode attached to IRQB on the MPU. You can connect any number of W65C22Ses that way if each has its own diode. The IRQ outputs of open drain devices would continue to be directly connected to IRQB on the MPU, as would the pull-up resistor. This method would be most practical if there were more than three of the W65C22S in the circuit, as the number of required inputs on the AND gate would start to become unwieldy.

Is this diagram correct? (Please excuse the drawing, I am on my Chromebook)
Attachment:
Screenshot 2016-04-08 at 12.39.04 AM.png
Screenshot 2016-04-08 at 12.39.04 AM.png [ 16.37 KiB | Viewed 3849 times ]

I think I will use this as opposed to the 74HC08 as it takes up less space (and the symbol for the Schottky diode looks cool :D).

_________________
- Billy


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 08, 2016 6:51 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8521
Location: Southern California
That'll work.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 10, 2016 4:04 am 
Offline

Joined: Thu Mar 31, 2016 1:26 pm
Posts: 60
Location: Austin, Texas
I am finishing up on my preliminary design but I wanted to ask a few more questions regarding interrupts.
    1. What exactly does the /VP or VPB pin do? Can I use it to tell where an interrupt came from (if I only have 2 chips)?
    2. If I am planning on using my VIA(s) for GPIO does it make sense to even connect their /IRQ pins?
    3. In my current design I don't have anything connected to /NMI, instead it is pulled through a 3.3K resistor to +5v. Is this okay?

Thanks to all of you for your valuable time! I should have a schematic done soon (which I'm sure I will have tons of fun debugging).

_________________
- Billy


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 10, 2016 4:23 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8521
Location: Southern California
billylegota wrote:
I am finishing up on my preliminary design but I wanted to ask a few more questions regarding interrupts.
    1. What exactly does the /VP or VPB pin do? Can I use it to tell where an interrupt came from (if I only have 2 chips)?
    2. If I am planning on using my VIA(s) for GPIO does it make sense to even connect their /IRQ pins?
    3. In my current design I don't have anything connected to /NMI, instead it is pulled through a 3.3K resistor to +5v. Is this okay?

#1: I have never used it, so I can't really comment beyond what's in the data sheet. I'll leave that to BDD or someone else.
#2: Absolutely. You'll want it for the timers too, not just I/O. Leaving the IRQ\ connections out will cramp your possibilities later.
#3: Yes; but why not have pin headers with removable shorting bars to select whether to have a given IC's interrupt output to go to IRQ\ or NMI\.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 10, 2016 4:59 am 
Offline

Joined: Thu Mar 31, 2016 1:26 pm
Posts: 60
Location: Austin, Texas
GARTHWILSON wrote:
#1: I have never used it, so I can't really comment beyond what's in the data sheet. I'll leave that to BDD or someone else.
#2: Absolutely. You'll want it for the timers too, not just I/O. Leaving the IRQ\ connections out will cramp your possibilities later.
#3: Yes; but why not have pin headers with removable shorting bars to select whether to have a given IC's interrupt output to go to IRQ\ or NMI\.

I'll connect the /IRQ pin of each interface IC to a header to select between /IRQ and /NMI on the processor (if I am correct, the Schottky diode for the VIA will need to go before the header to allow for multiple devices to be connected to /NMI without burning out the VIA).

_________________
- Billy


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 10, 2016 5:08 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
billylegota wrote:
1. What exactly does the /VP or VPB pin do? Can I use it to tell where an interrupt came from (if I only have 2 chips)?
It can safely be left unconnected, which is what almost everybody does. The usual way to tell where an interrupt came from is to begin the Interrupt Service Routine with a handful of instructions that interrogate the status registers of whatever peripheral chips might've caused the interrupt. The code then branches accordingly. /VP is for an optional hardware enhancement that makes the branch happen automatically, without any extra code.

Quote:
the Schottky diode for the VIA will need to go before the header
That's right. Have fun! :)

-- Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 10, 2016 5:36 am 
Offline

Joined: Thu Mar 31, 2016 1:26 pm
Posts: 60
Location: Austin, Texas
Quote:
It can safely be left unconnected, which is what almost everybody does. The usual way to tell where an interrupt came from is to begin the Interrupt Service Routine with a handful of instructions that interrogate the status registers of whatever peripheral chips might've caused the interrupt. The code then branches accordingly. /VP is for an optional hardware enhancement that makes the branch happen automatically, without any extra code.
I assumed that I could use it to easily tell if the interrupt came from a specific chip and was hoping that I could use it to branch my interrupt code as soon as possible based on if the interrupt came from the serial bus (ACIA) or not. Too bad the datasheet doesn't really have any information other than:
Quote:
The Vector Pull (VPB) output indicates that a vector location is being addressed during an interrupt sequence. VPB is low during the last interrupt sequence cycles, during which time the processor reads the interrupt vector. The VPB signal may be used to select and prioritize interrupts from several sources by modifying the vector addresses.
Which doesn't really glean any useful information. So it looks like I'll just leave it as NC.

_________________
- Billy


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 10, 2016 6:01 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8521
Location: Southern California
I think the data sheet gives the needed info, but relies on your resourceful design thought process for how to implement it. The various interrupt sources could go to a CPLD which would have the logic to respond to the vector addresses (it would have to look at all 16 bits) and put the right ISR address on the data bus. Most I/O ICs still have several possible interrupt sources though, so in many cases, even if you know which IC caused the interrupt, you will still have to examamine its status register to see which source caused that IC to generate the interrupt, if indeed you had more than one enabled.

Quote:
The usual way to tell where an interrupt came from is to begin the Interrupt Service Routine with a handful of instructions that interrogate the status registers of whatever peripheral chips might've caused the interrupt.

Jeff is of course right; but I'll go on. I put this in the 6502 interrupts primer, but I'll repeat it here. I have seen many ISR examples in the books that are much, much longer than necessary, polling every single possible interrupt source ever, even though in most cases you won't have more than a couple of them enabled. There is no sense in wasting time polling for interrupt sources you have not enabled. If you have four ICs that could generate interrupts, and only two sources enabled, there will be at least two ICs your ISR doesn't need to poll, and maybe three. Of the one or two left, poll only the status bits corresponding to the interrupts you have enabled.

Also, with the exception of that first 6502 class I took in 1982, I have never used BRK; so there's no sense in wasting my processor time examining the B bit. (This is discussed in the interrupts primer too.)

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 10, 2016 8:23 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10949
Location: England
If you have one high priority device that you really care about servicing quickly, that's what NMI is for. Acorn's Beeb uses NMI for the (optional) floppy disk controller - there are very few ticks available to service incoming bytes from floppy.

For serial, even at 115200 baud you have 86 ticks to deal with each byte (or more if you're running faster than 1MHz) so IRQ is probably good enough. The usual approach is for the interrupt service routine to check the most urgent chip first - for example, check the serial chip before the timer chip, if you think you might otherwise miss bytes. Or, if you're running a high speed timer for some critical reason, check the timer chip first.


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 10, 2016 9:23 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8411
Location: Midwestern USA
billylegota wrote:
Quote:
The Vector Pull (VPB) output indicates that a vector location is being addressed during an interrupt sequence. VPB is low during the last interrupt sequence cycles, during which time the processor reads the interrupt vector. The VPB signal may be used to select and prioritize interrupts from several sources by modifying the vector addresses.
Which doesn't really glean any useful information. So it looks like I'll just leave it as NC.

VPB is one of those signals that a first-time builder should not be considering. As Jeff suggested, ignore it for now. That said, I'll explain how it could be used.

When a hardware interrupt occurs or a BRK instruction is executed, the MPU executes a series of steps to save its state on the stack and then jumps to the interrupt service handler (ISR) code. The jump occurs by loading the program counter from a location in memory that points to the ISR that is expected to process the interrupt. As there are several interrupt types, there are several addresses involved, which are collectively referred to as the interrupt vectors. On the 65C02 or the 65C816 when operating in 65C02 emulation mode, the vectors are as follows:

Code:
$FFFA/$FFFB  non-maskable interrupt (NMI)
$FFFC/$FFFD  hardware reset
$FFFE/$FFFF  interrupt request (IRQ)

The addresses stored at these vectors are often burned into ROM, but in a unit whose operating system runs from RAM, the vectors will likewise be in RAM and could be changed. However, it gets even more interesting.

A system could be designed to prioritize IRQs, which means it would have hardware logic that can identify each interrupting device and assign it an ordinal number (interrupt number). A pecking order can be established based upon the interrupt number, making some interrupts more important than others. Nowadays, this function would be part of the glue logic in a CPLD or FPGA, but in the past was done with discrete devices. In either case, the glue logic, upon detecting an IRQ and determining which device caused it, could trick the MPU into jumping directly to the ISR for the interrupting device, eliminating the need to check all devices to see which one is interrupting. The result would be improved interrupt processing performance.

The trickery comes in two parts:

  1. The glue logic does nothing until the MPU asserts the VPB output, that is, pulls it low. When VPB goes low it means the MPU is fetching from the interrupt vector. It does this by performing consecutive reads from the least significant byte (LSB) at the vector address (at $FFFE in the case of an IRQ) and then the most significant byte (MSB) at the vector address (at $FFFF in the case of an IRQ). The address bytes are internally loaded by the MPU into the program counter (PC).

  2. The glue logic, in response to VPB going low, prevents ROM or RAM from actually driving the data bus and instead, takes control and places an alternate ISR address on it, first the LSB and then the MSB. That address is determined by the glue logic analyzing the interrupt number that it generated when a device interrupted. The MPU is none the wiser that the glue logic is talking to it and loads the alternate address into PC instead of the address at $FFFE/$FFFF. Hence execution is directed to the ISR associated with the interrupting device.

The logic to do all this is not particularly simple to implement, which is why it is something best left for a future project.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Sun Apr 10, 2016 3:54 pm 
Offline

Joined: Thu Mar 31, 2016 1:26 pm
Posts: 60
Location: Austin, Texas
GARTHWILSON wrote:
I think the data sheet gives the needed info, but relies on your resourceful design thought process for how to implement it. The various interrupt sources could go to a CPLD which would have the logic to respond to the vector addresses (it would have to look at all 16 bits) and put the right ISR address on the data bus. Most I/O ICs still have several possible interrupt sources though, so in many cases, even if you know which IC caused the interrupt, you will still have to examamine its status register to see which source caused that IC to generate the interrupt, if indeed you had more than one enabled.

Quote:
The usual way to tell where an interrupt came from is to begin the Interrupt Service Routine with a handful of instructions that interrogate the status registers of whatever peripheral chips might've caused the interrupt.

Jeff is of course right; but I'll go on. I put this in the 6502 interrupts primer, but I'll repeat it here. I have seen many ISR examples in the books that are much, much longer than necessary, polling every single possible interrupt source ever, even though in most cases you won't have more than a couple of them enabled. There is no sense in wasting time polling for interrupt sources you have not enabled. If you have four ICs that could generate interrupts, and only two sources enabled, there will be at least two ICs your ISR doesn't need to poll, and maybe three. Of the one or two left, poll only the status bits corresponding to the interrupts you have enabled.

Also, with the exception of that first 6502 class I took in 1982, I have never used BRK; so there's no sense in wasting my processor time examining the B bit. (This is discussed in the interrupts primer too.)

Hopefully I can keep my ISR simple. I am tempted to load the ISR into RAM and prompt the user as to what interrupts should be enabled / disabled (to reduce the effective size of the ISR) but that may be more trouble than it's worth.

_________________
- Billy


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 68 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: