Measuring current in a PWM signal.

Thread Starter

MB107

Joined Jul 24, 2016
345
I have an application for an automotive radiator cooling fan. For the moment I am using a Arduino derivative called a Robo-Red. It is pretty much the same as an Uno but can handle higher voltage inputs and more power output. I have the system working fine on the bench, with a 5V PWM signal off pin 9 of the Robo-Red, driving a Mercedes W203 fan directly from pin 9 PWM output. The Mercedes Benz fan uses a 10Hz. 0 - 5V PWM signal. A deviation from that signal will cause the fan controller to run at full speed by taking 12V DC power directly from the ignition switch. The logic behind that is buried inside the Bosch fan motor. The fan motor itself is a 600W motor with two large 6 ga power cables coming into it. and two smaller cables for +12 emergency mode signal and 0 - 5V PWM signal.

But the output current of the PWM signals off any of the Arduino like products is limited and I would like to know how close I am to those limits. Therefore I want measure the PWM current. In an attempt to do this I tried to install a 1 Ohm shunt resistor in line with the fan. The fan still runs fine with the 1 Ohm resister in place but as soon as I connect the leads to the O scope the fan runs away in emergency mode. I can successfully run the fan with the shunt resister connected to a DC volt meter. With the DC voltmeter I am recording 13 mV which will equate to 13mA with the 1 Ohm resister. But the wave form is PWM so the voltmeter will only average. I would like to use the O scope to get the max current. The shunt resistor is shown on the bottom right of the diagram.

Anyone know whats going on her or how this measurement can be made.

1639763958444.png
 

Irving

Joined Jan 30, 2016
3,845
You need to use two probes and use the 'scopes A-B math function to give the differential voltage across the shunt. You were connecting scope ground to one end of the shunt which killed the PWM.

The RMS value of a PWM = √D where D = duty cycle...
 

Thread Starter

MB107

Joined Jul 24, 2016
345
You need to use two probes and use the 'scopes A-B math function to give the differential voltage across the shunt. You were connecting scope ground to one end of the shunt which killed the PWM.

The RMS value of a PWM = √D where D = duty cycle...
Thanks for the reply.

I set the signal up to 5V PWM at 50% duty cycle. I tried that and it works, but I got a higher that expected value ~240mv = 240ma
I haven't figured out how to do math yet on the O scope but reading the cursors.

Input side of resister 5.28V high, 0.288V low
Output side of the resistor 5.52V high 0.528V low

Delta ~ 0.24V across 1 Ohm resistor. = ~ 240ma

Using the volt meter at 50% duty cycle 11.9mv, Sqrt(0.5) = 0.707

240ma seems kind of high but not unreasonable.
Not sure I understand what to do with the sqrt of D term 0.707.

And may I trouble you to answer why the scope has a problem and the volt meter does not. It seamed kind of weird to me just connecting the positive leads from the scope and letting the negatives get connected to nothing.

Does 240ma sound reasonable. I diden't think an Arduino could run that high.

I have a discrepancy between the voltmeter and the scope. It seams that for a 50% duty cycle PWM signal the RMS voltage should be exactly 1/2 of the peak voltage. That would give me about 24 mV peak about 1/10 of the scope readings. What am I doing wrong?
 
Last edited:

Irving

Joined Jan 30, 2016
3,845
240ma seems kind of high but not unreasonable.
Seems very high to me; a logic input would be <5v and less than a few milliamps. Maybe you're overdriving it; Are you sure its spec'd for a >5v input? and 5v relative to what?

Not sure I understand what to do with the sqrt of D term 0.707.
Vrms = √D x Vpk, ie a 5v square wave is ~3.53v rms - ie sqrt(0.5 x 0 + 0.5 x 5^2).
So 5v @ 25% PWM = sqrt(0 x 0.75 + 0.25 * 5^2) = 2.5v rms, and
5v @ 75% PWM = sqrt(0 x 0.25 + 0.75 * 5^2) = ~4.33v rms.

