Maker Pro
Maker Pro

Simultaneous events

I am not sure what micro-controller I would need for this. I want to set up an array of 8-12 buttons, and show which are being pressed simultaneously. I would assume I would need a specific micro-controller that has as many GPIO pins as there are buttons being pressed. My end goal is to make a USB game-pad that can handle multiple simultaneous button presses, but I am at a loss trying to figure out which micro-controller would be best suited for this. Thanks.
 

KrisBlueNZ

Sadly passed away in 2015
Any small microcontroller can do this, but you should investigate ones that have USB interfaces built-in. Some of the larger PICs have this, I think, and some of the larger AVRs.

You can scan multiple buttons in a grid using multiplexing, to reduce the amount of I/O needed. You need to use diodes in series with the buttons, so you can detect buttons individually when multiple buttons are pressed. This is standard though.
 
Thanks a lot for the reply. That seems like a logical path. Seems like my best option in PIC land, since I have a PICKIT3, is the PIC18F4550. Has USB interface, will operate with 5V USB power, lots of I/O ports (35), so no need for multiplexing. Seems a bit pricey though at $5 a pop. I don't need that many I/O Pins, but I couldn't find another PIC to satisfy my constraints.
 

KrisBlueNZ

Sadly passed away in 2015
I suspect you won't find any really cheap micro with built-in USB.

Multiplexing doesn't just save I/O pins; it simplifies layout (provided your board is double-sided or multi-layer) and reduces the number of ESD protection components needed.
 
I figured I wouldn't find any on the cheap, but $5 is reasonable to simply create a USB device. I hadn't really considered any layout for this since it would only be a one-off sort of project, and I was going to use perf-board. I was leaning toward reviving an NES controller that was broken by adding USB functionality instead of the "D-cannon" connector it has native. I think that comes out to only 8-buttons needed. Later I was going to find a broken SNES controller, and do the same if this worked out.​
 

Harald Kapp

Moderator
Moderator
As it is most unlikely that a human can press 2 (or more) buttons really at the same instant in time, you'll have to consider what "simultaneously" means in your context. E.g. two buttons pressed within 1 ms? This means that a single button press willl be delayed at least by this time because the controller has to wait 1 ms and look for a second button press to decide whether 1 or two buttons were pressed "simultaneously".

You will also have to add some debouncing to your software.
 
The 18F45K50 is an update of the 4550 that has more features and costs $2.93 unit price from Microchip Direct in PDIP or $2.74 in TQFP (surface mount)

Bob
 
Thanks for pointing out the 45K50. I had saw it before, but notice that there was only 11 left at the price of $2.93, but I just saw another link at that same price. Thanks.

I was wondering if it would just be easier to debouce using two 7400 NANDs as an SR latch or a 7475. For an 8 button controller I would need two 7400s or 7475s, and a 12-button controller I would need three 7400s or 7475s. I am crunched for space within the NES controller since I would like to reuse the original contacts of the original PCB. To do so I would cut the board as shown below.


nescontrol.jpg
 
Last edited:

Harald Kapp

Moderator
Moderator
I was wondering if it would just be easier to debouce using two 7400 NANDs as an SR latch or a 7475
It depends on what you take for easy.
A hardware solution will relieve you from some code for debouncing in software at the cost of additional hardware.
A software solution saves you additional hardware at the cost of a few lines of code.

Since almost any microprocessor you are going to use will have tons of spare cycles to burn while waiting for someone to press a button. I'd go for the software solution.
 
I have purchased a few 18F45K20 chips that have a few weeks lead time. Reasonable price so no complaints. I read over the software debouce article pointed out, and I have a feeling this type of solution is better to cut down on space since a 40 pin dip takes the bulk of the space I have. I don't trust myself with a flat pack since I have no experience with them. In the mean time I did some research into using a keyboard encoder from a usb keyboard to register button presses. Does anyone know if a keyboard encoder would satisfy the multiple button presses that a gamepad would require? I have a feeling keyboard to keyboard it would be different how many keys it can register at once. This may be a better solution in the short run since I happen to have two dead NES controllers that I could modify.
 
Below is how I would splice in the PIC18F45K50 to the original circuitry. The buttons and pull-ups and 4021N are all from the NES controller board. I am thinking of removing the 4021N from the PCBs socket, and then make a PCB to house the PIC18F45K50, and route the necessary pins to a two 8-pin row of headers at DIP spacing so that I can seat my solution where the 4021N used to be. I am not sure yet if I will have the spacing clearance, if I don't I may consider the flat-pack package.

schematicn.jpg
 
Something like this layout would be optimal I think if the schematic has no errors. Of course the 4021N will not have a chip, but rather rows of male header pins to seat into the original NES controller board.

boardnesco.jpg
 
hi,

why not use a smaller pic maybe a 25k50 28 pin or even a 14k50 if it has enough I/o pins free.


Secondly I would strongly recommend using in circuit programming for development, so you just need a header to connect to. you can even just leave staggered holes in the back of the pcb and push fit a connector while programming, just beare in mind thet the icsp needs highish impedance on the required lines so either avoide using portb.6 and 7 or... also you will need a 10k pullup on the reset and connect that to the icsp connector.

what compiler will you use?
 
I am thinking of just wiring the USB cable directly in instead of having the connector. In this case would it be more beneficial to layout if the mounting holes and pads for the USB wire were in different locations? For example, keeping the voltage and ground USB wire mounting holes closer to the PIC itself (PINS :31/32 or 11/12), and the data lines closer to the pins on the PIC itself (PINS: 23/24). In most USB boards where I have seen the USB cable directly soldered to the board and where they have no connector, the pins are in a a row, and not spread over the board. The layout may be a bit easier if I choose the mounting holes for the USB wires to be closer to where they need to be routed instead of putting them in a row, and routing them to the PIC's pins.


I have considered using a smaller PIC after I have tested on the 45K20. This seemed to be my cheapest option, and will be easiest to prototype with since it is a DIP package. I was thinking of adding an ICSP female header to come out the back of the device in my prototyping stages that way I could just plug my PICKIT3 directly into the female headers using long male header pins to bridge between the PIC's female header and the devices female header. Thanks for pointing out the 10K for the reset. I have a feeling that there is a lot that I could change on this board/schematic, but I threw it together in a few minutes the get the idea on "paper". I have yet to receive my PIC45K50 chips in the mail, but they are on their way from Thailand. I am considering replacing the entire board on the NES controller with a full fabricated board solution as well. If I am going to put in the time I would like a nice product in the end. I quite like the feel of the original NES controller so I am sticking with that case. Does anyone know how to layout traces for push buttons that work with that rubber (capacitive?) material. I kind of want to build up a solution where you could just take out the existing NES controller board, and replace it with this custom solution. It seems like those board's days are numbered.
 
Last edited:
You can for sure have the USB cable directly connected to the PCB, however keeping the connector( ideally close to the pin 23-24) keep your options open as you can solder the cable in the connector holes anyway. You can also move up the 4021 close to the pin's 40 -->30 and just leave the crystal and the capacitors on the board bottom. You have very few tracks so I suggest to place them on the top layer as much as possible and to fill the bottom with a large ground plane.

Olivier
 
Top