PS/2 -> PCjr keyboard conversion

Hardware questions and modifications

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Tue Apr 07, 2015 9:36 am

Unfortunately, I think I need to start over with the C version of the program, because it's just not doing what I thought I had programmed it to do. I actually have to program it to look for the wrong number of interrupts to get a consistent read off the PS/2 keyboard, and the first read after power up is always wrong (it's right if I look for the correct number of interrupts, but then every subsequent read is wrong for some reason). Not really sure what I'm messing up as I wrote almost all the code before testing any of it, so I think I need to go back and implement one thing at a time to make sure each thing works before I move on to the next.

EDIT (4/7): I'm not sure what change did it, but after a lot of trial and error I got my new PS/2 read routine reading properly the first time and every time, as well as buffering properly (I verified buffering by intentionally inserting a half second delay in the code that output what it was reading in, then I pressed the PAUSE key, which has the longest scancode; the whole scancode was output by the microcontroller with half second delays between each byte and no errors).
jmetal88
 
Posts: 793
Joined: Sun Jul 25, 2010 10:22 am

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Tue Apr 07, 2015 7:40 pm

Okay, now I'm back up to where I was in my original assembly code. That is, I'm reading in and translating codes to XT codes, putting them out on the UART, and correctly toggling the LEDs. Next I'll have to add the 220uS timer interrupt back in and hope it doesn't mess anything up.
jmetal88
 
Posts: 793
Joined: Sun Jul 25, 2010 10:22 am

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Tue Apr 07, 2015 8:39 pm

Well, the timer interrupts were causing crashes while I was trying to write LED states back to the keyboard, so I got rid of them. Instead, I'm timing the output using MPLab's delay macros and hoping the timing is close enough to not cause any hiccups on the PCjr. If it works, I think the code is complete at this point. I just need to fabricate a keyboard cable for my PCjr so I can hook the board up and test it.

EDIT: Alright, I'm not doing something quite right on the PCjr side. It's receiving scan codes, but it's beeping at me after each one, which I'm guessing means the parity check failed.

EDIT 2: It's pretty clear I'm not duplicating the output of a real keyboard correctly. I'm trying to output what's described in the tech ref, but maybe I'm misunderstanding the section or maybe what they wrote isn't accurate. I think I need to take my PCjr keyboard and this microcontroller board up to my school soon and record the outputs on the digital oscilloscopes up there so I can actually look at the whole scan code at once and see what I'm doing wrong.
jmetal88
 
Posts: 793
Joined: Sun Jul 25, 2010 10:22 am

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Wed Apr 08, 2015 11:07 am

I managed to get a snapshot of the waveform of the keyboard output earlier today. It exactly matches the drawing in the tech ref, so I know that's right at least. Next up, figure out what's wrong in my code that's causing the output to be invalid.
jmetal88
 
Posts: 793
Joined: Sun Jul 25, 2010 10:22 am

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Wed Apr 08, 2015 2:03 pm

Hoping I just figured out the source of my problem. I hooked the board up to my oscilloscope at home and finally got the triggering set right so that I could view the scan codes repeating while holding down a key, and it appears that the complement function does NOTHING in the XC8 compiler. Which means I have to replace all my bit inversions with XOR 1 operations.
jmetal88
 
Posts: 793
Joined: Sun Jul 25, 2010 10:22 am

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Wed Apr 08, 2015 2:35 pm

Alright! It's working now with just a few bugs.

1: The keyboard transmits some kind of 'ready' byte when it powers on that the PCjr doesn't know how to handle, so you have to CTRL-ALT-DELETE once to get it to finish booting.

2: Changing LED states, which uses interrupts, is messing with the timing going out to the PCjr, so the PCjr has no idea what to do with the signals it's getting for CAPS LOCK, SCROLL LOCK, and NUM LOCK. Evidently I need to write kind of a lock-out for data transfer back to the PS/2 keyboard so that writing data out to the PCjr is only happening while that's NOT happening.
jmetal88
 
Posts: 793
Joined: Sun Jul 25, 2010 10:22 am

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Wed Apr 08, 2015 3:20 pm

It's better now. Added code to just not transmit the first thing after power up and that fixed the first bit. The second bit was fixed by simply moving the output code up before the LED change code.

Additional problems I've noted:

1. Shift+* seems to permanently lock the computer. I would just advise not to do it.
2. The PAUSE button doesn't work. This makes sense as it would interrupt the transmit code for the first scan code to take the second scan code in to the buffer, which destroys the timing. By the same token, PRINT SCREEN also does not work. This is the reason I was originally using timer interrupts to generate the PCjr code instead of hard coding delay cycles, but that ended up messing with the timing of the PS/2 keyboard communication and the scan codes would start getting shifted over a bit or two. PS/2 keyboards are supposed to buffer their own bytes when communication is inhibited, though, so maybe I need to add communication inhibition to the PCjr output routine.

EDIT: Nope, trying to inhibit communication from the PS/2 keyboard during writes to the PCjr creates a whole bunch of other problems, effectively resulting in the keyboard not functioning at all. So I need to find another approach. Hmm.

EDIT 2: Ah! Just realized Shift+* is the key combo for PRINT SCREEN. So apparently PRINT SCREEN locks up my PCjr. I don't know if that's just because I don't have a printer attached or what.
Last edited by jmetal88 on Wed Apr 08, 2015 8:38 pm, edited 1 time in total.
jmetal88
 
Posts: 793
Joined: Sun Jul 25, 2010 10:22 am

Re: PS/2 -> PCjr keyboard conversion

Postby jmetal88 » Wed Apr 08, 2015 5:18 pm

Alright, I don't think I can figure out how to get PAUSE and PRINT SCREEN working without programming in special case scenarios for each one (and that would require a significant re-write of code that already works otherwise, which I'm not up to right now). I just tried my last resort effort to fix the timing, which was to use the PIC's timer through polling instead of using delay macros, but the PS/2 keyboard read interrupts still do too much damage between instructions for PAUSE and PRINT SCREEN to be sent correctly. So instead, I'm just going to re-map a key (F12, probably) to Fn, and you'll have to use the PCjr-style shortcuts for keys like PAUSE, PRINT SCREEN, and BREAK. After I get that done, I'll try to clean up my code a little, then I'll post the MPLAB project folder and circuit schematic here so that if anyone else wants to take a crack at fixing things, they can. Also a possibility: Porting the code to a smaller, cheaper PIC chip. I'm using a PIC16F88 (only because I already had it through a free sample program), which is about $3 a chip, but there are smaller chips available for 1/2 to 1/4 the cost which should still be capable of running the code.

EDIT: Nevermind, I got PRINT SCREEN and PAUSE working on at least the keyboard I'm testing with. See the other thread for more info.
jmetal88
 
Posts: 793
Joined: Sun Jul 25, 2010 10:22 am

Previous

Return to PCjr Hardware

Who is online

Users browsing this forum: No registered users and 1 guest

cron