6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 14, 2024 6:37 am

All times are UTC




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sun Oct 27, 2024 4:41 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
I've only used the VIA for messing around with the two ports. I've never used the actual shift register functionality of it.

From what I understand, the SR can be controlled with CB1 and CB2.

Quote:
2.11 Shift Register Operation

The Shift Register (SR) performs bidirectional serial data transfers on line CB2. These transfers are
controlled by an internal modulo-8 counter. Shift pulses can be applied to the CB1 line from an external
source, or (with proper mode selection) shift pulses may be generated internally which will appear on the
CB1 line for controlling external devices. Each SR operating mode is controlled by control bits within the
ACR.


The PS/2 has a CLK signal and a data out.
Is it as simple as shifting the data into CB2 and putting the PS/2 clock on CB1?

If so, I wouldn't have to use any of the port pins of the VIA. Or, am I missing something?

I actually got a VIA to work a PS/2 keyboard with my last SBC but I just used one of the ports and I don't remember how I did it. lol

Thanks again.

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 31, 2024 9:03 pm 
Offline

Joined: Sun Feb 22, 2004 9:01 pm
Posts: 104
It's fairly strightfoward to use a couple of data lines to read from a PS/2 keyboard, for instance link.

I was sure I had a link to code using the shift register, but can't find it, but it's possible. Interfacing is just this (slightly re-arranged as: this). The main fiddly bit with the code is that you're reading a 10-bit word into an 8-bit shift register. :?

_________________
--
JGH - http://mdfs.net


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2024 2:05 am 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
Thanks for the information. After some research, I decided to go with an ATMega328P in my design. It will double-duty as a power on reset, debouncing some buttons, resetting chips, and handling the PS/2. :-)

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2024 10:13 am 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1485
Location: Scotland
cbmeeks wrote:
Thanks for the information. After some research, I decided to go with an ATMega328P in my design. It will double-duty as a power on reset, debouncing some buttons, resetting chips, and handling the PS/2. :-)


Interested to know how you'll be interfacing the AVR to the 6502 bus (To get the keycodes). The Arduino PS/2 keyboard library is quite good though and can handle many different keyboard layouts.

Cheers,

-Gordon

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2024 12:11 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
From a VIA.
I plan on putting a shift register between the VIA and the ATMega which uses four pins of Port A. Then the other four pins will control the LCD registers, etc.

As for the PS/2, just straight 8 pins from the ATMega.

Attached is the unfinished schematic so far.


Attachments:
Screenshot from 2024-11-01 08-10-18.png
Screenshot from 2024-11-01 08-10-18.png [ 128.39 KiB | Viewed 102 times ]

_________________
Cat; the other white meat.
Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2024 1:59 pm 
Offline

Joined: Mon Jan 19, 2004 12:49 pm
Posts: 964
Location: Potsdam, DE
Seven bits of keyboard data and one 'ready' flag?


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2024 2:48 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
I'm not sure I know what you mean.

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2024 3:19 pm 
Offline

Joined: Mon Jan 19, 2004 12:49 pm
Posts: 964
Location: Potsdam, DE
Sorry, I was unclear: you have eight bits representing the state of the keyboard in some fashion, but no obvious way to say when a key is ready to be handled.

The classic way to handle that is to use one line to interrupt the processor, and for the processor to reset that interrupt bit. But I don't see anything to indicate that in (admittedly incomplete) drawing. So I wondered if you were using just seven bits of data - which would let you have all the ascii set, but give some difficulty with e.g. the cursor keys, F keys, and handling control and alt combinations - and somehow using the remaining bit to flag that a key is waiting.

Or perhaps you're going to let the 6502 handle the key combinations and just pass the real-time key values - though that requires all eight bits to collect the full set. So you still have to find some way to tell the processor that there's something to handle, with the added complication that only about a third of the key codes are equivalent to a key being pressed, so the processor might be a bit busy.

To be honest, I'd decode in the AVR, probably buffer the output, and encode the keys I care about into eight bits (this is what I am doing with my Pi Pico vga chip interface) and find some way to generate an interrupt (though you'll still need some way to clear that interrupt before the next keystroke).

I was just curious... I'm always ready to rip off someone else's better ideas, er, I mean, research alternative approaches :mrgreen:

For what it's worth, I tried a couple of fairly recent (= cmos) PS/2 keyboards and they're quite happy at 3v3, and don't take more than a few milliamps.

Neil


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2024 3:21 pm 
Offline

