Pages: [1] 2   Go Down
Author Topic: Current monitor for fan running with PWM through FET  (Read 1147 times)
0 Members and 1 Guest are viewing this topic.
Slovenia, EU
Offline Offline
Full Member
***
Karma: 0
Posts: 153
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am running 12V fan with FET transistor through digital pin with PWM (analogWrite). I wanna be able to know, when the fan stops because of failure (for example, if i would hold the fan with my arm the system must notice that).

I tried with LM324 current monitor through analog port but without luck. http://weber.fi.eu.org/blog/images/current_monitor.png

Have got any idea, how to do that?
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Either high side current measurement or use a small resistor on the source of the mosfet and measure the voltage over it - a little simpler.
Logged

Slovenia, EU
Offline Offline
Full Member
***
Karma: 0
Posts: 153
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried this with 0,1 and 0,22 ohm resistor but difference in voltage when fan was running normal and when i hold them with hand was almost negligible. I am running fan with three PWM states: 50%, 75% and 100%. Can you be more specific, where to measure and how to se the difference?
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How much current does the fan take? The ADC has a resolution of just under 5mV using the default analog reference; so if you choose the value of resistor in series with the mosfet source so that it drops 50mV or 100mV when the fan is operating normally, you will easily be able to detect it - but only if you read it while the mosfet is turned on.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The resistor value is a function of the current and the capabilities of your measurement instruments.

If you were to use low-side measurements, put your current sensing resistor on the source. Also put a low-pass filter on it, like 10k / 0.1uf capacitor and measure the voltage over the capacitor - the values of the resistor / capacitor depends on your pwm frequencies.

That approach assumes that you cannot synchronize the current sensing with pwm output. If you can, you don't need the low-pass filter - you then have cycle-by-cycle current control of the pwm.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If it's real important to know if the fan is running or not I would not rely on the current flow amount, I would want to know if there was actual air flow being generated or not. Possible detection methods? Perhaps some kind of sensitive air flow switch. Perhaps two thermistors one placed in the air flow path and one not in the air flow path and if the temperature delta between the two was not above some minimum value then there is a air flow problem, regardless of the current the motor is drawing. Again measure or detect directly what is the most important process variable, not some indirect derived signal.

Lefty
« Last Edit: November 13, 2012, 10:53:33 am by retrolefty » Logged

Slovenia, EU
Offline Offline
Full Member
***
Karma: 0
Posts: 153
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How much current does the fan take? The ADC has a resolution of just under 5mV using the default analog reference; so if you choose the value of resistor in series with the mosfet source so that it drops 50mV or 100mV when the fan is operating normally, you will easily be able to detect it - but only if you read it while the mosfet is turned on.

Fan needs 630 mA (12V).. I connected fan to FET like this:

DRAIN - Fan GND (12V is connected directly to fan+)
GATE - To Arduino
SOURCE - GND

