View previous topic :: View next topic |
Author |
Message |
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Mar 28, 2022 9:43 am |
|
|
That switch has 5 connections, U,D,L,R and ground.
An 8-way probably has same layout BUT U and L will be closed when 1/2 way between Up and Left.
At least that's the way I made them 4 decades ago... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Mar 28, 2022 9:51 am |
|
|
Jay is dead right.
The manufacturers of these want to keep actual switches to the
minimum. So just 4 switches & 5 pins. |
|
|
manusoftar
Joined: 19 Mar 2022 Posts: 46
|
|
Posted: Mon Mar 28, 2022 10:26 am |
|
|
Now that I see it, I think you are right... well, 4 pins less... I will have to change my loop a little to consider more than one switch active for diagonals... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Mar 28, 2022 11:11 am |
|
|
You should consider using 3 pins of Port E and 8 pins of Port D as a 'matrix.
That gives you 24 push buttons you can scan.
Easy to modify the CCS 4x4kpd example.
This is how everyone has done 'lots of switches' in the past, and with good reasons. It's fast, cheap, reliable, easy to expand, group switches, etc. and the main reason....
it WORKS !
Jay |
|
|
jaka
Joined: 04 May 2014 Posts: 36 Location: Finland
|
|
Posted: Tue Mar 29, 2022 9:08 am |
|
|
If you plan to use a matrix to connect a lot of buttons, note that you need to add diodes for each switch. Otherwise you will see 'ghosting' effect when pressing down multiple buttons.
FYI, I have done similar project using CCS: http://kair.us/projects/j_ace/index.html
I spent quite a while optimizing the speed of the functions, and minimizing lag. The CCS HID examples are terrible if you consider the lag. The J-ACE has average lag of 0.8 ms and worst case lag of 1.1 ms. It is faster than any commercially available arcade joystick encoder listed here: https://inputlag.science/controller/results |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Mar 29, 2022 1:02 pm |
|
|
Looking through the posts I come up with....
17 buttons
4 hat switch
2 analog
2 USB
2 RS232
6 LCD
total 33 pins needed
That PIC has 35 I/O pins, take 2 off for 12MHz xtal.
so it'll all fit, well should
. the 'trick' is to see if you can arrange them into good 'groups' of pins.
Jay |
|
|
waffles
Joined: 21 Dec 2021 Posts: 10
|
|
Posted: Tue Mar 29, 2022 2:16 pm |
|
|
@jaka : Can't thank you enough for sharing that codebase. Cheers! |
|
|
manusoftar
Joined: 19 Mar 2022 Posts: 46
|
|
Posted: Tue Apr 05, 2022 11:08 am |
|
|
temtronic wrote: | Looking through the posts I come up with....
17 buttons
4 hat switch
2 analog
2 USB
2 RS232
6 LCD
total 33 pins needed
That PIC has 35 I/O pins, take 2 off for 12MHz xtal.
so it'll all fit, well should
. the 'trick' is to see if you can arrange them into good 'groups' of pins.
Jay |
To make it more clear:
- 17 buttons
- 2 Analog
- 4 pins for HAT SWITCH.
That get's up to 23 pins, besides that, from the 40 pins that this PIC has you have to take out 4 which are the two VSS and the two VPP pins, also you have to take another two pins for the XTAL, and two more for the USB Data and one more for the VUSB and one more for the MCLR.
Let's say I won't use and LCD as I don't intend to do on the final circuit.
The thing is that I already bought the multiplexors and, after all, that is one of the uses of multiplexors so it should work.
Also I believe that not all the ports on the pic can be used as regular digital I/O, like, for example PORT_E I think it would not work propperly as digital I/O which actually would decrease the number of available digital I/O ports that is what I think I would need to monitor those 17 buttons and the hat switch.
In any case I will post how my circuit and my code is looking know because I made several changes but it is still not fully working.
Thanks for your time. |
|
|
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Wed Apr 06, 2022 6:18 pm |
|
|
You can use a maximum of 30 IO pins.
I have several usb interfaces with 30 pins being used as IO. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Apr 08, 2022 7:58 am |
|
|
The 'problem' with using muxes, is that it adds another layer of hardware and software. While cost is not much, using them does increase the time to read the switches and 'figure out' what to do with the data.
Directly reading the ports is simple, efficient and FAST. You might need the speed, seeing how it's a game interface. |
|
|
|