The problem
Most electric two- and three-wheelers in India use BLDC hub motors with Hall sensors and trapezoidal control. Getting commutation timing, dead time, PWM scheme and fault handling right decides efficiency, noise and the safety of the power stage.
Objectives
- Generate complementary PWM with dead time and a break input on TIM1
- Decode Hall sensor states and commutate through a six-step table
- Close a PI speed loop using Hall-period speed measurement
- Compare two PWM schemes on DC-link current ripple and efficiency
What you need
From the EV Embedded Development Kit
- STM32F103C8T6 microcontroller unit (Arm Cortex-M3)
- Analog potentiometer input
- Serial UART interface
- I2C and SPI buses to the onboard devices
- 16×2 LCD
- RGB LEDs and a buzzer
Software
- STM32CubeIDE with HAL TIM (advanced-control timer, Hall sensor interface), ADC, I2C and UART
- Embedded C
- Python with NumPy, pandas and matplotlib
- MATLAB/Simulink (optional) for a BLDC model
Extra parts
- Low-voltage three-phase BLDC driver board (gate driver and six MOSFETs) — The kit's motor driver is for brushed DC; a BLDC needs a three-phase bridge.
- Small low-voltage BLDC motor with Hall sensors — No motor is on the kit, and Hall feedback is needed for six-step commutation.
- Bench power supply with current limit — Powers the three-phase stage separately and limits damage while debugging.
- INA219 I2C current/power monitor — Current measurement is not on the kit; it measures DC-link current and power for ripple and efficiency comparisons.
Key concepts
- Six-step commutation
- At any time two phases conduct and one floats; the three Hall signals give six valid states, each mapped to one pair of switches.
- Complementary PWM and dead time
- TIM1 drives high and low switches of a leg with complementary outputs and inserts dead time through the BDTR register so both never conduct at once.
- Hall sensor interface
- A general-purpose STM32 timer can XOR the three Hall inputs and capture the time between edges, giving speed with no CPU polling.
- PWM schemes
- In H_PWM-L_ON only the high switch is chopped, while in H_PWM-L_PWM both are, which changes current ripple, switching losses and freewheeling paths.
Step-by-step guide
- 1
Model and requirements
Build a simple BLDC model with phase resistance, inductance, back-EMF constant, pole pairs and rotor inertia, taken from the motor datasheet or from simple tests such as measuring resistance and spinning the motor to read back-EMF. Simulate six-step control in Simulink or Python. Set targets for the hardware: the speed range, steady-state speed error under 2%, and a bench-supply current limit that protects the driver board. These targets anchor the later comparisons.
Checkpoint: A simulation showing speed response and an expected current waveform.
- 2
Wire the power stage safely
Connect the driver board's six gate inputs, enable and fault pins to the kit headers. Check the kit schematic for which TIM1 pins are free, such as PA8 to PA10 and PB13 to PB15, and use the DIP switches to disconnect any kit block sharing those pins. Join the grounds of the kit and the driver board. Power the bridge from the bench supply with a low current limit and no motor connected at first, and keep a written wiring table.
Checkpoint: A wiring table and photos; with the bridge powered, idle current is near zero.
- 3
Complementary PWM with dead time
Configure TIM1 in centre-aligned mode at 20 kHz with channels 1 to 3 and their complementary outputs. Set the dead time in the BDTR register to suit your MOSFETs and gate driver, using the datasheet switching times with margin, and enable the break input tied to the driver board's fault output. Start the outputs with HAL_TIM_PWM_Start and HAL_TIMEx_PWMN_Start. Check every pair on the oscilloscope with the bridge unpowered before applying power.
Checkpoint: An oscilloscope shows complementary signals with the configured dead time and outputs go safe when break is asserted.
- 4
Hall decoding
Read the three Hall inputs either through the timer's Hall sensor interface, which XORs them and captures the time between edges, or through EXTI interrupts on each edge. Form a 3-bit state from the three pins. Rotate the motor slowly by hand and record the sequence of states, comparing it with the motor datasheet. Treat states 000 and 111 as faults, since correctly placed sensors never produce them, and note any glitches near transitions.
Checkpoint: Rotating the motor slowly gives the six-state sequence in the order the datasheet specifies.
- 5
Commutation table
Write a table that maps each valid Hall state to which leg is switched with PWM, which leg is held low and which floats, with one table per direction. On each Hall edge, update the timer outputs by enabling and disabling channels through the CCER bits or the HAL calls, keeping the interrupt short. Start at a low fixed duty with the current limit set low, and check the motor spins smoothly both ways before going faster.
Checkpoint: At a low fixed duty, the motor spins smoothly in both directions and current stays within limit.
- 6
Speed measurement and PI loop
Measure the time between Hall edges with the timer capture to get electrical speed, divide by pole pairs for mechanical speed, and add a timeout that reports zero speed at standstill. Close a PI speed loop at 1 kHz that sets the PWM duty, with output limits and anti-windup, and use the potentiometer as the speed set-point. Record step responses and compare the measured speed error with the 2% target and with your simulation.
Checkpoint: Step responses meet the speed error target in steady state.
- 7
Protection
Add the protections a real drive needs: over-current cut-off using the INA219 DC-link reading, stall detection when no Hall edge arrives for a set time while duty is high, shutdown on an invalid Hall state, and immediate output disable through the break input. Show the fault cause on the LCD and signal it with the RGB LED and buzzer. Test each protection deliberately, for example by holding the rotor at low duty.
Checkpoint: Blocking the rotor by hand at low duty triggers stall shutdown within the set time.
- 8
Compare PWM schemes
Implement two switching schemes: H_PWM-L_ON, where only the high-side switch is chopped, and H_PWM-L_PWM, where both switches of the active pair are chopped. Run both at the same three speeds and the same load. Log DC-link voltage, current and power from the INA219 together with speed, and compute input power and current ripple for each case. Present the results in a table and explain the differences from the current paths in each scheme.
Checkpoint: A table of input power and current ripple for each scheme at three speeds.
- 9
Compare with the model
Feed the same speed set-points to your simulation and compare simulated and measured speed responses and DC-link current. Where they differ, identify which parameter is wrong, such as friction, inertia or back-EMF constant, refit it from the measured data and repeat the comparison. State the final agreement as a measurable error, because a validated model is what lets you study changes like commutation advance without risking the hardware.
Checkpoint: Model and measurement speed responses agree within a stated error.
- 10
Report
Document the power-stage wiring, the TIM1 and Hall timer configuration, the commutation table, the protection tests and the PWM scheme comparison, with oscilloscope captures of dead time and phase voltages. Include the safety precautions you followed, such as the current-limited supply and testing with the bridge unpowered. Present the model validation and discuss what limits performance, for example torque ripple from six-step commutation and Hall placement error.
Checkpoint: A report with oscilloscope captures, plots and tables.
Testing & validation
- Dead time and break response on an oscilloscope
- Hall sequence and commutation in both directions
- Speed-loop step response metrics against targets
- Protection tests: stall, invalid Hall state, over-current
- PWM scheme comparison of input power and current ripple
Expected results
A Hall-sensored six-step BLDC controller with complementary PWM, dead time, speed control and protection, plus a measured comparison of two PWM schemes and a validated motor model.
Research angle for your M.Tech thesis
Research questions: how do PWM scheme and commutation advance affect DC-link current ripple and input power at different speeds, and how sensitive is performance to Hall sensor misalignment? Metrics: input power at fixed speed and load, current ripple, speed error, torque ripple inferred from speed ripple. Baselines: H_PWM-L_ON without advance. A strong thesis would add a Hall-misalignment compensation method, quantify its benefit against the baseline, and validate the simulation model against measurements.
Take it further
- Add commutation advance at higher speeds and measure its effect
- Implement sensorless back-EMF zero-crossing detection
- Move to field-oriented control with phase-current sensing
Viva and review questions
Why is dead time needed?
MOSFETs do not switch instantly; without a gap, the high and low switches of a leg could conduct together and short the supply.
What does an invalid Hall state mean?
000 or 111 cannot occur with correctly placed sensors, so it indicates a wiring, sensor or supply fault and the drive must stop.
How do you measure speed from Halls?
Time between Hall edges gives one-sixth of an electrical revolution; dividing by pole pairs gives mechanical speed.
Why can the kit's motor driver not run a BLDC?
It is designed for brushed DC motors; a BLDC needs a three-phase bridge with six switches.