Embedded DC Motor Drive for a Drill
A fourth-year embedded-systems project: speed and direction control of a brushed DC motor for a power drill, taken from concept to a working prototype. The firmware is written in C directly against the registers of an Arm Cortex-M4 (TM4C123), with no vendor driver library.
- Team
- Three students
- MCU
- TM4C123GH6PM, Cortex-M4
- Drive
- H-bridge, 100 Hz PWM
- Firmware
- C, register-level
The problem
A drill needs a handful of fixed speed and torque settings, matched to different screws and surfaces, and it has to run in both directions. The brief was to build that controller as an embedded system from scratch: choose the drive scheme, wire the electronics, and write the firmware for a microcontroller without hiding behind a driver library.
Approach
- A small state machine. One push-button enables rotation, a second reverses direction on an interrupt, a 4-way DIP switch selects one of four speed steps, and two LEDs show the state.
- PWM instead of a linear voltage. Switching the supply at a set duty cycle gives an average voltage D·Vs without the continuous loss of a linear regulator.
- An H-bridge for direction. Clockwise drives the S1/S4 diagonal with PWM, anticlockwise drives S2/S3, using two PWM channels into the bridge.
- Register-level peripherals. Clocks, GPIO, interrupts, the PWM generators, an ADC sample sequencer (reading the DIP switch, to exercise the ADC), the quadrature-encoder interface and a UART link to a PC for debugging and commands were all set up with bitwise register writes from the datasheet.
The numbers behind it
Each speed step comes from the steady-state DC motor model, using the motor's constants Kt = Ke = 0.0218 N·m/A and R = 4.33 Ω:
The PWM timing is set by the clock tree:
Results
- 4quantised speed / torque steps, like a drill's clutch settings
- 100 HzPWM into the H-bridge from register-configured generators
- 2directions, reversed by an interrupt-driven switch
- 0vendor driver libraries: every peripheral set up from the datasheet
What worked and what didn't
The demo met the core brief: enable and reverse from the on-board switches, four selectable speeds, LED state indication and a UART link to the PC. The encoder speed measurement did not work reliably: the motor came with only a mechanical drawing and no electrical data for its encoder channels, so the expected signal had to be inferred.