6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 2:57 pm

All times are UTC




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Programming the 6522?
PostPosted: Tue Mar 02, 2021 7:45 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
I have the datasheet for the 6522 and I've seen examples here and there online.

But I was wondering if there was a book or even more detailed articles that go into more depth on the 6522? I'm a fan of these "recipe" books when it comes to design or programming and would love if something like that existed for the 6522.

Any suggestions?

Thanks!

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 02, 2021 8:00 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
It really depends on what you're trying to use the VIA for. The old 6502 Assembly Language Subroutines (Leventhal and Saville) has a section on the 6522 which may prove helpful.

Over the decades, I've used the 6522 for a centronics parallel port with handshaking (Vic-20 days) and more recently for basic parallel I/O and timer support for accurate delays and a RTC in software using a jiffy-counter.... all using interrupt-driven code. It's a fairly simple I/O chip to program.

I've not seen much usage of the serial port with the 6522 as it has an annoying feature (aka bug) that's been written up over the years. Worse, all the manufacturers of the 6522 and later CMOS versions opted to keep it that way. You can always view others' source code that uses the 6522... even the Vic-20 source is out there and that does quite a bit with it, including the RS-232 interface via (no pun intended) bit-banging on the parallel port.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 02, 2021 8:01 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8505
Location: Midwestern USA
cbmeeks wrote:
I have the datasheet for the 6522 and I've seen examples here and there online.

But I was wondering if there was a book or even more detailed articles that go into more depth on the 6522? I'm a fan of these "recipe" books when it comes to design or programming and would love if something like that existed for the 6522.

Any suggestions?

Garth has some discussion about programming the VIA on his website. However, and as I'm sure you know, you have to have defined a problem before you can formulate a solution. What do you want the VIA to do for you?

BTW, if you have plans to interface the VIA to external devices other than those with CMOS inputs you might be better served by the W65C22S. Yes, the totem-pole IRQ output can be a bit of a pain, but the I/O pins can drive harder than those of the W65C22N, which may turn out to be a useful characteristic.

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


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 02, 2021 8:15 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8505
Location: Midwestern USA
floobydust wrote:
Over the decades, I've used the 6522 for...timer support for accurate delays and a RTC in software using a jiffy-counter...

At one time, I contemplated doing that but disliked the fact that merely changing the Ø2 clock rate would upset the timing apple cart. That indirectly led to me using the counter/timer in the DUART to generate jiffy IRQs.

Quote:
I've not seen much usage of the serial port with the 6522 as it has an annoying feature (aka bug) that's been written up over the years.

Garth described a workaround for it. Although I currently have no application in which the VIA would be useful, I may add one to a future POC V1 revision so I can set up a Mickey Mouse "network" using the serial shift register and connect two POC units together.

I did something like that with my two Commodore 128Ds back when I was writing code for that machine. The "network" was good for 32KB per second, which meant I could rapidly transfer a sizable program from one machine to the other. The only thing was the CIA's outputs didn't have much oomph, so cable length had to be relatively short to avoid problems. If we had had the 74AC-series bus transceivers back then a much longer cable would have been practical.

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


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 02, 2021 8:31 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
BigDumbDinosaur wrote:
Garth has some discussion about programming the VIA on his website. However, and as I'm sure you know, you have to have defined a problem before you can formulate a solution.


Yep, I've read Garth's stuff many times (and will be implementing some of it). :-)

BigDumbDinosaur wrote:
What do you want the VIA to do for you?

Well, a few different things that I didn't want to flood the board with tons of "how do I do this??" questions. :-)

One such example is that I'm looking for a way to do a simple tone generator like how the Apple II does it.

This is a good example of what I'm looking for:

viewtopic.php?t=342#p2307

I assume the "to hi-Z load" would be a speaker?

Also, I have a few books on interfacing hardware to the VIC-20, C64, etc. They are really good ideas on small projects to implement. So I can look there too. I was just wondering if there was a "6522 Bible" or something like that.

Again, mostly so that I don't have to keep pestering you guys.

BigDumbDinosaur wrote:
BTW, if you have plans to interface the VIA to external devices other than those with CMOS inputs you might be better served by the W65C22S. Yes, the totem-pole IRQ output can be a bit of a pain, but the I/O pins can drive harder than those of the W65C22N, which may turn out to be a useful characteristic.


Yeah, this is a good point and may mean changing the way I was doing my interrupt hardware. I'm more interested in interfacing with vintage chips. The SD card I'm using is just for convenience. I hope to interface to the 1541 drive, etc.

BigDumbDinosaur wrote:
Quote:
I've not seen much usage of the serial port with the 6522 as it has an annoying feature (aka bug) that's been written up over the years.

