Skip to main content
emobility.academy
M.TechMotor controlAdvanced About 8 weeksKit + add-ons

Torque Derating Based on Battery and Motor Temperature

Build a torque-derating controller that reduces motor power as battery and motor temperatures approach their limits. Battery temperature comes from the BMS T-sense input and motor temperature from a lumped thermal model driven by measured current, and you compare simple linear derating with a model-predictive approach.

Uses: PWM · ADC · I2C

The problem

EV motors and batteries lose life or become unsafe if they run too hot. Controllers derate torque as temperature rises, but abrupt or late derating surprises the rider, while early derating wastes performance. A good strategy keeps temperatures under limits with the least loss of power.

Objectives

  • Measure battery temperature from the T-sense input and ambient from the BMP280
  • Estimate motor winding temperature with a lumped thermal model driven by measured current
  • Implement linear, PI-based and predictive derating strategies
  • Compare strategies on peak temperature, time over limit and delivered power

What you need

From the EV Embedded Development Kit

  • STM32F103C8T6 microcontroller unit (Arm Cortex-M3)
  • Second STM32F103C8T6 as the Smart BMS unit
  • 1S battery with connector and T-sense input
  • BMP280 pressure and temperature sensor
  • Motor driver for PWM motor-control experiments
  • Analog potentiometer input
  • I2C and SPI buses to the onboard devices
  • 16×2 LCD
  • RGB LEDs and a buzzer

Software

  • STM32CubeIDE with HAL TIM, ADC, I2C, SPI and UART
  • Embedded C
  • Python with NumPy, SciPy, pandas and matplotlib for thermal model fitting
  • MATLAB/Simulink (optional)

Extra parts

  • A small brushed DC motor within the motor driver's rating — The kit has a motor driver but no motor.
  • INA219 I2C current/power monitor — Current measurement is not on the kit; motor current drives the I-squared-R heating in the thermal model.
  • NTC thermistor fixed to the motor body (optional) — Gives a measured motor case temperature to calibrate and validate the thermal model.

This project uses the kit's lithium cell. Respect polarity, never short the terminals, and don't leave the cell charging unattended.

Key concepts

Lumped thermal model
Treating the motor as one thermal mass with a thermal resistance to ambient gives dT/dt = (P_loss − (T − T_amb)/R_th)/C_th, where P_loss is mostly I-squared-R.
Derating curve
Full torque below a start temperature, falling linearly to a minimum at the limit temperature, with hysteresis so torque does not oscillate at the boundary.
Predictive derating
Using the model to predict temperature a few tens of seconds ahead lets the controller reduce power earlier and more gently.
Fixed-point thermal update
The model runs at 10 Hz with small increments; on a Cortex-M3 with no FPU, Q16 fixed-point keeps it cheap and avoids precision loss from tiny float steps.

Step-by-step guide

  1. 1

    Requirements and safety

    Define the temperature limits: the motor derating start and limit temperatures, and the battery limits taken from the cell datasheet. Do not heat or cool the lithium cell externally; for tests near battery limits, inject a temperature offset in software instead. Follow normal cell care throughout: check polarity, never short the terminals and never leave charging unattended. Write the derating curves and a test plan that states which tests use injected values and which use real readings.

    Checkpoint: A table of temperature limits, derating curves and a test plan that uses software injection for battery extremes.

  2. 2

    Board and sensor setup

    Set the DIP switches for the Smart BMS unit, battery, motor driver, potentiometer, LCD and BMP280. Connect the INA219 on the I2C bus with its shunt in series with the motor supply. Read the BMP280 on its bus and apply the compensation formulas from its datasheet to get ambient temperature, and receive cell temperature from the BMS unit, which reads the T-sense input. Compare all readings with a thermometer and multimeter before collecting data.

    Checkpoint: Battery, ambient and motor current readings appear on the console and agree with a thermometer and multimeter.

  3. 3

    Collect thermal data

    Fix the optional NTC to the motor body with thermal tape. Run the motor at three constant duty levels, each long enough for the temperature to approach steady state, and log motor current, ambient temperature and the motor NTC at 1 Hz over UART. Let the motor cool fully to ambient between runs and log the cool-down too, since it shows the thermal time constant without any heating term. Save each run as a CSV file with its settings.

    Checkpoint: Heating and cooling curves for each duty level saved as CSV files.

  4. 4

    Fit the thermal model

    In Python, fit the lumped model's thermal resistance, thermal capacitance and effective winding resistance to the logged heating and cooling data, using SciPy least squares on the simulated temperature against the measured one. Hold one run back from the fit and use it only for validation. Report the fitted parameters with their uncertainty and the validation error, and plot measured against predicted temperature for the validation run.

    Checkpoint: Model prediction on the validation run stays within a stated error of the measured case temperature.

  5. 5

    Implement the model on the MCU

    Port the fitted model to the STM32 as a 10 Hz update in Q16 fixed-point arithmetic, using ambient temperature from the BMP280 and current from the INA219 as inputs. The per-step temperature changes are tiny, which is where fixed point keeps its precision better than repeated small float additions. Feed the same logged inputs to the MCU code and to the Python model, and compare their outputs over a full run.

    Checkpoint: MCU and Python model outputs agree within a small fraction of a degree.

  6. 6

    Linear derating baseline

    Compute a torque limit factor between 0 and 1 from the hotter of the battery and motor temperatures, using the linear curves from your requirements with hysteresis at each threshold. Multiply the throttle-derived duty by this factor before it reaches the PWM timer. Rate-limit the factor so it changes gradually and the rider never feels a sudden loss of power. Test it by injecting rising temperatures and checking the maximum duty follows the curve.

    Checkpoint: Raising the injected temperature reduces maximum duty along the defined curve.

  7. 7

    PI and predictive derating

    Implement two more strategies. The PI strategy adjusts the limit factor to hold the modelled motor temperature at a target just below the limit. The predictive strategy runs the thermal model forward over a horizon such as 30 s at the present power, and reduces the factor if the predicted temperature would exceed the limit. Make sure each runs within the 10 Hz budget, and log the limit factor and predictions for analysis.

    Checkpoint: Both strategies run in real time and their limit factor is logged.

  8. 8

    Indications

    Tell the rider what is happening. Show battery temperature, modelled motor temperature and the present limit factor on the LCD. Set the RGB LED amber while derating is active and red when a temperature reaches its limit, and give one short beep when derating starts so it never comes as a surprise. Check that the indications always match the logged derating state, including during recovery as temperatures fall.

    Checkpoint: The rider-facing indications match the logged derating state.

  9. 9

    Compare strategies

    Run the same demanding throttle profile with each strategy, starting from the same cool temperature each time. Compute peak motor temperature, time spent above the limit, mean delivered duty, and the number of large torque changes per run. Repeat each run at least three times. Present a table and overlaid plots, and state which strategy gives the best performance for the same protection, with the evidence.

    Checkpoint: A comparison table for linear, PI and predictive derating.

  10. 10

    Report

    Write up the thermal model and its fitted parameters, the validation results, the three derating strategies, and the comparison. Discuss the trade-off between thermal protection and available performance, how model error affects the predictive strategy, and what a production controller would add, such as a measured winding temperature or a battery thermal model. Include the safety approach you used for battery-limit testing.

    Checkpoint: Report with fitted parameters, validation plots and comparison results.

Testing & validation

  • Sensor readings checked against a thermometer and multimeter
  • Thermal model validated on a held-out run
  • MCU model output matched against Python
  • Strategy comparison on peak temperature, time over limit and delivered duty

Expected results

A fitted and validated motor thermal model running in fixed point on the STM32, and three derating strategies compared on how well they protect temperature while preserving performance.

Research angle for your M.Tech thesis

Research questions: how much performance does predictive derating recover over linear derating for the same temperature safety margin, and how sensitive is it to thermal model error? Metrics: peak temperature, time over limit, mean delivered power, torque change rate. Baseline: linear derating with hysteresis. A thesis-quality contribution would quantify the benefit across several duty profiles, analyse robustness to parameter error, and show the fixed-point implementation's cost on a Cortex-M3.

Take it further

  • Send the derating factor over CAN as a VCU would
  • Add an observer that corrects the model with the measured NTC temperature
  • Include a battery thermal model driven by estimated cell current

Viva and review questions

What does R_th times C_th represent?

The thermal time constant: how quickly the motor approaches its steady temperature after a change in power.

Why not heat the cell to test battery limits?

Heating a lithium cell is unsafe; injecting a temperature offset in software tests the logic without risk.

Why add hysteresis to derating?

Without it, temperature noise around the threshold would make torque switch up and down repeatedly.

Why fixed-point for the model?

The Cortex-M3 has no FPU and the temperature increments per step are small, so Q16 fixed-point is faster and keeps precision.

Related EV projects

All 100 EV projects