CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

USB GamePad with PIC18F4550
Goto page Previous  1, 2, 3, 4, 5
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temtronic



Joined: 01 Jul 2010
Posts: 8511
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 28, 2022 9:43 am     Reply with quote

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: 17981

View user's profile Send private message

PostPosted: Mon Mar 28, 2022 9:51 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 28, 2022 10:26 am     Reply with quote

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: 8511
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 28, 2022 11:11 am     Reply with quote

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: 35
Location: Finland

View user's profile Send private message

PostPosted: Tue Mar 29, 2022 9:08 am     Reply with quote

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: 8511
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 29, 2022 1:02 pm     Reply with quote

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: 2

View user's profile Send private message

PostPosted: Tue Mar 29, 2022 2:16 pm     Reply with quote

@jaka : Can't thank you enough for sharing that codebase. Cheers!
manusoftar



Joined: 19 Mar 2022
Posts: 46

View user's profile Send private message

PostPosted: Tue Apr 05, 2022 11:08 am     Reply with quote

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: 130

View user's profile Send private message

PostPosted: Wed Apr 06, 2022 6:18 pm     Reply with quote

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: 8511
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 08, 2022 7:58 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4, 5
Page 5 of 5

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group