Skip to main content

Open Loop Control

In this tutorial, we will explore how to run a BLDC motor using open loop control.

Prerequisites

In this tutorial, the following hardware is used:

You need a ST-LINK V2 Clone to upload the firmware to the board. You can purchase a cheap clone ST-LINK V2 under $5.

USB to Serial Adapter

Since the Aotenjo One board doesn't have an USB port, you need a USB to Serial adapter to communicate with the board via serial. In this tutorial, we will use a Blackpill STM32 board as a USB to Serial adapter to communicate with the Aotenjo One board, but you can use a cheap USB to Serial adapter or another STM32 board like the Blackpill as an USB to Serial adapter.

tip

You can use the following development boards as a USB to Serial adapter:

  • BlackPill STM32 board
  • BluePill STM32 board
  • ESP32-DevKitC

USB to Serial Adapter Diagram

If you're not sure how to use the BlackPill STM32 board as a USB to Serial adapter, you can refer to the Serial Communication tutorial.

caution

Make sure your BLDC motor's internal resistance is greater than 10 Ω; otherwise, the board may burn out.

ref. How to measure internal resistance

Installation

VScode with PlatformIO

You can install PlatformIO from the VSCode extension marketplace.

STM32CubeProgrammer

You need this to flash the firmware to the board.

Clone the repository

git clone https://github.com/aotenjo-xyz/one.git
cd one

The example code for the LED blink is located in the examples/openloop directory, so run the following command if you use linux or macOS to copy the example code to the src directory:

rm src/*
cp examples/open_loop/main.cpp src/
cp examples/open_loop/platformio.ini platformio.ini

For Windows, you can copy the files manually.

Quickstart

  1. Connect the Aotenjo One board to the ST-LINK V2 programmer.

    ST-LINK V2 <-> Aotenjo One
    3.3V <---> 3.3V
    GND <---> GND
    SWDIO <---> SWDIO
    SWCLK <---> SWCLK
    RST <---> NRST
    info

    Unlike the blackpill board, you need to connect the NRST pin to the ST-LINK V2 programmer for STM32G4 series.

  2. Connect the ST-LINK V2 programmer to your computer.

  3. Open the project folder in VSCode.

  4. Click on the PlatformIO tab on the left sidebar and click on the Upload button to upload the firmware to the board.

  5. Disconnect the ST-LINK V2 programmer, then connect the power supply and the BlackPill STM32 board to the Aotenjo One board. Finally, connect the BlackPill STM32 board to your computer.

    Power Supply <-> Aotenjo One
    12V <---> VCC
    GND <---> GND

    Aotenjo One <-> Blackpill STM32
    TX <---> PA3 (RX)
    RX <---> PA2 (TX)
    GND <---> GND

    Blackpill STM32 <-> Computer
    USB <---> USB

    Open Loop Control Setup

  6. Click on the PlatformIO tab on the left sidebar and click on the Monitor button to open the serial monitor. PlatformIO Monitor

  7. Turn on the power supply and input the following command in the serial monitor and press enter:

    T1

    Now you should see the motor spinning at a constant velocity. The value T1 represents the target velocity, which you can adjust to control the motor's speed. For example, entering T6.28 sets the target velocity to 6.28 rad/s — meaning the motor completes one full rotation per second. You can also rotate the motor in the opposite direction by entering a negative value, such as T-6.28.

    Serial Monitor Output

    Here is the video demonstration:

    BLDC motor open-loop velocity control

Commander

The code uses SimpleFOC library to control the motor, so you can use the Commander interface to control the motor. Here are some useful commands:

  • T<value>: Set the target velocity (in rad/s)
  • L<value>: Set the target voltage (in V)
  • ?: Get the available commands

If you enter ? in the serial monitor, you will see the list of available commands:

T:target velocity
L:target voltage

You can see the current target velocity by entering T and the current target voltage by entering L in the serial monitor.

References