3
\$\begingroup\$

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?

\$\endgroup\$
  • 1
    \$\begingroup\$ 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?) \$\endgroup\$ – Marcus Müller Sep 1 '19 at 10:37
  • 1
    \$\begingroup\$ But what sense would debugging a hardware that you won't use in the end make? \$\endgroup\$ – Marcus Müller Sep 1 '19 at 11:11
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Ruslan Sep 1 '19 at 11:14
  • 1
    \$\begingroup\$ ATMEGA16 does USB, but badly - see AVRUSB. \$\endgroup\$ – Jasen Sep 1 '19 at 11:32
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – the busybee Sep 1 '19 at 11:40
7
\$\begingroup\$

With PS/2 interfaces, both the host and the device should have pull-ups. So put stronger pull-ups on AVR side. Pulling it high even for a moment is just wrong.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.