PWM motor control with current sensing

I'm looking for some help with a motor speed control circuit.

The 12v motor is controlled by a variable PWM signal from the Arduino to the gate of a MOSFET (IRLZ44). The circuit needs to monitor the current used by the motor so it can shut off the motor under various load conditions. The threshold for this is set by a potentiometer.

The current is ascertainied by measuring the voltage across a 0.05 ohm resistor on the source side of the MOSFET and then using ohms law to calculate the current. The idea is that the voltage is sampled only when the PWM signal is high. The circuit and motor control seemed to work ok when using a more linear load, but the motor's induction causes big problems with the voltage measurement across the resistor. In the two photos, you can see oscilloscope plots measured at the MOSFET side of the resistor when the motor is moving slowly (image 1) and then at higher speed (image 2). It is impossible to measure a consistent voltage with this output.

What is the best solution for this problem? I thought about adding a low-pass filter but the PWM is variable so I assume the filter values would also need to change.

Sorry for the hand-drawn diagram and old-school scope pics!



The drawing is fine, but you forgot to include the required inductive kick diode. If it actually is missing, I'm surprised that the MOSFET is still alive. However, that rounded peak in the lower photo suggests that it already is damaged.

1 Like

The diode is actually there, but I forgot to draw it in my high quality diagram :slight_smile:

Measuring the current is a difficult problem, especially with a slow Arduino like the Uno.

You can buy motor drivers with current sensing. Pololu has the best selection.

If you monitor the motor RPM, you can accomplish the same results, as RPM is related to torque and that is related to current.

Not so easy with this as it the motor is a pump so it's not possible to monitor shaft rotations.

I did think about using something like this but, if possible, I would like to build something myself. Of course, I may change my mind if it proves far too difficult!

I would use an RC filter between sense resistor and analogue input.
Then you don't have the sampling problem.
Use 10k between Rsense and analogue in.
Cap value (analogue pin to ground) depends on PWM frequency.
You have a scope, so you can see the right amount of smoothing.
Leo..

1 Like

So just put a cap here?

If I put a resistor between the analogue in and the sense resistor, won't it skew the reading of what is already just a few tens of mV?

No, the impedance of an analogue pin is so high that a 10k resistor in series won't make a difference. You must have a 10k resistor between sense resistor and analogue pin, and a cap from pin to ground, otherwise the filter won't work.

Set Aref to 1.1volt, to maximise A/D readings.
Leo..

void setup() {
  analogReference(INTERNAL); // set Aref to 1.1volt, assuming Uno R3
}

Leo..

1 Like

It depends on the switching frequency, you may try the best one by observing the scope.

But I think the feedback voltage may be very small, you may need an op. Amp to raise the voltage.

Technically you also need a diode connecting from you feedback point (analog input) back to the Vss (normal practice to protect you controller)

..... so, a build-in driver with current limit worth you to buy :stuck_out_tongue:

Brattain, as I read from your requirements, I think your schematic is not your goal.

In fact, your circuit is a switch current measurement, it is best used as a peak current limiter. (Similar to a buck switching circuit for motor,but not actually is ).

If you would like to measure the average current, you should put you resistor at the top or bottom in series with the motor. (Of course, more circuit technique is necessary to achieve this measurement)

So, something like this? Do I just use the PWM frequency as the basis for calculating the value of the capacitor or does the duty cycle of the signal also need to be considered?

Move the cap to the left...

1 Like

This one better

Npn should be low side switching.

These days people use mosfets instead of bjt's.

You can try this circuit (Fig-1):


Figure-1:

OR

You can use the following Motor Driver (Fig-1). You need to install the Current Sense Resistor (Fig-3).
L298DriverPic
Figure-2:

L298Schematic-2
Figure-3:

Sorry, I just quote a conceptual example, you can use BJT, FET, IGBT or GaN

The main point I concern is the position of current measurement, if you measure the switch current it will not be accurate.

In large current, the circuit go to continuous mode, while in low current, the circuit go to discontinue mode. If no compensation is made, your measurements are not accurate.

That why I suggest to measure the current in a continuous way, in some book, it is named as average current mode.

Ray, as I understand Kirchoffs LAws, in a series circuit the current measured ANYWHERE in the circuit must be the same?