Week 13 - Motor Controller

This lab entailed the creation of a motor controller using pulse-width modulation (PWM) to change the speed of a DC-motor.

Circuit

The circuit includes the XIAO ESP32-S3, a small DC motor, one transistor (TIP120), one diode (IN914), two push buttons, one 4.7kΩ resistor, and two 1kΩ resistors (for the buttons). We also used the XIAO expansion board, which allowed us to power the motor using a dedicated LiPo battery, rather than powering it directly from the microcontroller. Our challenge was to use the push buttons to change the motor speed by adjusting the motor's duty cycle via PWM.

Circuit
Messy circuit, but functional

Code

The defining feature of our code was the use of interrupts to handle changes in fan speed. The interrupt routines were instantiated in the setup() function, and allowed us to control the fan speed asynchronously in response to hardware button presses.

Interrupt routines
Interrupt routines

Interrupt instantiation during setup
Interrupt instantiation during setup

Demo:

We had some issues getting the circuit to respond to button presses consistently, and the oscilloscope in the video shows quite a bit of noise in the circuit. This may have been due to defective buttons or loose jumper cables, but you can see the basic functionality of the system in the video below.

Downloads

The code used for our demo can be downloaded here.


More posts

Week 14 - Real-Time Operating System (RTOS)

An introduction to real-time operating systems (RTOS) for embedded systems.

View post

Week 12 - DAC Synthesizer

Creating a synthesizer using a digital-to-analog converter (DAC).

View post