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

Eco / Normal / Sport Drive-Mode Controller with Keypad Selection

Build a drive-mode controller where the rider picks Eco, Normal or Sport on the keypad, and each mode changes the throttle map, top power and acceleration ramp of a DC motor. The LCD and RGB LED show the active mode.

Uses: PWM · GPIO · ADC

The problem

EV riders want long range at some times and quick response at others. Drive modes trade performance for efficiency by shaping how throttle position becomes motor power, and they must switch safely while riding.

Objectives

  • Implement three throttle maps as lookup tables with interpolation
  • Apply per-mode duty limits and ramp rates
  • Allow mode changes only when it is safe
  • Compare average duty over a repeatable throttle cycle across modes

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
  • RGB LEDs and a buzzer

Software

  • STM32CubeIDE with HAL TIM, ADC and GPIO
  • Embedded C
  • Python with matplotlib to plot the throttle maps

Extra parts

  • A small brushed DC motor within the motor driver's rating — The kit has a motor driver but no motor.

Key concepts

Throttle map
A curve from pedal position to power command; a progressive curve gives fine control at low throttle, an aggressive one gives quick response.
Lookup table interpolation
Storing 11 points per map and interpolating linearly between them is fast and easy to tune without floating point.
Duty limit
Capping maximum duty in Eco limits peak power and current draw, which extends range.
Mode-change interlock
Switching maps at high throttle would cause a sudden power jump, so the change waits until the throttle is low or blends over a short time.

Step-by-step guide

  1. 1

    Define the modes

    Write a parameter table for each mode. Eco uses a progressive throttle map, 60% maximum duty and a slow ramp; Normal uses a linear map, 85% maximum duty and a medium ramp; Sport uses an aggressive map, 100% duty and a fast ramp. Keypad keys 1, 2 and 3 select the modes. Plot the three maps in Python so the team can see and agree the shapes before any code is written, and keep the plot for the report.

    Checkpoint: A parameter table and plotted maps agreed by the team.

  2. 2

    Set up the board

    Use the DIP switches to enable the motor driver, potentiometer, keypad, LCD and RGB LEDs. In CubeMX set the 72 MHz clock, a 20 kHz PWM channel and the motor-driver direction pins, ADC with DMA on the pot, GPIO rows and columns for the keypad and a timer for a 100 Hz control loop. Build a test program that prints the pot value and drives a fixed duty, to confirm every block works before adding logic.

    Checkpoint: The PWM output and pot reading both work in a test build.

  3. 3

    Throttle input

    Average the potentiometer readings over a short window to remove noise, apply a small dead-band at the bottom so a released pedal reads exactly zero, and scale the 12-bit result to 0–1000. This throttle position is the single input to every drive-mode map, so test it carefully: check both ends of travel, check it is steady when the pot is untouched, and check that it never exceeds 1000 even if the pot reaches the ADC limit.

    Checkpoint: Released pot reads 0 and full travel reads 1000.

  4. 4

    Lookup tables

    Store each map as 11 integer points at throttle positions 0, 100, 200 and so on up to 1000. Write one interpolation function that finds the two neighbouring points and interpolates linearly in integer maths, then scales the result by the mode's maximum duty. Keeping the maps as data rather than code means you can retune them by editing numbers. Test the function on the PC with the same C file, comparing results at and between table points.

    Checkpoint: PC unit tests of the interpolation give the expected values between table points.

  5. 5

    Per-mode ramp

    Apply a slew-rate limit to the duty so it can only rise by the mode's ramp step each 10 ms tick: small in Eco, large in Sport. Allow the duty to fall faster than it rises so lifting off feels responsive, and always allow an immediate cut to zero when the throttle is fully released or # is pressed. Log duty against time for the same throttle step in each mode and confirm the slopes match your parameter table.

    Checkpoint: Logged duty shows the slower rise in Eco than in Sport for the same throttle step.

  6. 6

    Mode selection logic

    Debounce the keypad and accept a mode change only when the throttle is below 10%, so the map never changes under a pressed pedal. If the rider presses a mode key at higher throttle, keep the current mode, show 'Release throttle' on the LCD and beep once. Set the RGB LED to green for Eco, blue for Normal and red for Sport, and start in the last safe default mode, Normal, after every reset.

    Checkpoint: Pressing 3 at high throttle is refused, and accepted once the throttle is released.

  7. 7

    Integrate and display

    Run the whole chain in the 100 Hz loop: read throttle, look up the active map, apply the ramp and update the PWM compare value. Update the LCD a few times per second with the mode name, throttle % and duty %. Ride through each mode with the same pot movements and check that the motor clearly feels different: gentle and capped in Eco, quick and full-power in Sport. Note any surprises for the tuning stage.

    Checkpoint: The motor responds differently in each mode for the same pot movement.

  8. 8

    Compare modes

    Record one throttle trace by moving the pot through a typical stop-start pattern, store it in flash or RAM, and replay it in a test mode so every mode sees exactly the same input. Log duty at 100 Hz for each mode and compute average duty and peak duty, which stand in for energy use and peak power since current is not measured on the kit. Present a table and overlaid plots, and repeat each replay three times.

    Checkpoint: A table of average and peak duty for each mode over the same throttle cycle.

  9. 9

    Document

    Write up the maps and their plots, the parameter table, the interpolation and ramp code, the mode-change interlock and the comparison results. Include photos and a short video that shows a mode change being refused at high throttle and accepted after release. Finish by explaining what a real drive-mode system adds, such as speed limits per mode, regen strength per mode and estimated range shown on the dashboard.

    Checkpoint: Report and demonstration complete.

Testing & validation

  • Interpolation unit tests
  • Ramp rate measured per mode from logged duty
  • Mode-change interlock test at high and low throttle
  • Average and peak duty over a replayed throttle trace per mode

Expected results

A three-mode drive controller with distinct throttle feel, power limits and ramps, a safe mode-change interlock and a logged comparison of duty demand across modes.

Take it further

  • Save the last selected mode in SPI flash so it survives power-off
  • Add an INA219 current monitor to compare real energy use between modes
  • Add a 'limp' mode triggered by a low cell voltage reading from the BMS

Viva and review questions

Why use lookup tables for throttle maps?

They are fast, use integer maths and let you reshape the curve by editing a few points without changing code.

Why refuse mode change at high throttle?

Jumping to a more aggressive map at high pedal would cause an abrupt torque increase that could unsettle the rider.

What does Eco actually save?

Lower peak duty and slower ramps reduce peak current and losses, which extends range in a real vehicle.

Related EV projects

All 100 EV projects