Garth described a workaround for it. Although I currently have no application in which the VIA would be useful, I may add one to a future POC V1 revision so I can set up a Mickey Mouse "network" using the serial shift register and connect two POC units together.


I've seen that work around. Basically delayed the clock a little IIRC.

BigDumbDinosaur wrote:
I did something like that with my two Commodore 128Ds back when I was writing code for that machine.


That C128-D is worth some money if you still have it. I bought one a few years ago and could literally sell it for almost twice what I paid. :-)

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 02, 2021 8:39 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
I wonder if there is a good cookbook for 6522 projects.

Here's a book:
Practical interfacing projects with the Commodore computers (1985, Robert Luetzow)


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 02, 2021 8:41 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
BigEd wrote:
I wonder if there is a good cookbook for 6522 projects.

Here's a book:
Practical interfacing projects with the Commodore computers (1985, Robert Luetzow)



That's exactly what I was trying to ask but sometimes I ramble on. lol

I have a "cookbook for VIC-20", etc. Would be cool if there was one devoted to the 6522. I'm thinking my best bet is to just find these interfacing books and reading through them.

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 02, 2021 11:34 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
cbmeeks wrote:
One such example is that I'm looking for a way to do a simple tone generator like how the Apple II does it.

This is a good example of what I'm looking for:

viewtopic.php?t=342#p2307

I assume the "to hi-Z load" would be a speaker?

No; a speaker is very low-impedance, not high-impedance. If you were to drive a speaker, the idea is that you'd follow the diagram there with an amplifier that has a high input impedance (like 100K), and the amplifier's output would supply the current needed for the speaker. A lower input impedance to the amplifier would reduce its input voltage (due to the voltage divider produced by that and the 8.2K resistor shown), which might be fine since the amplifier could amplify the voltage (not only supply the needed current); but then the capacitor should also increase if you want to keep the same corner frequency. If you want help with that, let me know what you plan to do, and I'll help you with the numbers.

