hi, im looking to sample 512 digital input (contact switches) to a computer via serial.
for a previous project i used a midibox with 128 DIN inputs driven by a 74HC165 shift registers.
what sampling speed should i expect when using shift registers and the arduino's ATmega168 (i think i need at least 30Hz), and the whole setup must be sampled ~simultaneously.
will the ftdi serial connection be able to pass this info fast enough?
from a bit of reading (im sure there will be much more of that as this progresses) i understand it better to use a shift register then a multiplex\demultiplex combo. any recommendation of alternatives to the CD4021BE that might be better to use?
more info in this thread, and here is something about an i/o expander.
still looking for an answer. there are many threads on extending i/o and i see some go by i2c.
but for getting 512io i will cross the limit of addresses possible with the i2c address space (128), i've seen a mention of an i2c hub like the PCA9516
from the blurb: While retaining all the operating modes and features of the I2C system, it permits extension of the I C-bus by buffering both the data (SDA) and the clock (SCL) lines, thus enabling five buses of 400 pF.
there is a nice selection of bus buffers for the 2-wire protocol, if there is a market there must be a problem, with interference, noise, cable length etc. any experience there?
another problem i see coming is passing 512 states. sure there is a way to move this fast via serial to pc.
i see there are a lot of threads with bits of info, i would be happy to hear of them.
yair
If they are just contact switches, why would you need a IO for each switch? You can use a matrix. In a simple matrix, 512 buttons would need a 32x16 grid. To scan it, you could use a pair of 74HC154 decoder chips and 6 I/O lines on the rows, and a pair of 74HC165 shift registers and 3 I/O lines on the columns. That's 9 IO and 4 extra chips. The software will be minimally complex and scan times very quick.
If they are just contact switches, why would you need a IO for each switch? You can use a matrix.
This is a very common approach, but it has a big caveat: it can't handle chords well. Chords are when the user is pushing more than one button at the same time. This is especially true of non-momentary switches that stay closed until you open them.
512io i will cross the limit of addresses possible with the i2c address space (128)
That's address space in the I2C NOT a limit in I/O. For example the MCP23016 can handle 16 I/O lines and takes up only one space in the I2C address map.
Admittedly you can only have 8 of these devices on at a time because you only have 3 external address lines but you could switch these address lines in software and therefore address an unlimited number of them.
Use SPI instead of I2C for your IO expanders and solve the addressing problem. You can have one SPI for each arduino digital output with no effort. If that's not enough, use a demultiplexer to switch n2 IO expanders with n digital lines from the arduino. a 4-to-16 demux could switch 15 IO expanders for 15*16=240 inputs. (only 15, because one demux output will select nothing, leaving the SPI bus inactive for some other devices.)
You can even get a bit recursive, and use another IO expander to select the CS line of the IO expander, or one more step, use an IO expander to drive a demux to select the IO expander.
If you can deal with tight SMT stuff, the MAX7301AAX has 28 ports and an SPI interface.
I think you were quoting me and no that is just the limit of address space not a physical limit. If you change the addressing sachem by multiplexing the address lines the limit then becomes how many physical devices you can drive. This then can be expanded by extra bus drivers.
I was under the impression that SPI required an address line from the host to each external -- so the first device would take 3 lines, the fourth would use another, the fifth another, and so on? I thought with i2c it was always 2 wires (+ gnd?) and they were addressable to 127 units?
That's address space in the I2C NOT a limit in I/O. For example the MCP23016 can handle 16 I/O lines and takes up only one space in the I2C address map.
i didnt think searching for an I2c i/o expander. thank you
Admittedly you can only have 8 of these devices on at a time because you only have 3 external address lines but you could switch these address lines in software and therefore address an unlimited number of them.
so basically i can connect 128 MCP23016 devices but only address 8 at a time. the rest are not reachable until i switch one of the legel address to them..
i2c protocol still alludes me. i will try going deeper
still not sure at what rate i can a pull data of it.
the datasheet states :
"The .. bit controls the sampling frequency.... If this bit is '0' (default), the maximum time to detect the activity on the port is 32 ms (max.)... If this bit is '1', the maximum time to detect activity on the port is 200 µsec. (max.)"
but im not sure as to how this relates to a complete design
maybe i will find a clever matrix circuit that allow for reverse polarity, this will surly help with cords.
I was under the impression that SPI required an address line from the host to each external -- so the first device would take 3 lines, the fourth would use another, the fifth another, and so on?
That is correct, but as I said, you can use 4 ATmega digital pins to drive a 4-to-16 demux and select one of 16 SPI devices.
I thought with i2c it was always 2 wires (+ gnd?)
correct.
and they were addressable to 127 units?
I think the standard specifies 121. It is a 7 bit address, but some of them are reserved.
The problem gets to be that the peripheral manufacturers don' think about you using 121 of them on the same bus, so they allow for very few (most I've seen is 3) pins to allow you to change part of the address.
Has someone mentioned using ATmegas as I2C IO peripherals? That's 18 inputs, 2 I2C lines. Since you'll write the peripheral software you can set the address to any valid I2C address, getting your full 121 peripherals.
If this bit is '1', the maximum time to detect activity on the port is 200 µsec. (max.)"
but im not sure as to how this relates to a complete design
The great advantage of this chip is that you don't have to continually read it to see if any input has changes. It has an output that goes high if any of the 16 inputs has changed state. This can be fed to a normal PIN input of the Arduino and quickly read. The chip has two modes for this line, fast response and slow response. You get payback for the slow response in the form of low standby power. I assume you will be more interested in in a quick response than low power.