Skip to main content
emobility.academy
B.Tech / BEMotor controlIntermediate About 4 weeksKit + add-ons

Soft-Start and Acceleration Ramp Controller for an EV Motor

Build a soft-start controller that limits how fast the PWM duty can rise and fall, so a DC motor accelerates smoothly instead of jerking. You compare a step, a linear ramp and an S-curve, and measure the inrush current with a current monitor.

Uses: PWM · ADC

The problem

A sudden full-voltage step on a stationary motor draws a large inrush current, stresses the battery and driver, and jerks the vehicle. EV controllers shape the torque command with ramps to protect hardware and give a comfortable ride.

Objectives

  • Implement linear ramp and S-curve rate limiters on the duty command
  • Make ramp rates selectable from the keypad
  • Measure inrush current and rise time for step, linear and S-curve inputs
  • Show settings and live values on the LCD

What you need

From the EV Embedded Development Kit

  • STM32F103C8T6 microcontroller unit (Arm Cortex-M3)
  • Motor driver for PWM motor-control experiments
  • Analog potentiometer input
  • 4×3 matrix keypad
  • 16×2 LCD
  • I2C and SPI buses to the onboard devices

Software

  • STM32CubeIDE with HAL TIM, ADC and I2C
  • Embedded C
  • Python with pandas and matplotlib to plot current and duty

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; the INA219 in series with the motor supply measures inrush current to prove the ramp works.

Key concepts

Inrush current
A stationary motor has no back-EMF, so its current at start is limited only by winding resistance and is far higher than running current.
Slew-rate limiter
The output can only change by a fixed amount each control period, turning a step input into a linear ramp.
S-curve ramp
Limiting the rate of change of the rate (jerk) as well as the rate gives smooth starts and stops of acceleration, which feels better to a rider.
INA219
An I2C device that measures the voltage across a shunt resistor and the bus voltage, and reports current and power through its registers.

Step-by-step guide

  1. 1

    Define the ramp requirements

    Decide the ramp profiles to test, for example 0–100% duty in 0.2 s, 1 s and 2 s, and a separate, faster ramp-down. Write the rule that an emergency stop key bypasses the ramp completely, because a ramp must never slow a stop the rider asked for. For each profile write down what you expect to happen to inrush current and how the start will feel. These expectations become hypotheses you check with measurements at the end.

    Checkpoint: A table of ramp profiles and the rule for emergency stop.

  2. 2

    Set up the board

    Set the DIP switches for the motor driver, potentiometer, keypad and LCD, and connect the INA219 to the kit's I2C bus with its shunt in series with the motor supply. In CubeMX set the 72 MHz clock, a 20 kHz PWM channel for the driver, ADC on the pot with DMA, I2C1 at 400 kHz and a timer interrupt at 1 kHz for the control loop. Note the INA219's address strapping so you know which address to expect.

    Checkpoint: An I2C scan finds the INA219 at its strapped address.

  3. 3

    Read current from the INA219

    Write the INA219 calibration register for your shunt resistance and the maximum current you expect, using the formula in its datasheet, then read the current register with HAL_I2C_Mem_Read. Before trusting it with the motor, connect a known resistive load and compare the INA219 current with a multimeter at a few values. Read the INA219 at a rate it can support for your conversion-time setting, and check the sign so motor current reads positive.

    Checkpoint: INA219 current agrees with a multimeter within a few per cent on a resistive test load.

  4. 4

    Throttle input

    Read the potentiometer through the ADC with DMA, filter it with a short moving average and apply a small dead-band at the bottom of the travel. The result is the target duty. The ramp, not the pot, decides the actual duty that goes to the timer, so keep the two as separate variables in the code and log both. This separation is what lets you compare a step start with ramped starts using exactly the same throttle input.

    Checkpoint: Target duty on the console follows the pot smoothly from 0 to 100%.

  5. 5

    Linear ramp

    In the 1 kHz loop, move the actual duty toward the target by no more than one step per tick, where the step is the full duty range divided by ramp time multiplied by 1000 ticks per second. Work in tenths of a per cent with integers, so a 1 s ramp moves 1 unit per tick and no software floating point is needed in the fast loop. Allow a separate, larger step for ramping down so releasing the throttle feels responsive.

    Checkpoint: Logged duty shows a straight ramp whose duration matches the setting within one tick.

  6. 6

    S-curve ramp

    Add a second state variable, the current ramp rate. Each tick the rate itself changes by at most a jerk limit toward the maximum rate, and the duty moves by the current rate. As the duty approaches the target, reduce the rate early enough that it reaches zero on arrival, which avoids overshoot. Plot duty against time for the linear and S-curve modes on the same axes and check that the S-curve has smooth corners at both ends.

    Checkpoint: The S-curve duty has smooth start and end with no overshoot past the target.

  7. 7

    Keypad settings and LCD

    Map keypad keys to settings: 1 to 3 choose the ramp time, 4 toggles between linear and S-curve, 0 selects step mode with no ramp for comparison, and # is the emergency stop that sets duty to zero in the same tick. Show the mode, target duty, actual duty and the latest INA219 current on the LCD at a few updates per second. Changing mode while running should only change how the next movement is shaped, never jump the duty.

    Checkpoint: Changing mode while running takes effect smoothly and emergency stop cuts the duty in one tick.

  8. 8

    Measure inrush

    Log INA219 current and actual duty at 1 kHz over UART for a 0–100% throttle step in each mode, with five repeats per mode and the motor stopped before each run. In Python extract peak current, time to reach 90% of steady running current and any current overshoot. Present the results as a table of mean and spread, plus overlaid current plots. Check whether the measured reductions match the expectations you wrote down in the first step.

    Checkpoint: Plots and a table showing peak current for step, linear and S-curve modes.

  9. 9

    Report

    Write up the ramp equations, the INA219 set-up and calibration check, the measured inrush results and a recommendation for ramp settings on this motor. Explain the trade-off between responsiveness, which the rider wants, and current stress on the battery, driver and motor, which the engineer wants to limit. Include photos of the set-up, the comparison plots, and a short demonstration of each mode including the emergency stop.

    Checkpoint: A report with measured plots and a demonstration of each mode.

Testing & validation

  • INA219 current checked against a multimeter
  • Ramp duration measured from logged duty
  • Peak inrush current for step, linear and S-curve inputs, five repeats each
  • Emergency stop response time

Expected results

A soft-start motor controller with selectable linear and S-curve ramps and measured evidence of how much each one reduces inrush current compared with a step start.

Take it further

  • Add a current limit that holds the ramp when INA219 current exceeds a threshold
  • Add drive modes with different ramp rates
  • Close the speed loop with an encoder motor

Viva and review questions

Why is inrush current high at start?

With the rotor stationary there is no back-EMF, so the current is the applied voltage divided by the small winding resistance.

How did you compute the ramp step?

Step per tick is the full duty range divided by ramp time times the loop rate, for example 1000 tenths of a per cent over 1000 ticks for a 1 s ramp.

Why does emergency stop bypass the ramp?

Safety commands must act immediately; a ramp that slows a stop could keep the vehicle driving when the rider wants it stopped.

What does an S-curve add over a linear ramp?

It limits jerk, so acceleration starts and ends gradually, which is gentler on the drivetrain and the rider.

Related EV projects

All 100 EV projects