Motor controllers

  1. BMSBattery S series
    1. BMSBattery S06S
      1. S06ST (torque sensor version)
      2. S06S-BL (Bluetooth version)
      3. PWM signals
        1. very low speed - 6 steps
        2. low speed up to max speed - sineware
      4. Phase B current signal
      5. Throttle
    2. BMSBattery S06SC
    3. BMSBattery S12S
      1. Programming header
      2. PWM signal at max speed - sineware
      3. Phase B and motor total current signals
    4. BMSBattery bottle battery controller
    5. LCD control panel
      1. LCD protocol
    6. Kunteng mobile app
    7. Bluetooh
      1. DIY Bluetooth module
    8. How to open the controller and solder the programming header
    9. Hardware mods
  2. Other controllers
    1. BMSBattery S06P
      1. various info
        1. 01
        2. 02
    2. Kunteng 18 mosfets motor controller
    3. Lishui motor controllers
      1. LSW-675
        1. Datasheets
        2. PWM signals
    4. JinHui motor controllers
  3. GreenEBikeKit


  1. BMSBattery Q75
  2. BMSBattery Q85
  3. BMSBattery Q100
  4. BMSBattery Q100C
  5. Tongsheng TSDZx mid drive motors

Development tools

  1. Linux
    1. Step-by-step tutorial development tools
      1. Hardware tools to flash and debug the firmware
      2. Tools to build the firmware
        1. stm8-binutils-gdb
      3. Tools to flash the firmware
        1. How to erase and unlock protected read memory
      4. (optional) Tools to debug the firmware
      5. (optional) Tools to debug using serial port
      6. (optional) Tools to see diffs on the source code
  2. Windows
  3. C library
  4. Other tools
    1. Battery voltage boost step-up converter

Motor control

  1. Torque speed
  2. Motor control scheme of S06S controller
  3. BLDC 6 steps
  4. PWM schemes
    1. So, Which PWM Technique is Best? (Part 1)
    2. So, Which PWM Technique is Best? (Part 2)
    3. So, Which PWM Technique is Best? (Part 3)
    4. So, Which PWM Technique is Best? (Part 4)
    5. So, Which PWM Technique is Best? (Part 5)
    6. So, Which PWM Technique is Best? (Part 6)
    7. So, Which PWM Technique is Best? (Part 7)
  5. PWM control and Dead Time Insertion
  6. Low inductance motors
  7. Throttle Control Modes
  8. Phase angle FOC
  9. PWM frequency VS motor eRPM
    1. Max motor speed using FOC
    2. Kelly controllers ultra high speed
  10. Sinusoidal Control of BLDCM with Hall Sensors Based
  11. Self-Learn Hall Sensor Calibration Mode
  12. STM8S105 Alternatives
  13. PID algorithm - negative output values
  14. Regeneration
    1. Regen in SimonK firmware
  15. FOC
    1. Shane Colton documentation and firmware
      1. Firmware
      2. Part 1: Field-Oriented
      3. Part 2: Field-Oriented
      4. Sensorless Pneu Scooter - part 1
      5. Sensorless Pneu Scooter - part 2
      6. Sensorless Pneu Scooter - part 3
      7. Observer
        1. Sensorless - 2011.04.10
        2. Sensorless - 2011.07.05

Datasheets and application notes

  1. STM8S105C6T6
    1. Interrupts
  2. forum messages
    1. 2017.04.25 - Initial forum message
    2. 2017.05.08 - First flash and debug on a dev board
    3. 2017.05.18 - First code flashing and running
    4. 2017.05.20 - more new information
    5. 2017.08.23 - SxxP versus SxxS versus LSW-675
    6. 2017.09.01 - Trying to figure out an algorithm to automatically adjust ui8_position_correction_value
    7. 2017.09.02 - How to do FOC on the BMSBattery S06S/Kunteng STM8 motor controllers
    8. 2017.09.03 - more ideas about zero crossing for FOC
    9. 2017.09.05 - measuring IQ current and manually adjusting position_correction_value
    10. 2017.09.15 - our OpenSource firmware efficiency compared to Lishui 12 FET FOC
    11. 2017.09.19 - measuring motor current
    12. 2017.10.23 - FOC and no FOC comparison
    13. 2018.01.10 - How to measure FOC_READ_ID_CURRENT_ANGLE_ADJUST
    14. 2018.02.20 - Reading motor phase current from the DC link current (shunt)

Torque sensors

  1. BMSBattery torque sensor


  1. STM8S003 board
  2. 2017.12.01 - Regen ebrake like coast brakes
  3. BEMF


  1. 2017.05.22 - Hackaday Links: May 21, 2017

Smart BMS with bluetooth

PWM control and Dead Time Insertion

PWM control and Dead Time Insertion

A project log for Gator Quad
Personal project to develop a quad copter using as much self designed circuitry and software as possible.
images/51-1.pngridonkulus • 12/09/2014 at 15:45•1 Comment So as is often the case I vastly overestimated my knowledge on a few subjects. In my last post on this project I had successfully designed and put together my physical motor driver. This meant that all I really needed to do to get the motor spinning was fire up some pwm signals on my micro and done, right!? Well I was wrong. There were two fundamental gaps in my knowledge on BLDC control that I did not know I was lacking in until I attempted to start writing the code to control a motor. The first of the two being the PWM control scheme. There are 4 main variants of PWM control schemes for a 3 phase BLDC controller. I originally was just under the naive impression that there was one standard way to perform the functionality, and was no so surprised to find that "there is more than one way to skin a cat." The second area of knowledge that I did not know too much about, and was only vaguely aware of is the practice of dead-time insertion (DTI). The main goal of DTI is to avoid a short circuit from the high side of the DC Bus to ground through the two transistors that control a single phase. This can happen because switching on and off transistors just like anything else is not instantaneous and some overlap may occur. DTI is guaranteed off time to ensure that no overlap happens. I knew that DTI was necessary I just had no idea how much was needed or how to go about implementing it. I had to do a bit of research before being able to answer either of those questions.
Trying to avoid this....

click me
Blown Transistor

This post will hopefully allow me to re-enforce what I learned and maybe teach others about these two subjects as well.

PWM Control Schemes

In a previous post I explained some BLDC motor basics and a few fundamentals of controlling one. I only briefly talked about speed regulation (see "Regulation Methods:") and did not go into much detail beyond what PWM is. Here I plan to expand on the concept some more pertaining to controlling BLDC motors.
Speed in a BLDC motor is directly proportional to the voltage applied to the stator. The speed at which the actual rotor is forced to the next position is determined by the strength of an applied magnetic force, and this is determined by the voltage applied to the stator windings. By using PWMs at a higher frequency than the commutations, the amount of voltage applied to the stator can be easily controlled, therefore the speed of the motor can be controlled.
A typical six-step PWM controller uses one of two PWM techniques:
1. Unipolar PWM switching - This technique refers to motor phases being switched in such a way that one of the phases returns current while the PWM modulation is happening in another phase, this is unipolar.
2. Bipolar PWM switching - This technique refers to the voltage passing through the two phases as being modulated with the PWM, both the input and output of current are being modulated.
Unipolar and bipolar approaches refer to the relationship of the two phases being switched.
Unipolar and bipolar switching have specific advantages. Unipolar switching reduces electromagnetic noise and the DC bus ripple because there is less switching. Bipolar switching is better suited for sensorless approaches where it is necessary to sense back electromagnetic forces (BEMF). The bipolar approach has the zero volt point at a 50% duty cycle, therefore there is more time to sense the BEMF.
Both unipolar and bipolar approaches can be either independent or complementary.
1. Independent PWM Mode - the top and bottom switches of a phase are operated independently over a commutation period. If a top switch performs a PWM, the bottom switch is off, and vice versa. In this mode, the drive can operate in two quadrants; again bipolar independent and unipolar independent switching are available.
2. Complementary PWM mode - the top and bottom switches of a phase are operated inversely; if one switch is on, the other is off and vice versa. This mode must be used if four quadrant drive operation is required. This mode needs dead time insertion (DTI) between the top and bottom switches to avoid any phase short-circuit, this will be explained more later. Unipolar complementary switching leads to lower switching losses and current ripple. However, from a back-EMF "sensorless" perspective, the bipolar complementary switching is the better choice as explained above.
The complementary or independent approaches refer to the relationship of the two signals controlling one of the phases.
The independent approach applies to the PWM only on one side of the phase. The complementary approach modulates both sides of an individual phase. The complementary and independent approaches allow the control to address either a 2 or 4-quadrant operation as shown in the below figure.

click me
Four Quadrants of Motor Opperation

With all of this in mind this leaves us with 4 basic PWM control techniques overall. I will attempt to summarize them in this PDF file and the below graphics.

click me
Click image to expand - Or download PDF from above

In my application I will use uni-polar complementary PWM switching. This will allow me in the future to use all 4 quadrants if I so desire. Since I am not using Back-EMF sensing I will not need the added benefits of Bi-Polar Complementary for that application; in addition I will have half the harmonic content and DC bus ripple. Below is one full electrical rotation with uni-polar complementary PWM switching.

Dead Time Insertion (DTI)

