Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Circuit layout for connecting PS/2 port to a PIC?

Status
Not open for further replies.

ChemE

New Member
I am working on a project to interface a mouse and keyboard with an xbox 360 controller. I am still learning but I do understand PICs so much better after 2 weeks of learning. I believe I have figured out how to connect all of the buttons from the 360 controller to a PIC(lets assume I am using a PIC16F737) using 4x4066IC analog switches. So here are the questions that I have:

  • Could someone please draw the schematic for connecting a PS/2 female port to a PIC16F737?
Please do not tell me to search Google for the answer because I have already and I have read whatever I could. Nothing I found through a google search was clear about connecting a PS/2 port to a PIC. A drawing of exctaly how to connect a PS/2 port to a PIC with an explanation of why any resistors or capacitors are used would be awesome.

  • I need to attach 6 analog signals (coming from potentiometers) to my PIC16F737. Do I need to attach reference voltages to the + or - Vref spots to be able to use th analog (DAC) pins?

  • Since I am attaching 6 analog signals to my PIC do I need a different Vref connection for each of the 6 signals?

  • What exactly is a Vref for?

  • The best way for me to learn about the analog pings on PICs is if someone could please draw a schematic for connecting analog signals to the analog pins of a PIC16F737 with a little explanation.

Thank you in advance for your replies, I am learning a ton from them.
 
hi chem

I need to attach 6 analog signals (coming from potentiometers) to my PIC16F737.
Do I need to attach reference voltages to the + or - Vref spots to be able to use the analog (DAC) pins?

NO, Use the PIC's internal +5Vref.
[look at ADCON1 reg on the datasheet, if VCFG0 and 1, are set to logic 0, then internal Vref]

Since I am attaching 6 analog signals to my PIC do I need a different Vref connection for each of the 6 signals?
NO, Use the PIC's internal +5Vref

What exactly is a Vref for?
If +Vref is say +5v then an ADn, input voltage of 0v thru to +5V would give you a ADC value of,,, 0 to 1023 [its a 10bit ADC, 0x3FF]

If +Vref was say, +2.5V then an ADn, input voltage of 0 thru +2.5V would give you an ADC value of 0 to 1023.

If +Vref set to +5V and -Vref set to say, +2V, then an ADn, input voltage of +2v thru +5V would give you an ADC value of 0 to 1023
Caution: there are min/max limits on +/-Vref

The best way for me to learn about the analog pings on PICs is if someone could please draw a schematic for connecting analog signals to the analog pins of a PIC16F737 with a little explanation.

You must say what the voltage ranges are you that you want to connect, as it effects the answer I can give you.

This should help with ADC part of the post.
 
Last edited:
I did the programming for this guy's project a few years back, which involves interfacing a PS/2 mouse:
http://imakeprojects.com/projects/seeing-eye-mouse/

There are some schematics/connection diagrams on there, though not to the level of drawing an exact picture with a real connector. But really, a PS/2 connector only has 4 pins - +5v, ground, data and clock. Hooking up +5v and ground is a no-brainer, and then you hook up data and clock to whatever PIC IO pins you want to use - there's not much need for a diagram, other than perhaps a diagram of which pin is which on the particular PS/2 connector you are using, which you can surely find by searching the web.
 
In case anyone who is replying is interested the xbox 360 controller uses a +5v power so from what I understand that will work great with PICs since I think most if not all run on 5v.

Eric you said:
You must say what the voltage ranges are that you want to connect, as it affects the answer I can give you.

To give a good example of what I am dealing with imagine a 1 dimensional axis of a joystick; if the joystick is pushed up all the way then that would equal 1.61v and if it is pushed down all the way that is equal to 0v. So if it is left idle in the center it should read 0.805v.

So 1.61v is the max and 0v is the minimum voltage I would deal with in my particular case.

So let me get this straight.
  • If I have 6 analog signals (6 different potentiometers) to attach to my PIC all I would need to attach is the +5v, ground and the 6 wires from the potentiometers? Or is there more I would need to connect to get this to work?
I hope what I just said was clear if not ask me to clarify

evandude,

From looking at the circuit from your webpage it seems very straight forward. Very nice article it's very useful.

  • I don't see any resistors or capacitors on the tracers going to the PS/2 port... I guess you didn't need them? Could you explain why?
  • Do I need to be worried about destroying a PIC if I hot plug into the PS/2 port?
  • I have attached an image of a PS/2 port connected to a PIC and it shows some resistors and capacitors could anyone explain why they are there?

My guess is the Vcc is not at 5v, so that is the reason for the resistors. Am I right?

Thank you for your replies! They have been really helpful.
 
hi chem,

> To give a good example of what I am dealing with imagine a 1 dimensional axis of a joystick; if the joystick is pushed up all the way then that would equal 1.61v and if it is pushed down all the way that is equal to 0v. So if it is left idle in the center it should read 0.805v.
>> So 1.61v is the max and 0v is the minimum voltage I would deal with in my particular case.

Using these voltage inputs with a +Vref [internal] of +5V....
ADNin = 0V, ADC value = 000
ADNin = 0.805V, ADC value = (0.805/5) * 1023 = 164 [ 0xA4]
ADNin = 1.61V, ADC value =(1.61/5)*1023 = 329 [0x149]

IF, you wanted to increase the resolution, [get a bigger count range], you could set the +Vref to +2.5V,
this would have the effect of doubling the above count values.
You would have to connect a +2.5Vref voltage source to +Vref, this would change ALL the ADCin's to the new scale factor.
[You should not use a +Vref of less than +2.5V, else you would be out of spec for the PIC]


>> So let me get this straight.
If I have 6 analog signals (6 different potentiometers) to attach to my PIC all I would need to attach is the +5v, ground and the 6 wires from the potentiometers?

The spec sheet for the PIC, states that the source impedance of the analog voltage source should not exceed 10K0.
All this means is, the resistance value of the joystick pots should not be more than 10K0...
If this is not possible, then there are ways around it, a little more circuitry.

Or is there more I would need to connect to get this to work?
No, providing the joystick pots are less than 10K.

Hope this is clear, ask if not.

Regards
 
ericgibbs,

Thank you for your help I really appricate it. There are a few things that I would like to make sure that I understand. Please bare with me I am still learning.

  1. The minimum Vref for a PIC is 2.5v?

  2. Am I correct to say that +Vref and -Vref set the upper and lower limits for voltage range of analog pins?

  3. Since the range that I am interested in is 0v to 1.61v do I need to attach a Vref? If the range was 0v to 5v then I guess I would not need to attach anything to the Vref?

  4. Could I just set the internal Vref to 2.5v, if not why?

  5. I think the resistance value between the pots is 10k, so its not under 10k is that ok?

  6. When you ask about the resistance between the pots are you talking about the resistance between the upper voltage and lower voltage?

  7. I have included a drawing of how I was planning to attach the pots to my pic could you please take a look at it and make any changes if see something wrong?

Thanks.

evandude,

After looking at that project you had made with connecting the PS2 port to a PIC I made my own diagram.

  • Would you please take a look at it and see if there is anything wrong with it?
I think it would help me a ton with learning this and progressing my project further. Thank you.
 

Attachments

  • analog to PIC.jpg
    analog to PIC.jpg
    48.4 KB · Views: 311
  • ps2 to PIC circuit.jpg
    ps2 to PIC circuit.jpg
    39.7 KB · Views: 378
hi chem,
The minimum Vref for a PIC is 2.5v?
From the data sheets I use, yes.

Am I correct to say that +Vref and -Vref set the upper and lower limits for voltage range of analog pins?
Yes, BUT again there a limits to -Vref and +Vref, settings, they are descibed in the datasheet, IMO, not very well!.
EDIT:
A more accurate description of the +/-Vref action, would be: the +/-Vref values set the 'span' or 'slope' of the ADC.

Since the range that I am interested in is 0v to 1.61v do I need to attach a Vref? If the range was 0v to 5v then I guess I would not need to attach anything to the Vref?
No, just program the PIC to use the defaults, ADCON1, reg.

Could I just set the internal Vref to 2.5v, if not why?
There is no way to do that. You can buy 2.50V ref devices, to connect to the +Vref input, they are powered from the +5Vsupply line.

I think the resistance value between the pots is 10k, so its not under 10k is that ok?
Thats just at the recommended limit, no damage will be done if you connected a higher value resistance pot, it would just effect the ADC response/acquisition time.

When you ask about the resistance between the pots are you talking about the resistance between the upper voltage and lower voltage?
Yes.

I have included a drawing of how I was planning to attach the pots to my pic could you please take a look at it and make any changes if see something wrong?
Will reply asap.
 
Last edited:
hi chem,
ref your dwg of the PS2 connector, are you reading the pin numbers in reverse order.?

my kbd datasheet says.
1. kbd clk
2. gnd
3. kbd data
4. n/c
5. +5V
6. n/c

On the Xbox dwg, remember the 0V connection from the Xbox to PIC pcb.

As a side point,, are you aware that the kbd data and clock lines are bi-directional? and open-collector.
Have you had a look at the keyboard 'key' coding requirements?
 
Last edited:
ChemE said:
evandude,

From looking at the circuit from your webpage it seems very straight forward. Very nice article it's very useful.

  • I don't see any resistors or capacitors on the tracers going to the PS/2 port... I guess you didn't need them? Could you explain why?
  • Do I need to be worried about destroying a PIC if I hot plug into the PS/2 port?
  • I have attached an image of a PS/2 port connected to a PIC and it shows some resistors and capacitors could anyone explain why they are there?

My guess is the Vcc is not at 5v, so that is the reason for the resistors. Am I right?
If you look at the basic schematic shown at:
**broken link removed**
There are a number of external components that "should" be used in general, however on a PIC you can basically get away without them. The idea is that the PIC needs to be able to put the line in two states: pulled low (with an output drive) or pulled high with a weak pull-up resistor, so that the keyboard/mouse can pull it low to send data. The PIC can do the former of course with a pin set as an output, and it can do the latter by setting the pin as an input with the internal weak pull-ups enabled. If the I/O pins you choose to use for the data/clock lines do not have internal weak pull-ups available, you would need to add pull-up resistors externally. Check the datasheet.

I don't see anything immediately wrong with your schematic at first glance, however I didn't verify the pinouts of the PS/2 connectors, and you of course need to check the pull-up thing I mentioned above.
 
ericgibbs said:
ref your dwg of the PS2 connector, are you reading the pin numbers in reverse order.?
More likely assuming the keyboard pinout is the mirror image of the mouse pinout. [edit](Probably thinking "Why else would there be six pins?")[/edit]

The truth is the mouse and keyboard pinouts are exactly the same. At work, I have a PIC with one PS/2 connector with only four wires attached. It has been used to test both keyboards and mice.
 
Last edited:
hi tk,
I dont quiet follow what you are saying?

As stated the PS connectors for mouse and keyboard are identical and there are only 4 active pins, hence only 4 wires?

If you check the OP's original drawing the mouse and kbd are labelled as a mirror image.

Regards
 
Status
Not open for further replies.

Latest threads

Back
Top