Joined: Mon Jan 19, 2004 12:49 pm
Posts: 964
Location: Potsdam, DE
p.s. it's handy if you include the programming connector for the AVR on the board too, if you have a wire-ended programmer.


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2024 3:34 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1485
Location: Scotland
cbmeeks wrote:
From a VIA.
I plan on putting a shift register between the VIA and the ATMega which uses four pins of Port A. Then the other four pins will control the LCD registers, etc.

As for the PS/2, just straight 8 pins from the ATMega.

Attached is the unfinished schematic so far.


OK. Great!

But hoes does the 6502 know when there is a character to read and how does the AVR know you're read it?

If I may suggest a change...

Move the speaker over to CA2 then the whole of port B is dedicated to the AVR interface.

Use the CB1 input as a strobe from an otherwise unused output on the AVR, so AVR decodes keypress (as an 8-bit ASCII, encode the keys like arrows, pgUp, etc. how you like) puts the 8-bit data on the output port, toggles CB1...

The 6502 gets an interrupt, reads the data, sets CB2 - connected to another spare pin which means the AVR then knows it's been read, so can present the next keypress.

This is basic VIA port read handshaking I think... (Although I recall that both ports work slightly differently - I'd need to check the data sheet)

Prudence might also suggest a flyback diode over the speaker...

-Gordon

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2024 3:37 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
Oh, I see what you mean. Yeah, I completely missed that!

Hmm, I will have to think about that as I have already used up all my pins on that VIA. (not totally sure how CA(B)1/2 work).

And yeah, I was going to have the AVR decode the key strokes and send the bytes over so the 6502 only has to read the byte. Or, multiple bytes actually like the F0 (or whatever it is) that indicates the stream is done.

Any suggestions? Thing is, I have two VIA's and a UART and I wanted the option of choosing which one connects to the /IRQ. And I really don't want to poll the AVR.

Going to have to think about this...

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2024 3:44 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
drogon wrote:
cbmeeks wrote:
From a VIA.
I plan on putting a shift register between the VIA and the ATMega which uses four pins of Port A. Then the other four pins will control the LCD registers, etc.

As for the PS/2, just straight 8 pins from the ATMega.

Attached is the unfinished schematic so far.


OK. Great!

But hoes does the 6502 know when there is a character to read and how does the AVR know you're read it?

If I may suggest a change...

Move the speaker over to CA2 then the whole of port B is dedicated to the AVR interface.

Use the CB1 input as a strobe from an otherwise unused output on the AVR, so AVR decodes keypress (as an 8-bit ASCII, encode the keys like arrows, pgUp, etc. how you like) puts the 8-bit data on the output port, toggles CB1...

The 6502 gets an interrupt, reads the data, sets CB2 - connected to another spare pin which means the AVR then knows it's been read, so can present the next keypress.

This is basic VIA port read handshaking I think... (Although I recall that both ports work slightly differently - I'd need to check the data sheet)

Prudence might also suggest a flyback diode over the speaker...

-Gordon


Oh, I like those ideas too.

Thanks

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2024 3:49 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
Something like this?

I'm struggling with how the /IRQ is going to work with the three devices. I can eliminate one of the VIA's from the /IRQ and that would leave a UART and VIA (PS/2, LCD). It would be really nice if I could use the PS/2 and get serial interrupts together.

I was going to use the /NMI for a monitor button but maybe I do something different.


Attachments:
Screenshot from 2024-11-01 11-50-50.png
Screenshot from 2024-11-01 11-50-50.png [ 122.65 KiB | Viewed 90 times ]

_________________
Cat; the other white meat.
Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2024 7:35 pm 
Offline

Joined: Mon Jan 19, 2004 12:49 pm
Posts: 964
Location: Potsdam, DE
There's some C code in this thread viewtopic.php?f=2&t=8069 that should be easy to port to the AVR; it's mostly look-up tables. It generates normal 8-bit ascii, with high bits set for various alt and cursor control keys, and it's easy to add your own combinations for those I haven't used. (It's the code I'm using in my Pico, currently on hold while I sort out a Tiny Basic).

With that, you can let the AVR manage the keyboard (and queue it as necessary) and just generate one more IRQ... I'm forty years out of touch with the 6522 but I think it has a mode that will latch a data bus input with (e.g.) CB1 or CB2 and possibly trigger an interrupt at the same time, per Drogon's suggestion.

Neil


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 01, 2024 7:38 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
Thanks again.

I'm going to start a separate thread on the speaker. I'm not sure if that simple 9 bit DAC will work on Port A so I might have to swap the two ports.

_________________
Cat; the other white meat.


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 33 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: