University project · 2020 · embedded systems

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
Four parallel straight lines of speed against torque for 100, 80, 60 and 30 percent PWM duty, from about 5,260 rpm and 60 millinewton-metres at full duty down to about 1,580 rpm and 18 millinewton-metres at 30 percent
The four speed settings, from the motor's constants: each PWM duty gives a parallel speed–torque line, so each setting has a predictable speed and stall torque.

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 Ω:

T = K_t · (V − K_e · ω) / R V = D · 12 V, D ∈ {100, 80, 60, 30} % no-load speed ω₀ = V / K_e = 550 rad/s (≈ 5,260 rpm) at 12 V stall torque T_s = K_t · V / R = 60 mN·m at 12 V

The PWM timing is set by the clock tree:

PWM clock = 40 MHz system clock / 64 = 625 kHz PWM period = 6,250 counts → 625 kHz / 6,250 = 100 Hz

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.

Skills shown

  • Embedded C
  • Arm Cortex-M4
  • Register-level drivers
  • PWM
  • ADC
  • Interrupts
  • Quadrature encoder (QEI)
  • UART
  • H-bridge motor drive
  • DC motor modelling
  • KiCad schematic