Author Topic: Help understanding a circuit  (Read 4504 times)

0 Members and 1 Guest are viewing this topic.

Offline terrieaTopic starter

  • Contributor
  • Posts: 20
Help understanding a circuit
« on: July 17, 2010, 10:42:52 pm »
Hi folks,

Yet another newbie question.
I bought a cheap USB Joystick that never worked, and I decided to keep the case and replace its internals with a Microchip based circuit to make my own USB joystick. The thing is this Joystock have a board with buttons and LED for its frontface. I need to hook up the Microchip to it, and I have to figure how it works to do it properly. I made a quickNdirty diagram of the board which is very simple:

There are five buttons, four LEDs, all driven by eight pins. The LED on the left and the two buttons on the right are quite simple, but what puzzle me are the three buttons and LEDs in the middle. They share the same pin for button sensing and LED switching. How is it possible to set the pin voltage to switch on/off the LED AND sense the button on the same wire ?

Thanks for your help
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19929
  • Country: gb
  • 0999
Re: Help understanding a circuit
« Reply #1 on: July 17, 2010, 11:03:06 pm »
The circuit doesn't have a power supply, which is positive, negative, 0V?

Assuming the top rail is negative and the bottom rail is 0V, otherwise it wouldn't work.

When the switches are open, the voltage on the output will be equal to 0V. When the switches are closed the output will be lower (remember it's a negative supply).

For example, suppose it runs off -15V and the LEDs have a voltage drop of 2V.

The current through an LED when the switch is closed:

I = (V-Vf)/R = (-15-(-2))/(1000+1000) = (-15+2)/2000 = -13/2000 = -0.0065 = -6.5mA

The voltage across the top resistor is equal to:
V = RI = 1000*-0.0065 = -6.5V

Therefore the voltage at the input is equal to the supply voltage minus the LED's forward voltage:
V = Vs-Vf = -15-(-6.5) = -15+6.5 = -8.5V

The negative numbers are because the voltage is negative.

I probably could've saved a bit of time by using the potential divider calculation, it's just easier for me to work it out in my head by doing it the long way.
 

Offline RayJones

  • Frequent Contributor
  • **
  • Posts: 490
    • Personal Website
Re: Help understanding a circuit
« Reply #2 on: July 17, 2010, 11:19:11 pm »
We have to presume the top rail is ground and the lower is Vcc.

The secret is the micro can, within a few instructions, set the pin as an input instead of an output, and determine whether the switches are closed. You would need weak pullups at the micro to sense the 1K being grounded by the switches.
ie. if the micro's pull up was 10k the resultant voltage could be a marginal logic 0. If the pull up was larger, the voltage would be lower and a more reliable 0 could be ensured.
Actually on second thoughts it is not that easy, the LED is still in circuit, and will contribute as a pull up too, albeit the drop across the LED will set a lower source voltage.
You would have to check the input levels for a valid logic zero to see if your logic zero would be reliable.

If LED is ostensibly on, the brief moment the micro pin becomes an input would be unobservable to the human eye.

Won't the LED light when a switch is held on?
NO, if the micro is sending a logic high out for the LED off state, the LED will remain off as the 1K will not be strong enough to overcome / drag the LED's cathode low enough.

This is actually common practice for front panel displays sharing a pin's function in such a way, and especially handy if the micro's pins are in short supply, but you have to be careful with the logic zero levels coming back to the micro.
 

Offline terrieaTopic starter

  • Contributor
  • Posts: 20
Re: Help understanding a circuit
« Reply #3 on: July 17, 2010, 11:48:14 pm »
Thanks very much for the explaination. That's exactly what I was looking for. So simple I didn't thought of it. Switching the pin to input just for reading and put it back to output. I'll chek to the levels and try not to blow everything.
 

Offline RayJones

  • Frequent Contributor
  • **
  • Posts: 490
    • Personal Website
Re: Help understanding a circuit
« Reply #4 on: July 18, 2010, 12:11:58 am »
You will still need to take care with the usual de-bouncing of the switches.

All that really changes in software is you need to add the port direction manipulation to your switch reading routine, otherwise it works the same.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11713
  • Country: my
  • reassessing directives...
Re: Help understanding a circuit
« Reply #5 on: July 18, 2010, 02:24:42 am »
i'll prefer position sensitive joystick where the software will know if we just tilt the joystick a little bit or all the way, usage of potentiometer and chip ADC feature is the way to do. do you mind to post the joystick picture here? i'm not sure i understand the schematic above. probably u meant the diode symbols are actually the LEDs?
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline terrieaTopic starter

  • Contributor
  • Posts: 20
Re: Help understanding a circuit
« Reply #6 on: July 18, 2010, 04:21:55 am »
RayJones>
I saw a code example of software debouncing. Didn't really dig into it, but seems the principe is to check if the value read from the pin is stable for a certain delay before considering the input have actually this value. Is there a rule of thumb to calibrate the delay of the debounce ?

shafri>
This Joystic is similar than the ones fond on arcade machines. The directions and buttons are all switches. Much more suitable for action games requiring fast/accurate actions. Positions joytick are far better for games requiring steady accurate action like flight simulators. I bet that's more your type of games ;)
For more precisions about the scematic, it is only a small part of the joystick. More precisely the joystick is originally composed of two boards. One main board with the main controls (directions, actions buttons, ...) and the chip. A second front-panel board with a "status" display (LEDs) and some controls buttons (start/select/etc..). I can replace the main board because the buttons are separate components attached to the case, not to the board. But for the front-panel board, the buttons are just contacts on the board itself, the LEDs are smt, and the board if shaped to fit exactly in the case with buttons and LED position matching the layout of the case. In a word it would be a nightmare to make another front-panel board. The schematic represent only this front-panel board, the 8 endpoints on the left represents the 8 wires coming out of the board that I have to plug to my microchip (which will replace the defective main board).
And yes the diodes represents the LEDs. again, It's a quick n dirty schematic. very quick, very dirty.
 

Offline RayJones

  • Frequent Contributor
  • **
  • Posts: 490
    • Personal Website
Re: Help understanding a circuit
« Reply #7 on: July 18, 2010, 04:49:02 am »
RayJones>
I saw a code example of software debouncing. Didn't really dig into it, but seems the principe is to check if the value read from the pin is stable for a certain delay before considering the input have actually this value. Is there a rule of thumb to calibrate the delay of the debounce ?


Yes, every switch contact has bounce when the contact is opened/closed.
The usual approach is to initially sense a change, then wait 10ms or so before accepting the switch state in software.
If you don't do this your software will more likely than not see multiple presses for one nominal physical operation of the switch.

If you're lucky you have a manufacturers data sheet that will specify the bounce duration, or next best use a DSO and capture the input a few times and see how long it lasts for.
A good rule of thumb is to then at least double the delay time to ensure long term reliability.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19929
  • Country: gb
  • 0999
Re: Help understanding a circuit
« Reply #8 on: July 19, 2010, 08:10:50 am »
i'll prefer position sensitive joystick where the software will know if we just tilt the joystick a little bit or all the way, usage of potentiometer and chip ADC feature is the way to do. do you mind to post the joystick picture here? i'm not sure i understand the schematic above. probably u meant the diode symbols are actually the LEDs?

If I remember rightly, old joysticks were completely analogue and  used to connect to a special connector on the sound card which used an ADC.

A modern USB joystick with probably have an MCU and an ADC built-in.
 

Offline RayJones

  • Frequent Contributor
  • **
  • Posts: 490
    • Personal Website
Re: Help understanding a circuit
« Reply #9 on: July 19, 2010, 08:39:54 am »
Actually if I remember rightly, the "ADC" was merely a multivibrator who's frequency varied according to the joystick pot's position.
The frequency was fed into a gated counter, the number of pulses counted over known period determined the position.

So not an ADC as you would normally consider / use, but perhaps useful to keep in mind for other designs.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf