second usb /ps2?

Discussion in 'Computing and Networks' started by Mathematics!, Mar 22, 2010.

  1. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    Ok , the usb pinout is
    one pin 5volts , 2 data pins , 1 ground pin
    here
    http://pinouts.ru/Slots/USB_pinout.shtml
    For the PS2 DIN connectors for old mouses/keyboards
    they are
    http://www.burtonsys.com/PS2_keyboard_and_mouse_mini-DIN-6_connector_pinouts.html

    I have an old usb to ps2 adapter connector that I am mucking around with and I am curious about a few things

    OK , forget for the moment the adapter connector and just focusing on the ps2 pins of an old keyboard.

    First how is the ps2 keyboard sending data is it the same voltage as usb?
    If I wanted to read the keyboard bits from a ps2 keyboard connector into a microcontroller how will I know the difference between a one and a zero? Is this data pin on the ps2 connector having a 5volts for a 1 and a 0volts for a zero...
    What do I do with this clock pin....
    Do I compare the clock pin the the data pin , I just don't know how to read it directly from the pin to my MCU.

    Basically what modulation scheme and voltage are the using to delimit a one from a zero. I know they use 11 bits send out to give the actual one byte key pressed....

    Also when sending usb data what delimits a 1 from a zero on the data line
    And why are their 2 data lines for usb?

    Thanks for any help with this
     
  2. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    The keyboard serial protocol is a very simple serial data format driven by an external clock signal. You send clock pulses from the MCU and read the data bits that are sent back. That is one is easy to do in software on a PIC or whatever.

    It's just 5V logic levels and is identical for both PS/2 keyboards and the older DIN plug keyboards.
    Info here:
    http://www.beyondlogic.org/keyboard/keybrd.htm

    More info and an actual interface circuit here:
    http://www.computer-engineering.org/ps2protocol/

    Keyboards and mice that come with USB adapters actually have two completely separate interfaces. They either use the spare pins on the PS/2 plug for the USB data lines or sense what type of signals are coming from the PC end and connect the appropriate internal interface to the plug.

    USB is a very complex protocol involving two way handshake setup.
    The only way to get this to connect with any external DIY device is to use a chip containing a dedicated USB slave peripheral, like some PICs and other MCUs or dedicated adapters like the FTDI modules here:
    http://www.ftdichip.com/Products/FTEvaluationKits.htm
     
  3. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    For the PS2

    Ok , but I don't understand what a logical one and zero is ?
    Is it 5volts for a 1 and 0 volts for a zero?

    Should I just use two pins on my AVR chip one directly connected to the clock pin the other directly connected to the data pin?
     
    Last edited: Mar 22, 2010
  4. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    It's all in that second link I posted...

    Data is 5V logic, High = 1.

    The clock & data lines are bi-directional using open collector drive and pullup resistors. You can link them directly to input pins, but need a couple of transistors driven by output pins (with appropriate base resistors) to do the open collector drive.
     
  5. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    Ok , I have taken one of my old computer keyboards apart.
    What I found is no chips or IC in it.

    The pictures attached is all that is contained in these PS2 keyboards.

    Basically a plastic strip of wire traces (no resistors on it or anything so I don't know how it can decide which key is which interms of voltage when a key is pressed )

    And the other picture is the only circuit board in the keyboard which just has 3 LED for the num,cap,scroll locks and a few resistors , capacitors ,and diodes that is it.

    I do see where the 4 wires are soldered on to it is on the board right before the resistors I am trying to figure out which wire is which?

    Their is a green, yellow, red, brown which are which???

    I got how to rigg up the data circuit using your second post with the transistors ,..etc. But what I am having trouble figuring out is do I keep the clock pin set to no voltage out it and just watch the data pin go to 5volts for a one and 0 volts for a 0.

    Do I keep checking the clock pin to see when the data bit is finished and when the next time to check for the next bit voltage????


    I am a little confused about this note I don't want to write data to the keyboard ... just want to read the 11bits being send by the keyboard into the MCU memory. I don't even know what righting to the keyboard even does their is no chips in the keyboard that I see at all...

    Thanks for any help in clearing up the wire colors and data reading
     
  6. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    There will be a chip there somewhere, probably a COB *(black blob)
    Old PC PS/2 keyboards often used Intel 8051 cpus
     
  7. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    I think I figured out that black is VCC and yellow is ground on this PS2 cord. I tested it by cutting the wires , stripping the wires , and attaching a digital multimeter. Heres a picture of the cord attached. The only voltage I got when I touch any two wires was 5volts dc only when I touch the yellow and black wires with the DDM.

    However I still cann't determine between the red and green wires which one is for data and which is for clock yet? I guess that will have to wait until I build the circuit.

    But I do also have a few questions of what resistors to use and should I use PNP or NPN transistors. And are those arrows on the MCU A and B pins diodes if so which ones should I uses? (Maybe switch diodes if that is ok???)

    As for the logical one being 5volts and logical 0 being 0volts I get that but what I don't get is how I delimit when the next bit is being sent , I know I do it from the clock in someway but I don't know how.

    It is some what confusing how this works. I am trying to figure this stuff out for the first time.

    Thanks for any additional help
    Maybe if you have time we can go thru how to send this
    01100101001 or something.

    Thanks
     
  8. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    Are you talking about on the plastic sheet where all the traces are because if you are I don't see anything but traces. If your talking about on the time circuit board (the only one in the keyboard)
    Then all I see on it is 3 LEDs, a few capacitors , 3 or 4 resistors , and 2 diode looking things that only have 2 pins on them.
    They are labeled FB1 and FB2???

    Other then that their is no other thing in sight other then the physical ps2 wires running to the connector. Unless the connector itself houses the
    chip. I always thought the chip was on the mobo somewhere not on the physical keyboard itself.

    Maybe I am wrong though.
     
  9. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    The photo just shows the keyboard membrane.

    At an edge of that there will either be a 'tail' with multiple conductors that connects to the keyboard IC, or the traces will go into a small resin blob - which is a bare silicon chip bonded to the flexible circuit and covered with epoxy to protect it - the COB that Blueroom mentions.

    For wiring, why not just plug it in to a socket & wire to that? The pinouts are fixed and defined.

    By 'arrows', I guess you mean the symbols at the side of the data & clock legends? They are just typical markings for an external connection to that fragment of schematic.

    The transistors should be NPN, as shown. You need series resistors in the connections to the transistor bases or either the MCU or transistor will be damaged. Use 4k7 there.
     
  10. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    Ok , I will take your words for it but it doesn't look like it's their must be really small and blend in with the traces.

    I mean in your second link half way down the page. In the diagram with the MCU , two NPN transistors , two 4K7 ohm resistors. On pins A and B their is a arrow on the line. Anyway was wonder if this is a electronic component or not? If it is then what component and type do I need?

    I am assuming I am the host, so to read data from the keyboard.
    I would follow the keyboard to host directions.
    Question when would you ever need to send the keyboard directions from the host? Or for that matter anything to the keyboard I see no purpose for this??? Isn't the whole point just to retrieve keys from the keyboard...
    Even if you can send stuff to the keyboard I don't know what I would send it to do anything for me.....

    I am slowly getting the picture of how this thing is going to work
    Don't really get why though you need a host to keyboard transmission ever and if so what the different commands you can send it to do stuff for your or what stuff it can actually do for you ,...etc
     
    Last edited: Mar 23, 2010
  11. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    That's the same bit I was looking at, the arrow symbols just indicate connections.

    The write facility is to control the lights on the keyboard. Some may have other programmable features as well.
     
  12. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    Gotcha

    To delimit the bits you read from the data line on when the clock is on the low side. If the data pin at that point is 5volt it is a logical 1 and if it is 0volts it is a logical 0

    Correct me if I am wrong with me understanding of how the data transmission goes.

    So on my MCU I just watch on the clock pin to see when it goes low then read from the data pin the value wait until it goes from high to low again read next data bit ,... on an on.

    If so then I am wondering from the schematic given in the second hyperlink why we even need the C and D pins thought the clock signal would be generated by the keyboard it self. So then I would just use the fact when pin B goes low read from pin A to get the data bit.

    Are these 2 other pins C , D just for the oppiste thing sending from host to keyboard which I am really not concerned about to much if it is just to turn on the keyboard LED or something ....?????

    I guess I am still missing part of the picture , not really sure why I need the open collector ,...etc
     
    Last edited: Mar 24, 2010
  13. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    Yep, looking through in more detail the keyboard always generates the clock.

    You can just connect clock and data to input pins on your micro, with pull up resistors.
     
  14. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    Wait , why do I even need pullup resistors.
    Cann't I just use pin A , B directly connected to data and clock ps2 pins
    And when the keyboard sends the clock signal low read the data at the data pin ,...etc etc

    I am not even sure why we need the 5volt VCC and GND on these pins...
    I thought you only needed the VCC , GND directly connected to VCC and GND of the ps2 pins.

    Because if you put 5volts on A , B pins then won't the data , clock pins be at 10volts when the keyboard clock goes high , same with the data pins?
     
  15. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    I'm sorry, I do not have a clue what you mean...

    The keyboard outputs are supposed to be open collector - without pullup resistors, they will stay low or only rise slowly. The resistors are needed to give a fast rise to 5V.
     
  16. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    What I mean is in the diagram.

    They have 4 pins on the microcontroller the 2 lower ones have the NPN transistors on them.

    There are resistors right below the 5volt source.

    Why do we need all this ... why cann't I just connect the clock pin on the ps2 to a pin on my MCU and the data pin directly to another pin on my MCU? Why do we need 4 pins and all those transistors resistors and VCC supply?

    At anytime I can put 5volts or zero volts or -5volts on a given pin of my
    MCU.

    Thought I only needed to supply power to the VCC pin on the ps2 connector so I don't understand why I need this addition VCC for the other pins????

    I guess I don't know what voltage I should have on pins C and D for me to beable to read data on pin A. Thought I only needed pin A , B why this open collector pin C , D stuff?

    I can hold line A or B high or low with my MCU if I have to...


    I thought the general procedure for reading keyboard data is
    the keyboard generates the clock signal so all I have to do is watch the state of that and when it goes low read what is on the pin A of the MCU if it is 5volts then it's a 1 if it is not then it is 0......
    for the next bit I wait until the clock signal goes again from high to low and repeat the proccess.

    Maybe you can explain because I am alittle bit confused and maybe I am missing some stuff.
     
  17. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    We've already agreed that you can remove the transistors as you don't need to write to the keyboard. C & D are then not used.

    The clock and data lines go straight to input pins on the mcu. They have shown buffers in the circuit but you can just directly connect them. (A & B).

    You need pullups to define the High level as the keyboard clock and data are driven by open collector transistors in the keyboard controller. They only switch to ground or open.

    The sequence should work like you say.
     
  18. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    I guess I didn't get what open collector meant
    Sorry , if I am being stupid.
    So the only reason why we need the 5 volts and pullup resistor is because the keyboard is not generating the voltage internally it is relying on the external 5volts to supply the highs and low's.... gotcha thought the keyboard itself was supplying it internally with the VCC pin on the ps2 connector... but it is not it is this open collector thing.

    Which makes me wonder what the 5volt VCC pin on the ps2 is doing for the keyboard?

    I am directly connecting the pins clock and data to the ps2 keyboards clock and data pins.
    If I do decide later to build the circuit with all the components NPN transistors , C/D pins...etc Then what do I keep C and D pins at?
    Do I just level them both always low if I want to read keyboard data Anyway did you say I should use a 4.7kohm resistors for both pullup resistors?


    Do I just keep pins C and D low on the MCU if I want to just read keys from the keyboard?
    Because I don't mind rigging it up like the diagram I am just unsure with these 4pins on the MCU how I am suppose to read the data?
    Do I just keep pins C and D always low?

    So the general algorithm
    is watch pin B for when the clock signal goes from high to low
    then read voltage level from MCU data pin ( 1 = 5volt , 0 = 0volts )
    repeat the process for the next bit.

    What I don't get is how do I know when the keyboard is not being used at all (like no keys are being pressed). Because I don't want to keep reading useless info.
    Maybe it's when both pins are always high or if the clock pin stay's always high the keyboard is not sending anything (i.e no keys pressed.)

    I think if you can answer all these questions I am ready to build it and code it.
     
  19. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    The 5V runs the processor in the keyboard that scans the keys and produces the serial data stream.

    The C & D pins would normally be low, so the transistors are off and not affecting the data sent from the keyboard.
    Don't forget to add resistors in line with the base connections if you use the transistors.

    As I understand it, the keyboard only sends a burst of data when a key is pressed or released.
     
  20. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    That only abilies if I use the C and D pins (I.e put +-5volts out those pins)
    What resistor values on the base of these transistors do you recommend?


    And I am going to start building/coding it up.
    I am going to use
    NPN general purpose transistors
    4.7kohm resistors for the 2 pullup resistors
    2 transistors base resistors ?????ohms

    Thanks for all your help I finally got it
    Sorry if I was being a little repetitive
     
Loading...