As you can see from the above image, either of the "Complementary" switching approaches require a guarantee that there will be no "shared" on time creating a short circuit from power to ground. This effect, even for short a duration causes large current spikes, which increases thermal output, and when switching a few thousand times a second quickly wears out the MOSFET. Worst case you blow up your whole circuit. There are again a few different approaches to how to tackle this problem so I will quickly try to lay out some of the common ones. I want to thank my friends from for helping me through a few of the different options.
1. One option is to use RCD delay circuits (resistor in parallel with a diode, feeding a capacitor hooked to the input of your gate driver). This circuit will delay turn on of your switch but not turn off so you'll have deadtime inserted in hardware. This method is a little imprecise due to variances in resistor values and capacitor values.
2. Another common option is using an MCU with a PWM peripheral that has integrated dead time. This is usually easily configured by a few registers and eats up very few clock cycles. This is a great solution for applications with a lot of H-Bridges. Only disadvantage is this requires a specific subset of MCU's. Here is an example of one.
3. A third commonly used solution is to insert a dedicated DTI Integrated circuit between the PWM control signals and the gate driver. Some chips themselves are the gate driver, some take one PWM in and split it into the two complementary signals, while others take two independent signals. Some take digital commands to adjust the deadtime, and some have fixed deadtimes. Point is there are a lot of different types so you need to make sure you know what you are getting. Here is an example of ONE type of DTI IC.
4. A fourth solution is to know your MCU's clock speed, and count the number of clock cycles to interject the appropriate amount of deadtime. In common single core MCU architectures you can use up-down counting and add half the deadtime to the compare register for the high side switch, and subtract from the compare register for the low side switch (or vice versa if you're using negative logic). Or in my case with the xMOS MCU timing is much more precise and you can specify exactly how many clock cycles you want to wait before toggling a pin.
I will be going with the 4th approach because my MCU gives me great flexibility in implementing that solution. However I need to know exactly how much deadtime I will need. This required a little bit of digging, reading, and crunching numbers. I found a lot of the information that was needed from these two online articles ( One , Two ). Please feel free review their, and my work to ensure that the math makes sense. I am trying to keep all of my equations in one spreadsheet located here. Below I will try to elaborate some on the process.
Explanation:In the most basic of terms, a MOSFET is limited in it's speed to switch on and off by the ammount of time that it takes to charge and discharge the small ammount capacitance found in its structure. This charge and capacitance information is usually found in the MOSFET data sheet under the "Dynamic Characteristics". Here is my MOSFET. As you probably know a MOSFET turns "ON" once the voltage between the gate and source rises above it's threshold voltage (Vth) or turns "OFF" once it goes below. The below images show the gate to source voltage (Vgs) as a function of time and the following image shows how that is directly related to MOSFET's gate charge.

click me
Gate to Source Voltage Charging and Discharging


click me
Vgs as a function of Gate Charge

Once we understand what is happening in a MOSFET when it is charging and discharging, we can begin to create a model that will allow us to best estimate those turn-on and turn-off times. Once we have a "worst case" scenario for how long it will take one transistor to turn on and the other to turn off, we will know the absolute minimum deadtime that will be needed to ensure safe operation. The below image shows a simplified gate drive circuit and is used as the base model for calculating the needed deatime.

click me
Simplified Gate Drive Circuit

Calculations:In order to successfully calculate the deadtime I needed info from my MOSFET's data sheet as well as had to make a few assumptions based on ballpark figures I gained from the above articles and reading other sources on the internet. I estimated the Sink Resistance of my Gate Driver to be 2 ohms as in article One from above. I did not find that value in my drivers spec sheet. I also estimated inductance of the PCB trace to be 20nH like the above article, as I figured this to be a reasonable assumption and that parameter does not have to much affect on the results of the below equations.

click me
Mosfet values from specsheet

The selection of the series external resistance (Rext) and the pull down safety resistor were discussed in this blog post.

click me
Additional gate driver values


click me
Gate Driver IC parameters and a few circuit specs

Again reviewing the standard discharge curve for a MOSFET and looking at our circuit model from above we can come up with the following equations. I highly recommend that you read over article One, and Two from above to fully grasp the concept for yourself.

click me
Vgs Discharge Curve


click me
Description of Discharge Time segments


click me
Necessary deadtime equations

The following are my results for the 6 equations. The last value being the one that I am after. ~ 142 ns of required deadtime. Since a lot of the above calculations were estimations and the fact that I am going to be working with a crudely put together proto-board I am going to start off with more than double the minimum deadtime at 300ns.

click me
Equation Results

With my micro-controller running at 100Mhz base clock I will only need to inject 30 clock cycles on each side of the PWM waveform to achieve the necessary deadtime. In my next post I will show you exactly how I accomplished that.
Wikipedia Articles• H Bridge
N-Type Only H Bridge configurations
Power MOSFET's
Gate Drivers
PWM for power delivery
Microcontroller Unit (MCU)
Web Articles / Published papers• Senorless BLDC control setup with explanation on PWM schemes
Sensored BLDC control setup with explanation on PWM schemes
See section 3.5. Methods based on PWM strategies
See section 2.1.3 Controlling speed and torque
Graphic of different PWM schemes
Deadtime calculation for mosfet driven h-bridge application (Article One)
Understanding Gate Charge parameters for MOSFETS and IGBT's (Article Two)