2021-03-20 OrangeBot Motor Controller MK2 - Current Sensing


OrangeBot Motor Controller MK2 - Current Sensing


One of the objectives for the OrangeBot MK2 Motor Controller is to add a third PID loop closed on the motor current.

The VNH7040 Half Bridge has a multi sense pin meant to monitor the H Bridge current, supply voltage and temperature. The current firmware driver should already ask the VNH7040 for the runtime current reading.

The objective for this entry is to check that the sense pin is working from an electrical standpoint, by checking no load and full load conditions and to implement electrical and firmware changes necessaries to make the current reading available to the microcontroller.

2VNH7040 Current Sensing

2.1Measure multi sense pin

A multimeter in series with the motor is used to measure the motor current.

An oscilloscope is used to measure the output of the multi sense pin.

Load is simulated by physically stopping the motor shaft by hand. No load/Stall.

Illustration 1: Setup

Illustration 2: Oscilloscope Measure

2.2Multi sense Circuit

Several circuits have been tested to bring the multi sense to the ADC pin.

On the microcontroller, PA0 ADC0 pin is used for the multi sense pin.

Illustration 3: Amplifier Circuit


  1. Works well enough

  2. Saturate due to high gain

  3. Somewhat less noisy as it takes the multi sense ground as reference.

The VNH7040 evaluation board uses a 33nF and 10KOhm resistor on the multi sense pin. This is not ideal because the ground is the noisy one from the power stage.

When building the proper VNH7040 motor controller board, the resistor can be grounded to the analog ground of the GD32VF103 and OP AMP for much improved noise rejection.

2.3GV32VF103 Pins

The output of the amplifier is connected to PA0 ADC0 pin of the microcontroller.

Illustration 4: Longan Nano GD32VF103 Pinout


Illustration 5: Schematics


With the electrical side of the circuit taken care of, support is added firmware side.

Right now the ADC reading is spot checked when the screen refreshes.

Illustration 6: Firmware Current

Github firmware repository (also click on photo)


This entry described how the multi sense pin of the VNH7040 can be used to provide the GD32VFD103 with a direct measure of the motor current.

Video 1: No load/Stall microcontroller and oscilloscope readings