Car MCU and engines commutation - olonho/carkot GitHub Wiki
Car engine activation, rotation speed and direction are controlled by MCU GPIO pins. I've chosen to use GPIO port B for controlling engines. Its pins has the following responsibilities:
- PB4 - enables engine on logical level 1. Disables engine on logical level 0.
- PB5 - sets rotation direction to forward on logical level 1.
- PB6 - sets rotation direction to backward on logical level 1. If PB5 and PB6 have the same logical level at the same time then engine doesn't rotate. To control speed of engines rotation do PWM on PB4.
We can control all the logical things using MCU GPIO pins but this pins can't supply enough power for our engines. I guess MCU would just burn if we connect GPIO pins to the engines. So we need some power source that can be controlled by GPIO pins. This kind of source is called engine driver. We use ST L293D engine driver.
Here is a MCU+L293D+engine commutation scheme. I use this scheme for our cars.
Second engine is added quite easily. You just need to attach controlling GPIO pins to ENABLE2, INPUT3, INPUT4 pins of L293D (right IC on the pic below). L293D pins and MCU GPIO pins are directly connected together so you can easily understand how L293D pins behave if you remember about spec on GPIO pins behavior up here.

Here is how to connect the 2nd engine controlled the same way as the 1st:
- Connect PB4 to L293D pin 9
- Connect L293D pin 7 to L293D pin 15
- Connect L293D pin 2 to L293D pin 10
- Connect engine 2 + pin to L239D pin 11
- Connect engine 2 - pin to L293D pin 14
Also you can add one more battery in serial to the current one. This allows to supply more voltage to the engines and speed them up. Also L293D doesn't apply all the Vs voltage to its outputs. For example if I apply 7.5 Vs then I get 5.6 V on each of 2 engines connected to outputs.
Tutorials about our engine driver commutation that I found helpful. Find additional information here.