--- title: "STM32 For Beginners [5]: Motors" date: 2024-10-10T00:36:00+03:00 draft: true summary: "..." author: "Rusted Skull" series: ["STM32 For Beginners"] tags: ["Embedded", "STM32"] --- Thus far we've learned very basic ways of making our microcontroller interact with the world: GPIO mostly. But to build a folkrace robot we need a little bit more. Motors, specifically motors with variable speed would help. The most simple motor to use in this scenario is a DC motor, like the [Pololu micro metal gearmotors](https://www.pololu.com/category/60/micro-metal-gearmotors). # Driving DC Motors, Theory To drive a DC motor, we typically use a H-bridge based motor driver. In the case of the Robotics Club course, we are given a [Pololu DRV8835 carrier board](https://www.pololu.com/product/2135) which contains the Texas Instruments DRV8835 dual H-bridge chip. "Dual" in this case means that one board can drive two motors, perfect for a simple differential-drive folkrace robot. {{< figure src="https://a.pololu-files.com/picture/0J4056.1200.jpg" caption="Source: https://wwww.pololu.com" >}} If we look at the "Using the motor driver" section in the "Description" of the carrier board's page, we notice the following diagram: {{< figure src="https://a.pololu-files.com/picture/0J4058.600.png" caption="Source: https://www.pololu.com" >}} The right side is dedicated to the motors, and the left side specifies the input signals expected from the microcontroller. We immediately notice that for this control scheme, the "phase-enabled mode", we need to generate two PWM signals, alongside a few GPIO output signals. Let's look a little closer as PWM now, since that's the missing piece for us.