And may I trouble you to answer why the scope has a problem and the volt meter does not. It seamed kind of weird to me just connecting the positive leads from the scope and letting the negatives get connected to nothing.
That's because they aren't positive and negative, but signal and ground. The ground side, in an AC powered 'scope, is connected to mains protected earth as is the ground (-ve) side of your bench supply (or USB feed to the Arduino), so the ground connections of the probes are, near enough and at low frequencies, the same potential as your Arduino ground. That why your PMW stops when you use a single probe and its ground connection across that resistor. Its crucial to understand this ground aspect as connecting the ground side of the scope to something that isn't ground can be highly destructive and physically dangerous. A classic beginner's mistake is connecting a 'scope probe to the -ve DC side of rectified AC mains while testing the internals of a switch mode power supply (SMPS). But -ve DC isn't ground, its approx -150v below ground. So bang goes the scope probe and, if you're very unlucky, the input amp of the 'scope and possibly some components in the SMPS. This is an expensive mistake you only make once... To do ths sort of testing you need a 1:1 mains isolation transformer (so that the system under test can 'float' relative to ground) or a high-voltage differential probe, ideally both.

I have a discrepancy between the voltmeter and the scope. It seams that for a 50% duty cycle PWM signal the RMS voltage should be exactly 1/2 of the peak voltage. That would give me about 24 mV peak about 1/10 of the scope readings. What am I doing wrong?
A true RMS test meter will read correctly whatever the waveform shape whereas a cheap one is only usually correct for sine waves. Its possible your test meter is not up to the job - what model is it? Try using the AC volts range?
 

Thread Starter

MB107

Joined Jul 24, 2016
345
Seems very high to me; a logic input would be <5v and less than a few milliamps. Maybe you're overdriving it; Are you sure its spec'd for a >5v input? and 5v relative to what?


Vrms = √D x Vpk, ie a 5v square wave is ~3.53v rms - ie sqrt(0.5 x 0 + 0.5 x 5^2).
So 5v @ 25% PWM = sqrt(0 x 0.75 + 0.25 * 5^2) = 2.5v rms, and
5v @ 75% PWM = sqrt(0 x 0.25 + 0.75 * 5^2) = ~4.33v rms.
So I have to make some assumptions in order to get this equation to work. Main question is you have a 0 multiplier in there that doesn't seem to effect the results in this case. This is the way I understand it.

1639935044031.png
So that makes sense in that it is in the operational range of the Arduino outputs of 40ma max 20ma recommended. You feel this is a bit high but keep in mind this is a used fan pulled from a junk yard. The values of 240ma I got with the scope still do not make sense.


That's because they aren't positive and negative, but signal and ground. The ground side, in an AC powered 'scope, is connected to mains protected earth as is the ground (-ve) side of your bench supply (or USB feed to the Arduino), so the ground connections of the probes are, near enough and at low frequencies, the same potential as your Arduino ground. That why your PMW stops when you use a single probe and its ground connection across that resistor. Its crucial to understand this ground aspect as connecting the ground side of the scope to something that isn't ground can be highly destructive and physically dangerous. A classic beginner's mistake is connecting a 'scope probe to the -ve DC side of rectified AC mains while testing the internals of a switch mode power supply (SMPS). But -ve DC isn't ground, its approx -150v below ground. So bang goes the scope probe and, if you're very unlucky, the input amp of the 'scope and possibly some components in the SMPS. This is an expensive mistake you only make once... To do ths sort of testing you need a 1:1 mains isolation transformer (so that the system under test can 'float' relative to ground) or a high-voltage differential probe, ideally both.
Not quite sure I understand all this but it will give me an idea of where to research. I'm sure there are plenty of videos available on it.

A true RMS test meter will read correctly whatever the waveform shape whereas a cheap one is only usually correct for sine waves. Its possible your test meter is not up to the job - what model is it? Try using the AC volts range?
I do not have a true RMS meter. It is a higher end automotive DVM Innova 3340a but definitely not true RMS. I get the same readings with my $10 harbor freight unit. I will give the AC range a volt rage a try. And possibly I know someone with a true RMS meter.

As far as the input requirements to the fan, I have seen Mercedes techs say on the web that the Mercedes fan requires a 4.7 minimum voltage. I cannot find that in any of the publications but I have driven this fan with a wave form generator and have verified it to be true. I have also driven this fan using the waveform generator up to 15V. It runs the same at 5V as it does at 15V. But in all cases the floor voltage need to be below 1 volt. This kind of information is very hard to get and consequently people are running the fan anywhere form 5 to 15 volts. But no reports of reliability. As far as I know, I am the only person driving it directly off the Arduino PWM output. Sure I have been running the fan for 30 seconds or so, but need a reliable solution for a 5 hour road trip through the desert. So if the current draw is really 16ma, I should be good for the RoboRed or the Arduino Uno. But the intent was to use a 3.3v nano with a 15ma recommended PWM output. That puts me on the edge in that the 3.3V nano would require the opticoupler just for the voltage difference. There is a 5V nano but with the same 15ma recommended output at this point appears to be marginal.

Thank You very much. You are very knowledgeable and informative.
 

BobTPH

Joined Jun 5, 2013
8,816
Are you sure you oscilloscope was not set for a 10X probe while using a 1X probe? If that is the case, it would be 24mA instead of 240.

Bob
 

Irving

Joined Jan 30, 2016
3,845
The values of 240ma I got with the scope still do not make sense.
Were you using x1 probes on a x10 setting? You could try a bigger resistor. Use a 1k. If its a 'logic' input it'll still work. The other thing to check is what voltage and current, if any, comes out of the fan's PWM input when its not connected to the Arduino? If its pulled up to 12v, even via a big resistor, then that invalidates the scope reading and would also explain why its >5v anyway.

Not quite sure I understand all this but it will give me an idea of where to research. I'm sure there are plenty of videos available on it.

That puts me on the edge in that the 3.3V nano would require the opticoupler just for the voltage difference. There is a 5V nano but with the same 15ma recommended output at this point appears to be marginal.
I'd use an optocoupler anyway. Automotive environment are full of high transient voltages and spikes that are deadly to an MCU!
 

Thread Starter

MB107

Joined Jul 24, 2016
345
Are you sure you oscilloscope was not set for a 10X probe while using a 1X probe? If that is the case, it would be 24mA instead of 240.

Bob
I don't think this scope has the capability of scaling the input. I have probes switchable from 1X to 10X but I did verify they were on 1X. Also I'm trying to measure across the resister, Im doing that by math and get to see the output of each channel both are running at ~ 5V if my scaling was off they would both be 50V. It almost seams like there is a DC shift between probes 1 and 2. There again this is a cheep digital 8 bit $500 4 channel scope. Insteck GDS1054B. I am reading the input signals as DC coupled. Other two options are AC coupled and Ground. I'm not sure what the difference between DC coupled and Ground is, sounds like both will give me a common reference point so I will give it a try.
 

BobTPH

Joined Jun 5, 2013
8,816
Use channels 2 and 3 and press the math button and choose - This will show you the difference. Your scope almost certainly will scale for the probes. Not sure how to set it though.

Edit: If it is like my Rigol, press the CH button for the channel and you will get a menu that allows you to set the probe to 1X 10Xor 100X, among other settings.

Bob
 
Last edited:

Thread Starter

MB107

Joined Jul 24, 2016
345
Were you using x1 probes on a x10 setting? You could try a bigger resistor. Use a 1k. If its a 'logic' input it'll still work. The other thing to check is what voltage and current, if any, comes out of the fan's PWM input when its not connected to the Arduino? If its pulled up to 12v, even via a big resistor, then that invalidates the scope reading and would also explain why its >5v anyway.
1K or 470Ω resisters will not work. 330Ω or smaller will work. With the 330Ω resister measured voltage across the resister is 2.936 VDC and 0.2VAC. No voltage comes out of the fan control PWM input signal with it disconnected from the Arduino.



I'd use an optocoupler anyway. Automotive environment are full of high transient voltages and spikes that are deadly to an MCU!
Yes on the opticoupler. My feelings exactly.
 

Thread Starter

MB107

Joined Jul 24, 2016
345
Use channels 2 and 3 and press the math button and choose - This will show you the difference. Your scope almost certainly will scale for the probes. Not sure how to set it though.

Edit: If it is like my Rigol, press the CH button for the channel and you will get a menu that allows you to set the probe to 1X 10Xor 100X, among other settings.

Bob
I found them they are set to 1X

I think I figured out the math looks like with the 330Ω resister in place at 50% Im getting 2.64V with the signal high and 4V when the signal is low. so 4.00/330 = 0.012 = 12ma. That's much closer to the 15.4 ma derived using the DVM. I bet if I tried to check the DVM with the 330Ω, I might come closer.


P1030349.JPG
 

Irving

Joined Jan 30, 2016
3,845
You need to set, when disconnected, the 0v level of both CH1 (yellow) and CH2 (blue) to be the same and also the volts/div at 2v/div and then connect to the load resistor,#1 to the Arduino end. As far as I can see the yellow trace (#1) zero level is set to be at 1.6v on screen and 2v/div, giving 0 - 4.4v, and the blue trace (#2) zero level is off the bottom of the screen and at 1v/div its apparently varying between approx 3.3v and 7v (assuming 0v is just off screen). Assuming #1 is drive side and #2 is the fan side that suggests there is a pull-up inside the fan and the Arduino is sinking >= 3.3/330 or 10mA when pulling down and is being pulled up by a (12-3.30)/0.01 = 870ohm approx resistor internal to the fan.
 

Thread Starter

MB107

Joined Jul 24, 2016
345
You need to set, when disconnected, the 0v level of both CH1 (yellow) and CH2 (blue) to be the same and also the volts/div at 2v/div and then connect to the load resistor,#1 to the Arduino end. As far as I can see the yellow trace (#1) zero level is set to be at 1.6v on screen and 2v/div, giving 0 - 4.4v, and the blue trace (#2) zero level is off the bottom of the screen and at 1v/div its apparently varying between approx 3.3v and 7v (assuming 0v is just off screen). Assuming #1 is drive side and #2 is the fan side that suggests there is a pull-up inside the fan and the Arduino is sinking >= 3.3/330 or 10mA when pulling down and is being pulled up by a (12-3.30)/0.01 = 870ohm approx resistor internal to the fan.
I think I got it. All scales the same at 2V/div and zeroed.

P1030350.JPG


P1030351.JPG
 

Irving

Joined Jan 30, 2016
3,845
OK that's much better.

So now we can see what's happening...

When the Arduino (yellow trace) pulls down to 0.25bv approx we have the fan input (blue trace) at 4v approx, and when its high, slightly over 5v, the fan trace is around 7.5v. Now an Arduino output cannot normally rise above 5v unless an external circuit pulls it up and thats exactly what you're seeing on the scope. The likely equivalent circuit is shown below; simple trial and error gives 680ohm, a standard value, as the pull-up resistor. Now this makes a lot of sense. In the automotive world very few circuits work by voltage levels; the vast majority use current sensing as its more immune to noise AND its fail-safe - an open circuit is easy to detect. Almost all signalling is done by 'pull down to ground' with a switch, a transistor or a MOSFET. The red trace shows the current in the pull-up resistor and I'll bet this is what the PWM circuit in the fan actually detects - which is also why it needs something below a 1k resistor to work.

1640011597312.png


If I'm right, then the circuit below will work perfectly...

1640013607061.png
 

Thread Starter

MB107

Joined Jul 24, 2016
345
OK that's much better.

So now we can see what's happening...

When the Arduino (yellow trace) pulls down to 0.25bv approx we have the fan input (blue trace) at 4v approx, and when its high, slightly over 5v, the fan trace is around 7.5v. Now an Arduino output cannot normally rise above 5v unless an external circuit pulls it up and thats exactly what you're seeing on the scope. The likely equivalent circuit is shown below; simple trial and error gives 680ohm, a standard value, as the pull-up resistor. Now this makes a lot of sense. In the automotive world very few circuits work by voltage levels; the vast majority use current sensing as its more immune to noise AND its fail-safe - an open circuit is easy to detect. Almost all signalling is done by 'pull down to ground' with a switch, a transistor or a MOSFET. The red trace shows the current in the pull-up resistor and I'll bet this is what the PWM circuit in the fan actually detects - which is also why it needs something below a 1k resistor to work.




If I'm right, then the circuit below will work perfectly...
Hello Irving

I see you must have found my how to make the opticoupler work thread. I just came here to ask if you wouldn't mind joining that discussion but here you are. Anything you can do to help would be appreciated.

Once again many thanks.

I tried your suggestion in a building block approach. I tried the baseline configuration with no resistors. Then I added the 330Ω resistor to the input side only. Then another 330Ω resistor to the output side followed by a second 330Ω resister to the output side. I had to use 2 330's to get as close as I can to 680.

Results are as follows. Note I have the yellow cable of the scope on the Ardrino side and the blue cable on the fan side. Also not that in each trace the signal input to output is inverted.

Baseline No Resistors
Input 100mv to 4.98mv
Output 6.1V to 13.2V

330Ω resister on input only
Input 200mv to 4.38mv
Output 9.48V to 13.1V

330Ω resister on input and 330Ω on output
Input 300mv to 4.48mv
Output 9.6V to 13.1V

330Ω resister on input and two 330Ω resisters in series (660Ω total) on output
Input 200mv to 4.28mv
Output 9.61V to 13.1V
 

Attachments

Irving

Joined Jan 30, 2016
3,845
Ah, I think you missed my point. The pull-up resistor must already exist inside the fan, you don't need to add anything externally...

If you put a 330ohm resistor from fan PWM input to ground - nothing else connected - and power up the fan, what voltage do you measure across the resistor?
 

Thread Starter

MB107

Joined Jul 24, 2016
345
Ah, I think you missed my point. The pull-up resistor must already exist inside the fan, you don't need to add anything externally...

If you put a 330ohm resistor from fan PWM input to ground - nothing else connected - and power up the fan, what voltage do you measure across the resistor?
If I'm understanding you right, you mean as I have done in the attached files.

Very similar to what I did to find the current through the biggest resistor that would run in series with the fan. So what I got was:

240mv to 5.16V on the input side (arduino side) of the resister (yellow)
3.84V to 7.48V on the output side (fan side) of the resistor (Blue).

Delta V low = Vin - Vout = -3.6V
Delta V high = Vin - Vout - 2.32V

Whats interesting about this is the voltage seen by the fan is 3.84V to 7.48V and the fan runs. If I just took my wave form generator and set it up to 3.84 to 7.48 square wave, I don't believe it would run.
 

Attachments

Thread Starter

MB107

Joined Jul 24, 2016
345
Ah, I think you missed my point. The pull-up resistor must already exist inside the fan, you don't need to add anything externally...

If you put a 330ohm resistor from fan PWM input to ground - nothing else connected - and power up the fan, what voltage do you measure across the resistor?
Hello Irving

I find I need to apologies as I have mis led you on something. I believe the question was asked if I disconnect the fan and measure the voltage at the fan wire what is the voltage and I reported zero. It turns out it's 13.8V. Unfortunately I only discovered that when I was measure it with a scope and then discovered I had my DMV leads plugged in to the current sockets. This actually makes me feel a lot better about the opticoupler. When its off it's passing the fans normal 13.8V. When its on its pulling the fan voltage down to the 5V level of the source.

Sorry for the confusion.
 

Irving

Joined Jan 30, 2016
3,845
Hello Irving

I find I need to apologies as I have mis led you on something. I believe the question was asked if I disconnect the fan and measure the voltage at the fan wire what is the voltage and I reported zero. It turns out it's 13.8V. Unfortunately I only discovered that when I was measure it with a scope and then discovered I had my DMV leads plugged in to the current sockets. This actually makes me feel a lot better about the opticoupler. When its off it's passing the fans normal 13.8V. When its on its pulling the fan voltage down to the 5V level of the source.

Sorry for the confusion.
That's exactly what I was expecting. And if you do pull it down to ground using the current range on the multimeter what current do you get? I'm expecting about 20mA.

This is why its not a good idea to drive the fan input direct from the Arduino. When the Arduino output is high the fan is pulling it up to 13.8v and the only reason the Arduino output is just over 5v is the catch diode in the Arduino is clamping it to the 5v rail, as shown in the diagram below, which depicts a typical CMOS output stage driving the fan input. The danger is that if there's a big spike on the 13.8v rail that can have a detrimental impact on the internals of the Arduino. A transistor would remove that issue, but complete opto-isolation as per post #14 is the best protection.

1640102541668.png
 

BobTPH

Joined Jun 5, 2013
8,816
You need to connect the opto coupler collector to the blue wire and the emitter to ground.

and you need to connect the optocoupler anode to Arduino +5V and cathode to the Arduino GPIO.

Now, whe the GPIO is high, the opto is off and the blue wire is pulled up, so high. When the GPIO is low, opto is on so blue wire is pulled down.

This assumes the opto can sink the required current, which we still don't know.

Bob
 
Top