Hello, picture below is how i imagined to measure voltage and current on the PWM controlled brushed 12V DC motor. I'm affraid that the ground will jump from common ground to relative ground and destroy arduino.
My question - how can i measure current and voltage on device that is PWM controlled over mosfet?
I already tried ACS712 and it is horible so i ordered INA219 and INA260 modules just in case.
Thank you in advance
TTS
Do you understand what PWM is? You'll have to smooth, filter, or average it to get a usable meausrment.
The average voltage should be proportional to the PWM... At 50% PWM (127 or 128) and a 12V supply you should be getting 6V average, minus whatever (hopefully small) voltage loss you're getting across the MOSFET.
By horrible I mean that the voltage output of ACS712 is very susceptible to many different types of noise. Changes on the Vcc throw off the Vout. Changes in magnetic fields around the module throw it off. Overall, not a very reliable module for my needs.
The main problem here is that the voltage is divided over R1 and R2 but the R2 is grounded only during the on state a.k.a. duty cycle. That means that the path of least resistance during the off state is through R1 and directly towards A1 pin. That probably means 12V on A1.
Now i don't know how to avoid this problem. Should i wire R2 to the common ground and take the 4.8V measurements as the zero?
Once you start talking about grounds that are not common, floating grounds, fair grounds and any other kind of ground then that's a warning you are doing the wrong thing. The anode of D1 and the negative pole of the motor is never ground, although in your circuit it is sometimes connected to ground via Q1. Ground is a point in a circuit designated by the circuit designer, not the negative pole of the supply or anything else.
The solution to your problem is to measure the voltage at the junction of Q1 drain and the motor negative, and to measure the voltage at the motor positive. If you can be sure that Vcc is known and does not vary you can do away with measuring at the motor positive. You then use maths to calculate the difference between the 2 voltages and work out the voltage across the motor.
Note that as the ACS712 is measuring current, and as it uses a completely isolated measuring technique, it can go anywhere in the current path, it does not have to be between Vcc and the motor positive. If you are not familiar with Kirchhoff's circuit laws - Wikipedia then please study them as they tell you why this is.
I think you will run into difficulty for 2 reasons:
PWM chops up the current, so you are not measuring a nice, neat hardly varying voltage.
DC motors produce their own voltage because they act as generators when turning, so you need to know what the voltage you see actually represents.
I used ACS712 at the source side of the circuit since it's recommended in the specification to do so. Are you suggesting that it's better to measure the current on the source side of the circuit?
I'm a bit confused what do you mean by that. Are you suggesting to measure voltage across MOSFET? I'm sorry for the confusion in the advanced
Measuring voltage and current on a pwm controlled motor is very difficult to do as implied by @PerryBebbington .
The voltage and current waveforms will be complex due to the characteristic of the motor ( inductance , back emf) and the PWM signal . They won’t be nice square waves.
The Arduino can only take spot readings which will be meaningless . You may possibly get something with lots of very fast samples , but these would need to be say ten times greater than the pwm frequency - creating loads of data that you need to sort out .
I’d put this in the too hard drawer .
Btw don’t drive the motor from a connection made to the Arduino board .
I'm not saying it's better to measure here or there or somewhere else, I'm saying that because it uses a measurement technique that isolates the measured current from the rest of the circuit you don't need to worry about where you do the measurement. If you understand Kirchoff's current law then you know the current is the same at all points in a series circuit, giving you freedom to measure where you want.
In addition to what I said before and building on what @hammy said, if you measure while Q1 is on you will see Vcc across the motor, if you measure while Q1 is off you will see the motor back EMF voltage. Where I disagree with @hammy is that I see this as an interesting project that will teach you a lot of you pursue it. Difficult yes, but worth it for what you will learn.
Please read and understand Kirchoff's circuit laws, particularly the one about voltage. The voltage across the MOSFET is easy to measure. The voltage across the motor is Vcc minus the voltage across the MOSFET.
I tried to make a pwm variable current source ( with feedback ) for an inductive load and failed as I could not measure a representative current because of the rise time of the current and the back emf - gives an interesting current and voltage waveform .
Timing the current measurements with the PWM outputs and then trying to control it did for me .I’d think motors are worse .
Yes educational , but I don’t know how you would do it lol.
If you COULD usefully measure current and voltage what information would you get by doing so?
I've not tried but perhaps you could measure the AVERAGE voltage and current.
However you CAN measure the voltage Vx across the FET when the motor is running at 100% and (Vcc -Vx) * PWM will give you the average voltage
and
With this circuit architecture, users can implement a simple
RC filter via the addition of a capacitor, CF (see Application 7)
from the FILTER pin to ground.
may give you a more useful value for current.
If you COULD usefully measure current and voltage what information would you get by doing so?
(eg motor power, speed, torque ...)?
Thank you all for your replies. I ditched the voltage measuring with voltage divider, because it seemed impossible. Also the ACS712 simply didn't work for me, too much noise in the results.
At the end I was able to get very useful readings using INA260 and INA219 modules.
Using falstad sim i figured out where was the best point to place the module, to get the most useful readings and I also added a 22nF bypass cap to filter out some of the noise.
Anyhow, INA modules are the way to go if you don't want to pull out your hair.