So, if i am using connection of FET and fan like this.. Where should i put resistor and where should i measure (analog input of arduino)?
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would put a small resistor (ideally 10mohm but higher is ok given that the current isn't too big) from the source to ground.

You should see voltage pulses on this resistor (6mv or so) when the motor is running, and nothing when the motor is disconnected.

Whether you use a low-pass filter after that will depend on your particular solution.

You can also detect a stuck motor (connected but not running): you will see higher magnitude of the pulses.


Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Fan needs 630 mA (12V).. I connected fan to FET like this:

DRAIN - Fan GND (12V is connected directly to fan+)
GATE - To Arduino
SOURCE - GND

So, if i am using connection of FET and fan like this.. Where should i put resistor and where should i measure (analog input of arduino)?

Connect the 0.22 ohm resistor between the mosfet source and ground. Also connect the junction of the two to an analog input, either directly (if you synchronize the analogRead with the PWM) or via a low-pass filter. You will get nearly 140mV across the resistor at full speed, which you can easily detect via analogRead. Or, use the 0.1 ohm resistor, you will get 63mV across it at full speed.

You should also connect a small resistor (100 to 220 ohms) between the Arduino output pin and the gate of the mosfet, to reduce the peak current to within the Arduino's rating when the pin changes state and the mosfet's input capacitance charges/discharges. An additional resistor (say 100K) between the output pin and ground is recommended, to ensure that the mosfet remains off while the Arduino is powering up and has not yet set the pin to be an output.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would put a small resistor (ideally 10mohm but higher is ok given that the current isn't too big) from the source to ground.

You should see voltage pulses on this resistor (6mv or so) when the motor is running, and nothing when the motor is disconnected.

As the count resolution for a arduino analog input pin is 5 millivolts or so and who knows what the noise floor will be, this seems like a most undesirable unreliable measurement to use to determine if the motor is operating at normal current draw or not.
Lefty


Whether you use a low-pass filter after that will depend on your particular solution.

You can also detect a stuck motor (connected but not running): you will see higher magnitude of the pulses.



Logged

Slovenia, EU
Offline Offline
Full Member
***
Karma: 0
Posts: 153
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also connect the junction of the two to an analog input, either directly (if you synchronize the analogRead with the PWM) or via a low-pass filter. You will get nearly 140mV across the resistor at full speed, which you can easily detect via analogRead.

You mean that i connect one wire after resistor to analog input, right (what did you mean with junction of two)?

[FET SOURCE]-----[RESISTOR]-----(to analogInput)-----[FET GND]      <-- like this, right?

Quote
which you can easily detect via analogRead

How to do that? I tried with this but if i am correct it can be used only if power supply is 5V?

1. SensorValue * 12/1023 to get voltage value
2. Than use I=U/R with values of 12V and 0,22 ohm to get current
3. If i hold the fan current should increase

Is that right?

Quote
either directly (if you synchronize the analogRead with the PWM)

And how to do that?
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Also connect the junction of the two to an analog input, either directly (if you synchronize the analogRead with the PWM) or via a low-pass filter. You will get nearly 140mV across the resistor at full speed, which you can easily detect via analogRead.

You mean that i connect one wire after resistor to analog input, right (what did you mean with junction of two)?

[FET SOURCE]-----[RESISTOR]-----(to analogInput)-----[FET GND]      <-- like this, right?


No, like this:

[FET SOURCE]-----(to analogInput)-----[RESISTOR]-----[GND]

Quote
which you can easily detect via analogRead

How to do that? I tried with this but if i am correct it can be used only if power supply is 5V?

1. SensorValue * 12/1023 to get voltage value

No, sense_voltage = analog_reading * 5.0 / 1024.

2. Than use I=U/R with values of 12V and 0,22 ohm to get current

No, use I = V/R with V = sense_voltage as calculated above.

3. If i hold the fan current should increase

Is that right?

Yes, most fans will draw more current if you hold them stalled.

Quote
either directly (if you synchronize the analogRead with the PWM)

And how to do that?

Simplest way is to do a digitalRead from the PWM pin and wait for it to be HIGH before you call analogRead. After the analogRead call, do another digitalRead and check the pin is still HIGH, discarding the analog reading if it is not.
« Last Edit: November 13, 2012, 02:00:09 pm by dc42 » Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Slovenia, EU
Offline Offline
Full Member
***
Karma: 0
Posts: 153
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Quote

No, sense_voltage = analog_reading * 5.0 / 1024.



Ok,

it is intresting to me that i should use 5V although i am powering my fan with 5V.. I will try and report.. Thank you for now!
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The 5V in that calculation is the voltage on the Aref pin of the microcontroller. You can use a different voltage reference, see http://arduino.cc/en/Reference/AnalogReference.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Slovenia, EU
Offline Offline
Full Member
***
Karma: 0
Posts: 153
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The 5V in that calculation is the voltage on the Aref pin of the microcontroller. You can use a different voltage reference, see http://arduino.cc/en/Reference/AnalogReference.

Today i tried all you sad and i think it works.. I used 10k and 10uF electrolytic capacitor for low pass filter (is 10uF too much?)

I measure this values:

Power of fan: 12V stable over LM7812

rpm = 127 (50%)
fan run normal: 180 mA
hand on fan: 240 mA

rpm = 191 (75%)
fan run normal: 290 mA
hand on fan: 420 mA

rpm = 255 (100%)
fan run normal: 420 mA
hand on fan: 620 mA

Of course this values are changing a little but i think i will be able to include them into my "warning alarm".

Btw, i still don't really understand, how to synchronize the analogRead with the PWM (to measure without low pass filter). Can you give me a code example? This is my part for measuring current:

Code:
  analogWrite(fan, 255);
  int sensorValue = analogRead(A0);
 
  float voltage = sensorValue * 5.0 / 1023.0;
 
  float current = voltage / 0.22;
 
  Serial.println(current);
Logged

Pages: [1] 2   Go Up
Jump to: