6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 11:16 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sat Sep 21, 2013 10:25 pm 
Offline

Joined: Mon Apr 16, 2007 6:04 am
Posts: 155
Location: Auckland, New Zealand
...but I don't know why!

Why it's working that is. I am working on my little Orwell computer. Just a very basic 6502 really. I am using an old TI99/4 matrix keyboard on it and am using the Oric circuit as Garth describes in his primer using a 4051 (http://wilsonminesco.com/6502primer/potpourri.html#KBD).

I have my keyboard scanning routine working. Basically the 4051 is hooked to a 6522. The keyboard is conveniently 7 rows by 8 columns. I scan the rows by counting out on one port then I look the columns by reading the other port as one byte. The inputs are pulled up and a key press brings them low. Since shift, control and function keys, are part of the matrix I handle them separately then use them to modify the index into a look up table I have to match the key pressed. Apart from those three keys (well four since there is a separate alpha lock key) I only treat single key presses as being valid.

Currently I poll in a loop but will use a timer on the VIA to do a periodic scan. I just return the character in one byte and have another byte to indicate if there is valid data in it (I also return the status of the shift, control, function and alpha in it).

Now this is all working great. I don't support repeating yet but will do that outside my keyboard routine. I do handle non repeating though. It's all working rather well and that's what is confusing me! All my code does for now is scan the keyboard and send the key to my serial port driving my video output. Type a key and it echos to the screen. The little display thing I use (http://www.batsocks.co.uk/products/Other/TellyMate.htm) works like a terminal so TAB, ESC, LF, BS and so on all works. I actually have it displaying on a 1960s Sony 5 inch micro television via an RF modulator!

I haven't put in any debouncing yet but everything is all working. I was expecting some glitches by so far nothing. I can't figure out why I don't need it. I am guessing it's because everything is so slow I am processing well after the debouncing has stopped. Or perhaps these keyboard keys just don't bounce a lot (it's a nice positive keyboard). A full pass through the scan routine take 520 uS when a key is pressed (running a 1 Mhz clock).

Is there something inherent in that Oric circuit I am not seeing? Debounce should be easy enough to put in of course.

Image

Simon

_________________
My 6502 related blog: http://www.asciimation.co.nz/bb/category/6502-computer


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 21, 2013 10:35 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
How many times a second does any given key get looked at? How quickly do your passive pull-ups pull a line up? It is apparently slow enough and the keyboard good enough that it just works. But like you say, if it's just luck that it all worked out, and you don't know why, you can't depend on it continuing to work right.

That sure is an old TV, if it has a channel 1! I don't know what year that was removed and given to the amateur radio 6-meter band.

_________________
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 Sep 22, 2013 1:41 am 
Offline
User avatar

Joined: Sat Sep 29, 2012 10:15 pm
Posts: 904
Hah! It has channel 0 as well!

_________________
In theory, there is no difference between theory and practice. In practice, there is. ...Jan van de Snepscheut


Top
 Profile  
Reply with quote  
PostPosted: Sun Sep 22, 2013 1:44 am 
Offline

Joined: Sat Oct 20, 2012 8:41 pm
Posts: 87
Location: San Diego
But looks like no channel 13?


Top
 Profile  
Reply with quote  
PostPosted: Sun Sep 22, 2013 2:36 am 
Offline

Joined: Mon Apr 16, 2007 6:04 am
Posts: 155
Location: Auckland, New Zealand
Well this would be a European version of the TV so it's PAL and I believe the channels are different too than US ones? I think this particular tellie is from 1962! The sound unfortunately isn't working but I should be able to open it up and have a look and hopefully fix it. Here in NZ they are slowly turning off analogue TV transmissions. I think Auckland, where I am, is one of the last places in the country where it will be turned off which will be on December 1st.

The pull ups seem to take 1uS. I am confusing myself trying to measure things I think. I can see the key bouncing on the scope. But the bouncing is a lot less than the time a key is being read as low which varies from 144uS to 430uS depending on the key based on row and column. Any bouncing I see on the scope seems to last about 50uS.

I think the reason it is working is I am effectively de-bouncing it in my main code. The valid data flag is only set while a key is actually pressed. In my main loop I only print a key if it is different to the last key I printed. When I print out the key I store it in a previous_key variable I use to do that comparison. When there is no data I clear that previous key value.

So I think what is happening is my scanning is so much slower than the bouncing I never catch it happening?

Simon

_________________
My 6502 related blog: http://www.asciimation.co.nz/bb/category/6502-computer


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 26, 2013 7:20 pm 
Offline

Joined: Mon Apr 16, 2007 6:04 am
Posts: 155
Location: Auckland, New Zealand
Just a quick follow up. Debouncing is all working now. I re-jigged my code and split it into two parts, one to scan the matrix and return which key was being pressed and another to then work out what to do with that information and handle the debouncing, non repeating and so on. I now have about 40mS or so debounce time which is more than enough and it correctly handles key down/key up to prevent runaway key presses. With a couple more simple counters I could implement delayed auto repeat as a feature too although I haven't for now. I detect the alpha lock key but don't use it for anything yet so need to add that in too. That will only affect the A-Z keys of course. Shift, control and function all work.

I really need to fix the sound on the little tellie and rig up an output to do simple bleeps and bloops next!

Simon

_________________
My 6502 related blog: http://www.asciimation.co.nz/bb/category/6502-computer


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 50 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: