# How to correctly set logical high level on a PS/2 port?

I'm trying to make a keyboard emulator on ATmega16A. I'm currently implementing logical low as output-zero, and, since the host(?) is supposed to pull up the line, I send logical high state as input mode of my pins. This lets me easily check that inhibit condition hasn't happened while I'm transmitting data, in addition to outputting "1".

But the problem is that in this mode, the time to raise the voltage to 95% VCC appears to be about 25 μs, which is quarter of the maximum allowed clock period (minimum frequency is 10 kHz). So I've now tried to actively drive the pin to VCC, and only then switch it to input mode to check for inhibit condition.

Is this kludge of actively driving the bus high actually legal from the protocol POV? I'm following this document and have failed to find how exactly one should output logical high level.

Should I instead use a lower-resistance pull-up resistor on the keyboard side and leave the pin in input state when trying to output logical high value?

• 95% is not "barely resembling a good signal", to be honest, it's pretty solid (and not very surprising it takes long – effectively, the pull-up has to charge the parasitic line capacitance, and you know how capacitor charge curves look!). I really don't know enough about the IO pin characteristics of ATMegas to comment on impedance, but PS/2 really is an open collector bus, and thus you mustn't actively drive it high, because you'd be missing the inhibit condition. Maybe adding weak pullups on the keyboard side would be permissible? (completely different direction: why not USB? why Atmega?) – Marcus Müller Sep 1 '19 at 10:37
• But what sense would debugging a hardware that you won't use in the end make? – Marcus Müller Sep 1 '19 at 11:11
• @MarcusMüller logic doesn't depend on hardware. What I'm trying to develop first is the logical side: bits, delays, sequences of commands and responses etc. – Ruslan Sep 1 '19 at 11:14
• ATMEGA16 does USB, but badly - see AVRUSB. – Jasen Sep 1 '19 at 11:32
• You could do what the MCS51 series (8051 and siblings) do: Switch to high for a short time with a low impedance and after that switch to high impedance. Well, you might need an additional port pin and a resistor for that. Or you try the internal pull-ups. – the busybee Sep 1 '19 at 11:40