The diagram shown was for using the shift register to get basically a PWM for what amounts to a 9-level D/A converter. If all you want is square-wave beeps with a single frequency at a time (which is all I remember Apple II's doing), you could get that from a VIA's PB7 output toggled by the timer with no microprocessor attention except to start and stop the tone. I've done that, too.

Quote:
I was just wondering if there was a "6522 Bible" or something like that.

I have the 1982 book "Advanced 6502 Interfacing" by John M. Holland, but I was disappointed that it has very little about the '22. I don't know anything as comprehensive for VIA applications as what's in the "Tip of the Day" topic you linked to, and 6502 primer, particularly the "Circuit potpourri" page and to a lesser extent the "I/O ICs" page, which also have links to working sample code for many of the circuits. There are undoubtedly plenty of things done with the '22 that I have not thought of, but I try to show there how it really does live up to its name, "Versatile Interface Adapter," and stimulate the reader's imagination as to what he could do with it. I keep updating it too.

Quote:
I've not seen much usage of the serial port with the 6522 as it has an annoying feature (aka bug) that's been written up over the years.

The SR has a bug in only one of its seven modes of operation. It will not affect most VIA users.

_________________
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: Wed Mar 03, 2021 3:05 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 704
Location: North Tejas
There is a section about the interval timers of the 6522 in this book:

http://www.atarimania.com/documents/Pro ... iments.pdf


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 03, 2021 2:21 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
GARTHWILSON wrote:
If all you want is square-wave beeps with a single frequency at a time (which is all I remember Apple II's doing), you could get that from a VIA's PB7 output toggled by the timer with no microprocessor attention except to start and stop the tone. I've done that, too.


What they managed to achieve out of that Apple II speaker is pretty amazing. I think the record was 5-bit audio, IIRC.

Anyway, yes! That's what I'm looking for. I actually have PB7 free and love the idea of using it to drive a speaker for simple tones. Is there a schematic for that? Or, should I go off the 9-value one we've been talking about?

GARTHWILSON wrote:
I have the 1982 book "Advanced 6502 Interfacing" by John M. Holland, but I was disappointed that it has very little about the '22. I don't know anything as comprehensive for VIA applications as what's in the "Tip of the Day" topic you linked to, and 6502 primer, particularly the "Circuit potpourri" page and to a lesser extent the "I/O ICs" page, ...


Yes, I was quite surprised at the lack of dedicated books to the 6522. And you're right...the "Tip of the Day" and "Circuit Potpourri" is great. It's where I've spent most of my time learning about the 6522. Seems there are tons of articles here and there that feature a 6522 but nothing actually devoted to it in print.

BillG wrote:
There is a section about the interval timers of the 6522 in this book:
http://www.atarimania.com/documents/Pro ... iments.pdf


Thanks for that! I have dozens and dozens of books in my collection but never saw that one.

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 03, 2021 6:08 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8505
Location: Midwestern USA
BigEd wrote:
I wonder if there is a good cookbook for 6522 projects.

Here's a book:
Practical interfacing projects with the Commodore computers (1985, Robert Luetzow)

Oh! I forgot all about that one. That's a good recommendation.

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


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 04, 2021 7:11 am 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1488
Location: Scotland
cbmeeks wrote:
GARTHWILSON wrote:
If all you want is square-wave beeps with a single frequency at a time (which is all I remember Apple II's doing), you could get that from a VIA's PB7 output toggled by the timer with no microprocessor attention except to start and stop the tone. I've done that, too.


What they managed to achieve out of that Apple II speaker is pretty amazing. I think the record was 5-bit audio, IIRC.

Anyway, yes! That's what I'm looking for. I actually have PB7 free and love the idea of using it to drive a speaker for simple tones. Is there a schematic for that? Or, should I go off the 9-value one we've been talking about


The Apple II audio essentially wired the output of an address decoder ($C03x IIRC) to a flip-flop then to a transistor to drive the speaker. that would be more efficient (ie. less cpu cycles) than a read/modify/write to flip the output of a VIA pin but use what you've got to get going.

I remember toggling the address (read or write - didn't matter!) and watching the speaker cone move in & out (simple things to keep me amused while pouring over the Apple II schematics!)

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 04, 2021 8:06 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
cbmeeks wrote:
GARTHWILSON wrote:
If all you want is square-wave beeps with a single frequency at a time (which is all I remember Apple II's doing), you could get that from a VIA's PB7 output toggled by the timer with no microprocessor attention except to start and stop the tone. I've done that, too.

What they managed to achieve out of that Apple II speaker is pretty amazing. I think the record was 5-bit audio, IIRC.

Anyway, yes! That's what I'm looking for. I actually have PB7 free and love the idea of using it to drive a speaker for simple tones. Is there a schematic for that? Or, should I go off the 9-value one we've been talking about?

If you want to feed the speaker directly from PB7, I would put the output signal through a 47uF capacitor (+ goes toward PB7), then through a 100Ω resistor, then to the speaker, and the other speaker terminal goes to ground. The approximately 17mA (for a W65C22S) load, sourcing 50% of the time and sinking the other 50%, IOW, 8½mA average for each transistor, won't hurt it, although I might not want to go much heavier full-time. It will be plenty audible but not loud. This all assumes an 8Ω speaker. If you have a 16Ω speaker, you'll get a little more volume. If you want more volume than that, I would definitely go with an amplifier rather than reducing the resistor value. I need to add a lot of general-purpose simple analog circuits to my website.

_________________
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: Thu Mar 04, 2021 4:50 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
GARTHWILSON wrote:
If you want to feed the speaker directly from PB7, I would put the output signal through a 47uF capacitor (+ goes toward PB7), then through a 100Ω resistor, then to the speaker, and the other speaker terminal goes to ground. The approximately 17mA (for a W65C22S) load, sourcing 50% of the time and sinking the other 50%, IOW, 8½mA average for each transistor, won't hurt it, although I might not want to go much heavier full-time.


Much heavier? Do you mean driving more than 50% duty cycle? What would happen if I accidentally set PB7 as output and drove it 100%? I know I won't hear audio but I don't want to damage anything.

GARTHWILSON wrote:
I need to add a lot of general-purpose simple analog circuits to my website.


Yes! This would be fantastic. I know very little about DC circuits and about 1000x less on analog. Would love to see some write ups with more analog stuff. :-)

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 04, 2021 7:42 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
cbmeeks wrote:
GARTHWILSON wrote:
If you want to feed the speaker directly from PB7, I would put the output signal through a 47uF capacitor (+ goes toward PB7), then through a 100Ω resistor, then to the speaker, and the other speaker terminal goes to ground. The approximately 17mA (for a W65C22S) load, sourcing 50% of the time and sinking the other 50%, IOW, 8½mA average for each transistor, won't hurt it, although I might not want to go much heavier full-time.

Much heavier? Do you mean driving more than 50% duty cycle? What would happen if I accidentally set PB7 as output and drove it 100%? I know I won't hear audio but I don't want to damage anything.

If you accidentally feed it DC, the capacitor will block it. No harm done. By 'heavier,' I meant reducing the resistor value so a signal produces more current flow and the pin-driver transistors in the VIA get hotter.

_________________
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  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 16 guests


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: