Measuring Single-Ended PWM Motor Current...

Go To Last Post
30 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm working on a small brushed DC motor project. This project will be sporting the Mega168, running at about 1MHz, using the internal oscillator for the prototype.

The motor drives a small pump, triggered by a pressure switch monitoring the differential pressure of a moderately sized blower.

While I'm thinking that I don't really need to measure motor current, I'd like to monitor it and back off the PWM at a certain trip point.

I'll probably use one of the newfangled Allegro Hall sensors devices - which I have several in the parts bin.

My thought on this is to measure the motor current during the high time of the PWM drive signal. I'm thinking that I could connect the PWM output signal to a near by digital input and use that to tell the controller when the PWM output was high. This signal would then be monitored and used to synchronize the start of the ADC measuring the Hall analog current monitor.

While this will probably not work well for very short PWM high times, it should allow the bulk detection of motor over current during the PWM high time, I think.

Any thoughts??? Is there a better way?

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmmm... How much does the inductance of the motor smooth out the current at your PWM frequency?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Microcarl

I'm here in Cinci, so this must be the motor capital....My first AVR project was a bidirectional DC motor drive, using pwm. You might drive the motor on the low side, which is much easier (pwmming the gnd). If you only need rough current meaurements, the fet on resistance can act as a poor man's current sensor. Just an op amp & feed it into your a/d.
Works quite well, though I was running 40 amps.

I put a few other tricks in there that really souped up the performance.

Hoyt

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Some of the stepper motor drivers use a current sense resistor in the ground leg of the half-H winding drivers, then RC lowpass that (mostly for spike reduction, faster than the L/R load time constant).

While this is a small voltage and very near ground, its not that hard to amplify and it ought to be cheaper than one of those fancy Hall Current Sensors.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the replies.

I'm not committed to anything, as yet. I've only got a prospective schematic drawn up, so everything is quite fluid at this time. The major requirement for this project is size. The PCB needs to be 1" x 1.5" x 0.5". So everything must fit in this area, minus the motor ans pressure sensor, and it must be realized with a single-sided PCB - by client requirements.

I'm not so much interested in the technology of measuring the motor current, as I am the technique. I was hoping that I could measure the real time motor current while the power was actively being applied, and not an average form of it. This part is not a customer requirement, but a matter of my own experiment and learning experience.

As I have posted in the past, I had been developing a closed-loop servo motor controller some months back that was shelved for other priorities. I was hoping to use this new project to gain some insight as to whether or not I can measure instantaneous (PWM cycle by PWM cycle) motor current and apply my findings to the closed-loop servo motor controller that I hope to pick back up very soon.

Again, thanks for your input.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Carl, if you use direct PWM it is indeed hard to measure the motor-current while PWM is high. I suggest to make a small SMPS, using that very same PWM, and then it's quite simple to measure the motorcurrent. It will still be very responsive, assuming you use a 20 kHz or more for the PWM. The implementation depends of course on voltage and current specs of the motor. Can you share that ?

Nard
(working on the repair of the recordplayer: motor starts running @ 1.4V and 30 mA ..... different scale huh ?)

A GIF is worth a thousend words   She is called Sylvia (2018), lives at Mint18.3 https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nard,

The acronym "SMPS " eludes my understanding. I don't (or cant reason out) what this means.

But the motor is specified at 12VDC @ 0.3 Amperes. It's certainly not a sizable motor at all, compared to say, 5, 10 or even 20 Ampere motors that I've worked with in the past. And all of those were open loop and used no type of current monitoring - simply blind control - save the closed loop system that I've been working on, targeted at my Table-Top mill. .

While this clients needs does not require closed loop, nor is there any specific request for current monitoring/limiting, I'd like to at least add some protection, as it is supposedly being designed to perform some sort of critical control of an industrial "Something-or-Other " requiring corrective response from the device I'm designing.

The specification from the client are adequate to build his specific requirements. I just don't think he's thought through anything having to do with fault notification and any possible corrective action that could be required.

Other then what I've already explained above, I have not been told what the actual end application is. I've only been told that I need to design a control that starts a small pump that will run for up to 5 minutes when triggered into operation by a pressure sensor that is monitoring the differential pressure of some sort of exhaust blower.

EDIT:
Design specifications:
1. The controller will operate directly off of a 3V3 lithium coin (CR2032) battery.
2. The design needs to operate for at least 30 days, from a single battery.
3. Battery replacement at 30 days is a scheduled maintenance activity.
4. The pump motor will be powered from a secondary 12VDC power source.
5. The design will start a pump motor when triggered by the actuation of a differential pressure switch.
6. The pump motor will run for a maximum of 5 minutes.
7. The trigger is edge sensitive - meaning that the pump motor will come on only when the blower motor initially starts, and when the 5 minutes have timed out, the pump motor will turn off - and remain off until the blower goes through a complete turn-off and turn-on cycle.
8. The design must have a watch-Dog that ensures that the pump motor turns off within the given time interval - precluding the use of a simple NE555 timer for the On-Time control for this project.
9. The design must have a "Device Operational " indicator in the form of a pulsing LED at 5 to 10 second intervals - also precluding the use of an NE555 timer.

True, this could be accomplished with a couple of NE555 timers, but a Mega48/88/168 controller will cover all of the requirements, with a tremendous room for expansion.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

Last Edited: Sat. Sep 6, 2008 - 04:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm with you on keeping an eye on motor-current. Especially with a pump (rush-in current)

SMPS: sorry for that .. :oops: Switched Mode Power Supply that is.

3.6W, that's feasible for a small sized SMPS on the limited boardspace. But because the current is so low, you may need to a few windings to get a proper reading from the Hall-sensors.

A GIF is worth a thousend words   She is called Sylvia (2018), lives at Mint18.3 https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You probably use a transistor to power the
motor via PWM. You could use a
current-sense-resistor of say 0.5 Ohm in
the emitter (source) connection. Filter the
voltage across this resistor using an RC filter
to smooth out the PWM, so that you get
a mean-motor-current reading. That will probably be
good enough. At 0.3A with 0.5Ohm you get 150mV,
use a low reference voltage for the AVRs ADC
and I think that should work.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Adding to what ossi said above, if you leave out the RC filter (or use a very small one - recommended - to get rid of the noise from the brushes) you'll get the real time current you are looking for. Now it is a matter for the ADC and then you have to do the filtering digitally in code to get the mean value.

You should sample the current sense input fast enough so that the ADC can track the variations (including peaks) - the waveform will not be a clean DC level, but then you already know that.

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've posted a schematic of what I've discussed.

I tried to post the attachment using 640x480 resolution, but the detail looked like crap. Sorry for the excessive size.
The final component values have not been fully decided upon, as of yet.

Comments welcome.

EDIT:
Update schematic to reflect suggestions.

EDIT:
One more time...

Attachment(s): 

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

Last Edited: Wed. Sep 10, 2008 - 01:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What's the PWM frequency? IMO the 10K/0.1uF filter time constant is a little high for the real time current waveform you are going for. Great for the average value, though.

You have connected analog and digital grounds together at the uC. Is that deliberate?

10K seems a little high for the MOSFET drive. (R7). Is that deliberate too, to reduce switching transients/ slow down rise time of the current, etc.? Otherwise I would use about 50 ohms; not more than 1K.

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With 3V3 as supply-voltage you should select
MOSFET with really small gate-threshold. So a
logic level type is required. But since you need
only low current that will be no problem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ossi,

I'm just a bit disappointed here, as this will be the second time I'm writing a response to your two posts.
I hit the submit button, and all I got was some sort of error message. So I'll give it another try.

I don't yet know the PWM frequency, as I don't yet know how long it will take to perform a single ADC conversion using the internal 8MHz/8 clock.
As such, I don't know the ADC divider, either. I'll figure that out at the next opportunity - that would be when I actually get off my lazy but-tux and get it done.

For the FET driver, I have some 5A HEXFET drivers that I used in my last project, in a full H-Bridge configuration. They drove two solenoids in a latching relay rated at about 0.75 Amperes each.
I drove those FET gates comprising the H-Bridge with 10K Ohm resistors, without issue.
I'm thinking I should be fine. If not, I can work out that issue at hardware debug - same for the RC of the PWM read-back filter.

I don't have a problem connecting the analog & digital GNDs together, as I've always done it this way - with the common connection point at the point where power & GND comes onto the PCB.
As always, each GND will have their own separate main trace back to their respective power source. I'll then connect a much thinner reference trace between the two.

