Electronic – Multiplexing L298N motor drivers

motormultiplexer

I'm working on a project where I need to drive 20 motors with no speed control just running the motors. But I don't have 20 available pins to connect to all the drivers directly. Is it okay to multiplex these drivers with pulling all the GNDs HIGH and all the input pins LOW and then reversing the pins of the needed motor eg. I have to run the row 3 column 4 motor I put the row 3 LOW and column 4 HIGH. Is it a preferred method of doing it or should I choose another method? Sorry for the bad diagram.

enter image description here

Best Answer

Is it okay to multiplex these drivers with pulling all the GNDs HIGH

No! According to the L298 datasheet, input pins must not go more than 0.3 V below ground. Another possible problem is that each motor driver would need its own fully isolated power supply to keep the grounds separate.

If the motor drivers had opto-coupled inputs then you could do it, because the optocoupler provides the required isolation and its input is an LED that only lights up with one polarity. Some L298 motor driver boards have optocouplers built in, but they usually connect them all to a common supply rail so you can't multiplex more that one input independently.

You could add external optocouplers like this:-

schematic

simulate this circuit – Schematic created using CircuitLab

Is it a preferred method of doing it or should I choose another method?

Using a matrix of optocouplers has the advantage of keeping controller ground noise (caused by high motor current) away from sensitive parts of the circuit such as the MCU.

Another method would be to use 1-of-n decoder ICs to convert binary to single outputs, eg. 74HC4514 (you need two of them because each IC only has 16 outputs). This would free up several I/O pins because you only need 5 or 6 pins to control two 1 of 16 decoders. On the minus side you would have to be more careful with routing of ground wires to the motor controllers.

Or you could shift registers such as the 74HC595 (3 required), or an I/O expander IC.