24bit GPIO expander [xpost from /r/nicechips]
I'm working on a project which has lots of pots, switches and indicators in 60 different modules. These modules have approximately 20 objects. So instead of using MCU's on every module; I thought, if I use GPIO expander on every module and a main MCU board I would get rid of MCU cost and/or cable complexity.
TI has good offerings for this purpose but they are using I2C and it lets you change only 3 bits of I2C address which provides you maximum 8 devices on a I2C bus(I need at least 60).
So which GPIO expander would you recommend? Or what would be the best way to accomplish this project.
Thanks
Edit: Here is the thread in /r/nicechips
4
u/slide_potentiometer Feb 12 '14
If you're throwing 60 devices on an I2C bus you may run into issues with load capacitance and drive strength of the devices, and depending on the latency requirements you may run into bus contention as well.
Some I2C repeaters have enable inputs, allowing you to switch devices on and off the bus, which would take care of address contention. However, this results in times when you can't poll some of your modules.
Some questions: Do your modules need to be hot-swappable, or is the configuration fixed? How many inputs and outputs do you expect to see at once- will the end-user control several switches/pots simultaneously, or expect to see outputs in real time?
The first application that comes to my mind that would require 60+ pots is a mixing board for a recording studio. This application may call for a large number of simultaneous real-time input/output, with I/O latency being critical.
Some math: if you need a device to be responsive in ~30ms (a medium-responsive 1/30 of a second), your entire polling cycle per module must be within 500 microseconds (30 ms / 60). Shortening the response time proportionally decreases this required time. User interfaces require a low response time like this to avoid feeling sluggish and laggy.
If you break up your 60 modules into e.g. 4 bus groups of 15 then you get 4x the time per module on the bus to complete a polling/update cycle (and only need 4 address bits).
Figure out how much data each module needs to exchange and your bus overhead, because you may need to run this bus very fast to keep things responsive.
1
u/sfaunl Feb 12 '14
Latency is not that critical. But as you said, it needs to be within acceptable response times to avoid lag on interface.
Modules are going to be hot-swappable to make future updates easy. So all switches are going to be read from a computer software and this software will decide how to set the indicators.
Thanks for warning about capacitance. I think, I won't have problems with capacitance because modules are not far from each other. But it needs to be taken care of the right way.
3
u/cypherpunks Feb 12 '14
Consider just programming a small microcontroller as a port expander. It's a smidgen slower, but you can use all possible I2C addresses, and include more complex features (like unattended blinking).
The trick is, don't get fancy. If you just program it to behave like a simple register-addressed slave, the firmware won't be complex.
1
u/sfaunl Feb 12 '14 edited Feb 12 '14
Thanks for the tips :)
And yes, after searching for a while, it seems using a small microcontroller is much more suitable for this purpose. Also it gives the ability to read potentiometers directly.
Besides an I2C expander which suits in my project starts from 3 dollars each. And if I use an MCU from STM32 F1 series, price goes as low as 1.5 dollars.
2
Feb 11 '14
It would take a bit of RTL, but you could use a CPLD for this. You could have them connected to the MCU via I2C. Since it is programmable you could have as many bits of address as you want.
There's an example from Altera here.
1
u/sfaunl Feb 11 '14
It would be great but wouldn't it cost much more? Money, effort and time wise.
2
Feb 11 '14
I don't think it would be that expensive, but it does cost more time I guess since you need to program it.
2
u/fruitcup729again Feb 11 '14
NXP has a lot of i2c parts: http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_general_purpose_i_o/#products
The PCA9501 has 6 address inputs, but only 8 I/O. I didn't look over the whole list of products to see if there was something that fit your needs better.
Another option would be an i2c mux, like the PCA9547. It is an 8 channel mux so you can duplicate your i2c addresses 8 times behind each. And you can have 8 muxes on the bus.
1
u/sfaunl Feb 11 '14 edited Feb 11 '14
PCA9505/06 looks promising with its 40 IO, but again it has 3 address inputs.
I2C mux sounds reasonable. If I use it with NXP PCA9505 or TI TCA6424A, then I can connect 64 devices on a single bus.
4
u/anne-nonymous Feb 11 '14
Mcu's can be cheaper than io expanders. For example you can get a numicro mcu with 30 io for 62 cents.it also comes with an arduino like environment called coocox .
6
u/ArtistEngineer Feb 11 '14 edited Feb 11 '14
I've found that, in many cases, a microcontroller is either cheaper or more useful than a GPIO expander.
e.g the ATmega48 is USD$1.58750 (100+). It's nowhere near the smallest and simplest, but it does support most digital protocols natively. e.g. I2C, SPI, UART.
http://www.digikey.com/product-detail/en/ATMEGA48-20AU/ATMEGA48-20AU-ND/739775
If all you need is simple button inputs, you can use shift registers to clock in the data. But if you need a mixture of IO, PWM and analog, then you might as well throw a microcontroller at the problem.