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.
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..
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
}
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?
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.