In fact, I'm not sure what the ramifications would be, if the AVR analog & digital GNDs were totally and completely isolated GND systems.
What does this look like, internal to the AVR. Would they truly be isolated? Or are the analog & digital connections brought out of the AVR separately, only for PCB board level noise control?

Anyway, Ossi, Ill look into these things as I start PCB development.

Thanks for your input.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think the same thanks go to emuler also.

Sometimes I also have problems in submitting
replies. I often paste my answer if it is long, just
to be save.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I don't have a problem connecting the analog & digital GNDs together, as I've always done it this way - with the common connection point at the point where power & GND comes onto the PCB.
As always, each GND will have their own separate main trace back to their respective power source. I'll then connect a much thinner reference trace between the two.

That is fine; :D you just haven't drawn it that way in the schematic. ;)

Quote:

In fact, I'm not sure what the ramifications would be, if the AVR analog & digital GNDs were totally and completely isolated GND systems.

I don't think they can ever be totally isolated. They still have to remain within the absolute maximum ratings, don't they?
Quote:

only for PCB board level noise control?

That seems more likely. There will be similar considerations inside the chip, of course, but nothing very fancy.

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Considering a one month operation on a small battry, you may even need to consider to leave out PWM at all .... and just turn on the motor full ..
Ah well, you know the drill.

Nard

A GIF is worth a thousend words   She is called Sylvia (2018), lives at Mint18.3 https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Carl,

My $0.02 ... (and worth every penny of it!)

You show the voltage on J1-3 as minus 12 V ... probably typo.

R4 is shown as 10K for current setting of your LED running off 3V3 ... I don't think anyone will ever see that light level. I would look at driving the LED off your motor 12 rail and use a NPN to switch it if you can spare the real estate.

Also I think that your 20K values for R2 and R3 might be a bit current thirsty. Especially with your target month operation. The exact value read by the ADC is not important (I assume), so using 100K pots will save you current but still achieve range adjustments. You might even consider placing the pot between a couple of extra resistors and limit your range of adjustments and lower the current further.

Cheers,

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Help teach an old dog new tricks:

I've been following along, but haven't added anything as I have no experience driving motors, and very little experience with MOSFETs.

That said, I have a question about the above circuit, if this doesn't constitute hi-jacking Carl's thread.

