3
\$\begingroup\$

I'm working on a project in which I need 32 outputs from an MCU that only has 8 free outputs.

To accomplish my goal I have the following requirements:

  • I must be able to toggle more than one output at the same time

  • Data must come in as fast as possible

  • I cannot lose data packets

  • The data should be transferred in a reliable way

I though about using a 4-16 Decoder, but I cannot switch more than one output at the same time with it.

I can use I2C communication to expand my IOs pins, but I'm not sure if I'll have issues with timing and data packets.

One possibility is to use multiplexing.

I'm using a AM3359 ARM Cortex-A8 @ 25Mhz

Any other ideas?

\$\endgroup\$
  • \$\begingroup\$ Do you have to use any specific data protocol? Although you have to toggle more than one output at the same time, do you need be able to toggle ALL outputs at the same time (i.e. is there a max number of synchronous outputs)? \$\endgroup\$ – gbmhunter Dec 5 '13 at 20:20
  • \$\begingroup\$ You say you need 32 outputs but that data must "come in" as fast as possible. What does that mean? Saying "as fast as possible" is nonsense...what is your real requirement? \$\endgroup\$ – Joe Hass Dec 5 '13 at 23:53
  • \$\begingroup\$ @JoeHass Its that I need speed to toogle the output, I need do everything in less than 1us for example. The time that I set the GPIO in the uC into the time that final output reach that state. \$\endgroup\$ – Butzke Dec 6 '13 at 1:11
  • \$\begingroup\$ @gbmhunterI don't have to use a specific protocol. I can use some SPI or I2C. The outputs that I can toggle at the same time is random, so I can toggle just one or two at the same time, as I can toggle all the outputs at the same time. \$\endgroup\$ – Butzke Dec 6 '13 at 1:19
  • 1
    \$\begingroup\$ @pjc50 - I have to use this MCU, not other choise. Its a AM3359 ARM Cortex-A8, but I only have 8 free outputs to use on it. \$\endgroup\$ – Butzke Dec 12 '13 at 16:52
4
\$\begingroup\$

I2C operates at 100kHz, 400kHz, 1MHz, and 3.4MHz standard. Many i2c expanders can do what you need, both input and output. And it has acknowledgement bits, so you know (kindof) if a expander received the data packet.

Without knowing you exact data rate requirements, can't be sure, but i2c expanders are as good as any other type.

Update: Since you have mentioned 1MHz and a 25MHz mcu, the Microchip MCP23009 3.4MHz 8bit I2C expander could work. Up to 8 can be used on a single bus using a voltage divider on the address pin. The MCP23018 is the 16 bit version, so you only need 2 (and could sample them if needed).

Alternatively, there are SPI expanders that can go up to 10MHz. The MCP23009/18 can do both I2C at 3.4MHz and SPI at 10MHz, so you can test both to see what suits you best.

\$\endgroup\$
  • \$\begingroup\$ @butzke updated \$\endgroup\$ – Passerby Dec 12 '13 at 18:07
6
\$\begingroup\$

A common approach is to use a chain of 74HC595 or similar serial-in-parallel-out shift-register chips, and drive the chain using the clock-output and MOSI wires of an SPI port as well as one "ordinary" I/O pin. The SPI clock-output pin should connect to the shift-clock input of every shift register, and the ordinary I/O pin should connect to the register-clock input of every shifter. One shifter should have its data-in connected to MOSI; a second shifter should have its data-in connected to the data-out from the first. If there's a third shifter, its data-in should be connected to the data-out from the second, etc.

Using this approach, three processor pins can connect to any number of shift-register chips which collectively control any number of pins. To set the outputs, send to the SPI port the data which are supposed to go in all the shifters, sending the data for the shifter that's furthest away from the processor first. Once all the data have been sent, pulsing the register-clock pin high and then low will cause all of the shift register outputs to change simultaneously. One may change as many or as few outputs as desired on each step; the only factor limiting the number of outputs one may control is the need to respecify the state of every output any time one wishes to change any of them.

If you only need certain groups of outputs to be able to change simultaneously, it may be helpful to have multiple independent shift-register chains. All of the chains can share the clock-output and MOSI pins (using one register-clock output per chain) if one ensures that once code starts shifting data to a chain, all the data for that chain will be sent and strobed before the SPI bus is used for anything else. If one has 240 outputs which need to change occasionally and 16 that need to change somewhat more often, giving the chips controlling 16 frequently-changing outputs their own register-clock pin will mean that changing those pins will only require sending two bytes out the SPI rather than 32.

\$\endgroup\$
2
\$\begingroup\$

As @passerby say, I2C is the easiest protocol, one line for data and another for clock, you can make it by sodtware and I think that the timing requirements are minimal and as you will only use the expander as outputs there won't be any problem... I think there's no minimum for I2C...

Another idea I thought is to use latches with a decoder to address the bus but with that maximum you can acomplish is 16 outputs.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.