Shop OBEX P1 Docs P2 Docs Learn Events
whats the max number of mcp23016 can be used on a single propeller — Parallax Forums

whats the max number of mcp23016 can be used on a single propeller

AHMET AKSUAHMET AKSU Posts: 62
edited 2007-07-27 16:33 in Propeller 1
is it possible to use 40 mcp23016 with propeller or is it possile to read 640 switches with i2c

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-24 15:04
    I believe you can have up to 8 MCP23016 devices per I2C bus and a Propeller can support multiple I2C buses with 2 I/O pins per bus.

    If what you want is to read large number of switch closures, I'd suggest using a matrix arrangement with a switching diode in series with each switch to avoid crosstalk in the matrix. You could use 74HC595 serial to parallel output shift registers for one side of the matrix and 74HC195 parallel input to serial shift registers for the other side of the matrix (20 x 32 or 40 x 16). Even though these are serial shift registers, they can be clocked very fast so that scanning the matrix can be done quickly, certainly fast enough for human interaction.
  • AHMET AKSUAHMET AKSU Posts: 62
    edited 2007-07-24 16:00
    thanks Mike Green. is this means for a 48 * 16 I must use 3 mcp23016 for the 48 and 1 mcp23016 for 16.is that right!
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-24 16:32
    If you want to use the MCP23016, you will need 4 devices for a matrix. You could do this as 48 x 16 (768 switches max.) or 32 x 32 (1024 switches max.) You could also use 74HC595 x 6 plus 74HC165 x 2 (I made a mistake on the part number in my earlier posting) which might be cheaper, but use more I/O pins.
  • deSilvadeSilva Posts: 2,967
    edited 2007-07-24 21:23
    The 23016 is not really a low-cost device. As the Prop is very well suited to substutute 1.5 x 23016 - with a huge capacity for any kind of preprocessing - you might even consider a multi-Prop approach. The only thing making it more complicated is its need for an additional EEPROM...

    The 74HC595 is a very good substitute for at least a PCF8574 at 1/4 of its price.

    When using 640 switches there must be a "system" behind it, generally leading to some matrix alignment in a natural way..

    Post Edited (deSilva) : 7/25/2007 4:54:33 AM GMT
  • AHMET AKSUAHMET AKSU Posts: 62
    edited 2007-07-25 06:51
    are there someone who have a scheme abaut using 74hc595 and 74hc195 for reading 640 swithes values
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2007-07-25 07:59
    Ahmet,
    Sure you can use eighty 8-bit shift registers but your requirement of 640 switches begs the question, are all these switches in the one enclosure or are they distributed about and also are they momentary action (push-button) or latching (switch).

    If they are push buttons it would be possible to wire up a matrix very simply in a 48 x 16 array so that you could set all 48 outputs active and read in 16 inputs quickly looking for a key press from which you can scan 48 lines in a successive approximation scheme to quickly derive which button is pressed. This requires only 8 shift registers compared to a 32 x 24 scheme which only requires 7 registers but takes longer to read in 24 (or 20) inputs.

    If they are switches then good luck as you can still scan them in a matrix but you definitely need those isolation diodes for each switch as Mike has pointed out (I just read his post properly and I'm saying the same thing).

    *Peter*
  • AHMET AKSUAHMET AKSU Posts: 62
    edited 2007-07-25 08:35
    the swithes are micro pushbuton swithes .every group have 40 micro switches and there are 16 groups.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2007-07-25 12:56
    For each group of 40 buttons which I am guessing are only operated one at a time as in visitor information exhibits etc then I would be inclined if it were me to program up a small 20-pin micro to scan this group of buttons and relay the results. How far apart are the groups anyway, that's a lot of buttons and I'm thinking that they would be several metres apart at least which would limit the shift register approach.

    Sorry Ahmet, you are making us work too hard while you dole out the information sparingly. We spend too much time guessing and I seems all too common on forums that someone may be given the responsibility to come up with a solution and ends up fishing for a way to do it. That may not be the case but you may notice there is a lot of nibbling at the bait with wordy replies while you casually jerk the line with one liners. Please describe what you are trying to achieve otherwise we will probably end up giving you the right answer for the wrong question.

    *Peter*
  • AHMET AKSUAHMET AKSU Posts: 62
    edited 2007-07-26 09:38
    peter in attach you can see buttons locations is it possible to work with i2c on·40 cm *160 cm area
    lam.doc 98.5K
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2007-07-26 12:42
    Ahhhhhhmet, it is all so clear to me now. Isn't Ahmet Aksu the actor in that Turkish film "Ice Cream"? I believe it was a comedy.

    But of course you are not the same Ahmet.

    AHMET! the document tells me nothing! Although I do understand that it's physical size is 40cm*160cm now and plus I've had a good laugh.

    Look, understanding the WHY helps to arrive at a better HOW. Your dimensions correspond to a small human body, is it possible that there would be many buttons/switches pressed at the same time? You don't have to say exactly what it is although that would help but I will just have to answer based on the limited information you have given. If you proceed with an implementation based upon advice given here and it doesn't work then don't blame us.

    You should know the basics of column/row addressing just by looking at your document. Imagine 3x 23016s connected up to the 40 columns and that each column in each row is connected straight through. So column 1 in the top row is connected to column 1 in the next row and so on all the way to the 16th row. Then do the same with a 23016 connected to the 16 rows. Imagine that your 40 lines are connected at the top of the diagram and the 16 row lines are connected down the right hand side. Draw a line through each row and each column and at the intersection of each row and column draw a switch so that it is connected to it's row line and it's column line. So your top left hand switch will be connected to column 1/row 1 and your bottom right hand switch will be connected to column 40/row 16.

    See! that was easy. the intersecting lines look like a net or a matrix which is why it is referred to as a switch matrix. Now instead of 640 lines you are doing this with 40+16=56 lines! From here software can select 1 column at a time by making only one of the columns an output and driving it low. Then software reads the 16 row lines to see if any of them is low, that is if no key is pressed you will read $FFFF (because of pullups resistors that you would have connected). There are many optimizations possible but that is the basic scheme.

    *Peter*
  • AHMET AKSUAHMET AKSU Posts: 62
    edited 2007-07-26 14:39
    Peter .Thanks for your answer.I understand your mean.I will use this switches arrays in indusrial field.So I must know that can i2c bus work properly abaut an area of 40cm*160 cm .I m asking that : each row has 20 cm distance to other row.the total distance betwen top and bottom row is 160 cm .is i2c bus suitable to this distance
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-26 15:33
    Ahmet,
    You are not discussing the use of I2C over this 1.6 x 0.4m area. You are discussing handling switch closures over this area. The switches would be connected to the I2C parts somewhere else close by. In any event, NXP has many application notes describing the use of I2C over moderate distances. They discuss the use of different values of pullup resistors and the proper characteristics of the drivers for SDA and SCL. At moderate distances like this, the type of wiring and the position of the wires (for the I2C ... not the switches) and the electrical environment are all important. The clock speed is moderate (100KHz) so the issues are similar to those for most kinds of serial communication.
  • AHMET AKSUAHMET AKSU Posts: 62
    edited 2007-07-27 14:14
    thanks Mr Mike Green . My idea is using one sx48 for every 40 piece of swithes and one propeller for 16 piece of sx48 I can see the sx an swithes side of the project .sx watch the 40 switches position and say the positions to propeller also propeller must say something to every sx this is good .I want to know that how propeller and 16 piece sx48 conect to each other.do you think abaut i2c or other method .which is sutable
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-27 14:42
    I don't understand why you insist on doing this project with an expensive part (like the MCP23017 or the SX48) as compared to a cheap part (like the 74HC595) and without using a matrix arrangement. A 74HC154 decoder would give you 16 outputs and you could use 3 of these to get 48 outputs, then just use the Propeller itself for the input side of the matrix with 7 I/O pins for the output side and 16 pins for the input side for a total of 23 I/O pins. For that matter, you could do the whole thing with one SX48 and the 74HC154 decoders. You do need a diode for each switch so you can detect multiple switch closures, but these are very cheap (less than one cent a piece in lots of 1000)
  • AHMET AKSUAHMET AKSU Posts: 62
    edited 2007-07-27 15:38
    I m very sorry Mike .I think I couldnt told my mean.in my project every 40 switch must be an independent cell and there are 18 cell but there are distance betwen eachother and prop.and I want that : every cell can know its own state and can make some
    other calculations depend on my proses , run some actuators open and close leds etc.in this side I can see the road.what sx do in the cell.I only want to know that: which is the best bidirectional comunication betwen proppeller and sx.I think 23 I/O pins too much.the comunication line must work in serial style I think price of materials is every time important.but in my project every cell must have its own cpu to make neccessary calculations ,works.I dont know how this 18 slave sx48 comunicate bidirectionaly with one propeller.If you can say something thats will wonder for me .
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-27 15:56
    Some questions for you:
    1) How much information needs to be communicated back and forth between the Propeller and an SX48? How often? How quick a response?

    2) Who's in control? Is the Propeller the "master" or do the SX48s act as "masters"?

    3) The simplest scheme would use an "open-collector" serial bus using a FullDuplexSerial driver with the Propeller sending a polling sequence with the number of the SX48. All the SX48s would be listening and the one recognizing its number would respond with its status. Any information for the SX48 could be sent with the polling sequence. Have a look at the various peripheral devices that Parallax sells for the Stamps like the Parallax Servo Controller, PWMPAL, or the RC-4 relay board. They all use an addressable serial command sequence.
  • AHMET AKSUAHMET AKSU Posts: 62
    edited 2007-07-27 16:15
    Many Thanks Mr Mike Green :

    The slave Sx48 must say to propeller
    1. stop the system
    2 the positions of swithes that generate pulses on last stop
    when a pulse arrived from 40 pieces of switches .the frequancy of stop pulses generated by the swithes is 50 times/hour but
    when this pulse generated machine must stop very quickly.if you say somethink abaut the comunication tis will be good for me
  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-27 16:33
    It sounds like the amount and rate of information from the SX48s is fairly small and infrequent so a polling scheme would work well.

    Again, look at the description of the communications between a Stamp and any of the peripherals I mentioned (download the manual). The Propeller would be in control and it would send a command to each SX48 in turn. The SX48 would send back the status of each of the 40 switches (perhaps 4 switches for each serial character using hexadecimal digits 0-9,A-F in a sequence of 10 characters) and a character that would mean "stop the system" or not.
Sign In or Register to comment.