I believe there are two separate power sources, a 3 V supply for the uC, and a 12 V supply for the motor. I believe that these two do NOT share a common ground. The schematic shows the Mosfet Source tied to the 12 VDC Common (12 V supply's "Gnd"). The Mosfet's source also ties to R8, then to the 3 V ground.

The grounds can't be tied together, otherwise one would short out R8, and the I-Sense voltage would be 0 V.

I believe that the 12 V supply feeds current through the Pump Motor, then into the Mosfet Drain, out its Source, and out the 12 VDC Common back to the 12 V supply. This motor current doesn't flow through R8.

If the Mosfet has a very high input (Gate) impedance, then very little current will flow into the Gate and out the Source to the 3 V ground, generating very little I-Sense voltage.

So, what is the expected I-Sense voltage level?

Clearly I'm missing how this circuit works. Any guidance would be appreciated.

Sorry for Hi-jacking Carl's thread, but Motor Control is on my list of things to learn.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nice catch, Doc. :D Yes, the way the 12V supply has been hooked up, the motor current will never flow through the sense resistor. The 12V common has to be connected to the other side of the sense resistor, ie. GND.

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

emuler wrote:
Nice catch, Doc. :D Yes, the way the 12V supply has been hooked up, the motor current will never flow through the sense resistor. The 12V common has to be connected to the other side of the sense resistor, ie. GND.

Ah, yes! Isn't that an interesting mistake I missed? I added the sense resistor later in the design, and then forgot to move the 12VDC common.

The schematic has been updated for the LED current limiting resistor, as well as the 12VDC common reference.

Thanks guys!

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just made an estimate how much current the
device may draw:

CR2032 has 0.2Ah at my supplier.
30 days have 720 hours.
So allowed operational current (mean)
I = 0.2Ah/720h = 280 uA.

Two parallel 20k pots already result in 3V/10k=300uA !

Try to make power to pots switchable (connect
VCC side of POTs to a port).

How much current does controller draw ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ossi wrote:
I just made an estimate how much current the
device may draw:

CR2032 has 0.2Ah at my supplier.
30 days have 720 hours.
So allowed operational current (mean)
I = 0.2Ah/720h = 280 uA.

Two parallel 20k pots already result in 3V/10k=300uA !

Try to make power to pots switchable (connect
VCC side of POTs to a port).

I think I already stated the idea that I would drive the pots off of an I/O pin few posts up.

ossi wrote:
How much current does controller draw ?
The final version will probably be a Mega48P, sleeping until the pressure sensor wakes it up.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've posted the updated schematic and PCB artwork back on page 1 of this thread. Several things in the schematic were moved around to accommodate a simpler PCB layout. Shuffling things around, made possible a single-sided PCB layout - which is always one of the highest priorities when I lay out any PCB.

One of the trade-offs, be it very small, was that I'll have to bit-bang a PWM motor control, if ever PWM is actually required. But hey! There's all the time in the world with this project.

The smallest trace width is 0.01", while the largest trace width is 0.05"
The PCB is about 1.725" x 1.475" - well within the clients requirements.

I've been working on the schematic & PCB artwork all weekend. I'll sleep on it and do a final sanity check tomorrow. Hopefully, everything is as I planned. If not, it's a simple change at this stage of the design. If all is well, I'll fabricate the PCB blank and stuff them in the evenings of this coming week. I think I'll be able to comfortably get 4 blank PCBs out of a 4" x 6" blank copper clad PCB panel.

Any additional input is welcome, as always.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I think I already stated the idea that I would drive the pots off of an I/O pin few posts up.

Did you decide not to do this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

CirMicro wrote:
Quote:
I think I already stated the idea that I would drive the pots off of an I/O pin few posts up.

Did you decide not to do this?

Yes, it's there, which is the reason for 0R-1, just to the Lift of pot R3. I just forgot to change the schematic, which I'll do right now...

Thanks Mike for the pointer to my omission.

EDIT:
Ok, it's been updated, Mike...

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I finally got a PCB made and assembled. I was also able to setup the fuses on the first try.

I'm running a Mega168 on the internal oscillator/8, on a 3.0 volt CR2032 coin battery.

The small traces are 0.01" and the larger traces are 0.025". The PCB dimensions are 1.45" x 1.75".

Pictures are attached...

Check-out and test programming will begin tomorrow evening.

Attachment(s): 

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Carl,

Nicely Done!

Your expertise is evident, yet again!

I hope all goes well powering up the motor.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've added some extras onto this PCB. So after the functionality is codded, I'll be experimenting with adjustable current limiting.

But I'm sitting here rationalizing out the coding that I'll be doing over the next few days, and the basic operation is actually quite trivial - an input goes low, the motor starts and runs for 5 minutes, then shuts off. If the input remains continuously low for say, a 30 minute period, the motor re-starts and runs for another 5 minutes. The cycle repeats endlessly.

But the part that I'm having trouble getting up to speed on, is putting the thing to sleep and waking it up once a second to check the input and service the output. I've not done any work with any of the sleep modes, as yet. So I'm still a little intimidated by what might need to be done, and what I haven't though about yet. But I definitely need the sleep mode, if I'm going to get this thing to operate for 30 day periods between the scheduled maintenance events.

Oh well, like everything else, I'll figure it out - but it'll probably when I'm pushing a walker.

Thanks for the complement, Doc.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perhaps once every second is not long enough to give you much savings by way of power consumption. There is a time delay before the device wakes up fully and is ready for use. That alone will eat up a sizeable chunk of the 1000ms.

That said, the rest should be pretty straightforward.
Wake up.
Wait set number of cycles until the device is ready.
Do what you have to do.
Go back to sleep.

(btw. compliment)

P.S. Don't know much about the conditions this thing will be subjected to, but I would have recessed the main connector further back so the female part would rest on the PCB instead of hanging in mid-air. (Ignore this if the connector goes into a PCB and is soldered there).

Apart from that your PCB, as always, is a work of art. I'd rather watch those than see some dumb paintings in an art gallery.

If you think education is expensive, try ignorance.