gneidermeier / stm8_mcp

Open-source brushless motor control firmware on STM8s microcontrollers.
Apache License 2.0
6 stars 5 forks source link

Introduction

This is a minimalistic implementation of a brushless DC motor driver on STM8 microcontrollers. It is presently limited to the small (1100kv) brushless outrunners such as seen on cheap drones and RC planes.

The software drives the motor by applying the 6-step (trapezoidal) drive sequence. Motor synchronization is to be accomplished by using the motor back-EMF waveform sampled by the ADC (analog digital converter) input to the STM8.

Obtaining and installing development environment

Presently the de-facto toolchain is ST Visual Develop with COSMIC C compiler - these tools have free licenses, but are available for Windows OS only.

sdcc (available for multiple OS) may be supported at some point and eventually transition to patched for use with SDCC as that one has all C files split into one function per file (SDCC linker unable to perform dead code elimination?)

Download IDE and compiler toolchain:

Working with stm8_mcp project source code

Installing STSW-STM8069 STM8S/A Standard peripheral library

Cloning source code from github:

Select the active project:

Selecting the active project sets the platform by inserting the compiler define '-dS105_DEV' into the compile command.

Note on installation/configuration of SPL:

The stm8_mcp project was copied from the SPL template V2.3.0. (STM8S_StdPeriph_Lib/Project/STM8S_StdPeriph_Template).

As in the template project, the location of the SPL source files is set in the stm_mcp project as a relative path. The SPL library files are kept external to the stm_mcp project and not distributed with it, thus the requirement to download it separately.

If creating a new project and not a copy of the template, be sure to setup the toolchain in STVD:

Running the controller with a motor

The critical component of the hardware is the 3-phase driver circuit. The 3-phase driver circuit is implemented in large part by the [IR2104 half-bridge IC] (https://www.infineon.com/dgdl/Infineon-IR2104-DS-v01_00-EN.pdf?fileId=5546d462533600a4015355c7c1c31671). Most variations of the this kind of circuit use an [N channel MOSFET] (https://www.infineon.com/dgdl/irfz44npbf.pdf?fileId=5546d462533600a40153563b3a9f220d) for both the high-side as well as low-side of the half-bridge. The IR2104 incorporates a built-in charge pump for driving the high-side (Vgs of HS going to be significantly higher than Vbat).

Reference project implements the controller with an Arduino Uno, which has the additional capability of the input comparator. This provides a means for detecting zero-crossing point and thus direct measurement of motor timing.

Connecting a motor can cause the potential for more dramatic failure scenario so do it at your own risk to your dev board and equipment!

The following equipment is suggested:

Build Documentation

The project documentation is generated from Doxygenized comments in the code and supplemented by diagrams generated from markup by PlantUML. GitHub pages is set to serve from a gh-pages branch of the project repo - Documentation link.

GitHub now provides option for Simpler GitHub Pages publishing which could be considered.

Prerequisites:

To build the documentation:

  1. Open the Command Prompt (or alternatively, Power Shell) in Windows and execute the command cd <project_root> to navigate into the project root directory.
  2. In a Windows Command Prompt run doxygen from the root of the project root directory and capture the output to a text file: doxygen docs\config\doxyfile.cfg 2>&1 > doxygen.log

The documentation is generated under the <project_root>/build directory. Open <project_root>/build/html/index.html to view the HTML documentation.

Update documentation on GitHub pages

In a separate project directory, create a clone of the project repo in which to checkout the gh-pages https://github.com/gneidermeier/stm8_mcp/tree/gh-pages.

In the gh-pages clone-repo, create an orphan branch 'gh-pages' - (I needed [help with this] https://stackoverflow.com/questions/48235671/deploy-project-to-gh-pages-from-a-git-clone).

Replace all of the contents in the docs/ directory of the gh-pages branch with the contents of <project_root>/build/html in the build branch. Execute the commands shown below in an appropriate shell environment (e.g. Linux, Git Bash or Cygwin) to deploy the docs in gh-pages:

cd /path/to/my/clone_clone_of_gh-pages
git checkout --orphan gh-pages
git rm -rf .
rm '.gitignore'
echo "#Project gh-pages site" > README.md
cp -r `<project_root>/build/html/* docs/
git add docs/
git commit -a -m "Initial Commit"
git push -u origin gh-pages

If there is any conflicts with the gh-pages branch, it is easy to delete a branch (e.g. on github web) and the commands above will then work to regenerate the branch.