motor current monitor

davidwf

Senior Member
For part of a circuit I need to monitor the current drawn by a small DC motor (about 2 Amps or so) and cut the output instantly when it exceeds a pre-set limit (about 5 Amps).....I intend to use a small (0.1 Ohm) resistor in series with the motor and feed the input into an ADC pin for comparison against a pre set value.

Unless anyone has a better idea, is there any way of speeding up the "step through" rate on the attached code as it takes a small but significant amount of time to react and I need it to be almost instant.

I am using a PIC 18X

thanks in advance
Dave Faulkner
 

Attachments

Last edited:

papaof2

Senior Member
Do you need to wait 2 seconds for the motor to come up to speed?

I would think more in terms of a fraction of a second.

Motor:
high 1
pause 200 ' ignore for 0.2 sec whilst motor starts & stabilises
'this pause may not be needed - just the timing pause in the b3 loop

for b3 = 1 to 50 ' loop 50 times
pause 800 'adjust to get one second per loop
readadc 2,b1 ' read motor current on ADC input 2 PIC pin 1 into b1
if b1>49 then '> 49 instead of >= 50
low 1 ' motor has stopped or exceeded pre set current limit so turn it off
exit sub
end if
next b3
low 1 ' failsafe to stop motor after 50 sec
return ' back to where you left the program

John
 

hippy

Ex-Staff (retired)
There's probably some in-rush current so perhaps the best technique is to track that until it peaks then declines ( with a timeout and too high trap in case it starts in a failed mode ) then go into normal monitoring mode.

Not sure I'd stop on the first over-current detection but then I'd sample many more times than once per second so the response would still be fairly quick. Stop on the first detected over-current and any glitch would stop the motor and that could be pretty hard to debug or determine.

An absolute fail-safe is acceptable but it's better to catch the over-current before it gets to thats everity if possible.

For maximum response time sample as often as possible, no pauses, and run the PICAXE as fast as it will go ( SETFREQ M8 ).

Code:
  SetFreq M8
  [i]Startup handling[/i]
  Do
    ReadAdc 2, b1
  Loop Until b1 > [i]N[/i]
  [i]Stop the motor[/i]
 

davidwf

Senior Member
Yes the initial delay is needed......my apologies as I should have explained its' use is for a combined curtain motor and lighting controller....when I've cracked it I will of course share it here !

The initial surge must be ignored otherwise the curtains will stop prematurely.....around 2 seconds seemed good from experimentation as the motor load stabilises once things are moving smoothly but it needs to STOP as soon as the curtains meet, any delay causes big problems with the mechanism and track.

My original circuit comprised of an op-amp to sense the current and capacitors and a 555 to delay it ......it worked reasonably well but was messy and the whole component count was in excess of 50, a PIC seemed the ideal replacement...and I am sure it will eventually work.

Thanks for the prompt reply
Dave F
 
Last edited:

BeanieBots

Moderator
How about some end of travel sensors?
Another (or possibly additional) option would be to use a comparitor on the current sensor and use it to trigger an interrupt on the PICAXE.
 

Ralpht

New Member
David,
Moving curtains actually puts a bit of a load on a motor and once it's speed has stabilised, that translates into a bit of inertia.

You mention that the motor must stop the instant the curtains are closed otherewise there will be big mechanical problems.

Ignoring any delays in the motor driving circuit and assuming the stop signal comes as soon at the curtains meet, (a perfect situation) there will still be a bit of an over run due to mechanical inertia. Will that cause mechanical problems?

If so, you had better start the motor stopping process a fraction before you need it to stop. This pretty well indicates some form of sensors as BeanieBots mentioned, either optical or mechanical/electrical (a limit switch). This is usually the easiest and more error free way to detect when a motor should stop.

Detecting a high current situation as the time to stop an operation, whilst a viable method, has a higher chance of failure than a simple position sensor. Higher current = more heat = shorter life = more likely to fail - usually at the worst possible time thanks to a certain Irish gentleman named Murphy.

You can over spec. the components to prevent them being over stressed etc but that is higher expense. Depends on your required trade off.
 

davidwf

Senior Member
How about some end of travel sensors?
Another (or possibly additional) option would be to use a comparitor on the current sensor and use it to trigger an interrupt on the PICAXE.
Thanks but travel sensors would involve wiring along the track - a definite no no....I like the idea of a comparator - it is the system I used before.....not sure how to create an interrupt though...I am new to PIC !
 

davidwf

Senior Member
Thanks RalphTeichel......

As stated I have been using an op-amp system monitoring the current through a 0.1Ohm resistor for several years and it works perfectly, the curtains do in fact stop instantly.
I agree with your surmise of inertia but the system uses a low voltage geared motor (200:1) and the track uses a fabric cord (it is a Swish Powerglide track).

The only reason I want to use a PIC is to also operate remote controlled lights and other systems off the same sensor...the PIC WILL provide the ideal solution in my case......and it is so much easier than loads of individual components !
 

BeanieBots

Moderator
Have a look at the command "setint".
You define a certain input condition, when that condition is met, (ie your comparitor trips), the program instantly jumps to a special subroutine. All variables are common so your interrupt routine will know everything your main program knows and can thus decide what action to take (if any).
Once the interrupt routine has completed, program control returns to where it left off.
Needs a little thought but not too difficult to implement.
Don't forget, we're always here if you get stuck.
 

Texy

Senior Member
Rather than sensing when the motor needs to STOP - ie, when its already too late, why not go back to your original idea and power the motor for a set time? Picaxe circuitry will still keep the component count down. You'd have to be clever if there are more states than the curtains being just either 'open' or 'closed', but you could keep a counter to remember the curtain positions.

Texy
 

hippy

Ex-Staff (retired)
To expand on Texy's idea - It maybe not practical in this instance, but where intertia is a problem with two colliding objects, use a timed period of fastest travel then slow down the winding motor as the collision becomes more imminent.

I have a VCR which does that so when stopping a fast forward or rewind there's no sudden slamming on of the anchors and no tape stretch. It seems to make some clever guesses as to when manual stops may happen so it slows down the motors at half hour, hour intervals and so on where it thinks the start of a program may likely be then speeds up again. When it's the same tape still in the VCR it remembers exactly where record and stop were pressed. The only thing it doesn't do which would be clever is to display the clock with time offest so if I hit stop/play at displayed "01:00" when it's slowed it's motor and stopped it will be exactly "01:00" on the tape position. Can't have everything I suppose. Seems odd to have such cleverness but not go all the way. Perhaps they ran out of code memory ?
 

BCJKiwi

Senior Member
There is also the mechanical option of a compressible bumper - attach to one curtain glide so it hits the other curtain glide when they come together.

If appropriately engineered, this will cause a steadily rising current which can be sensed and used to shut off before final impact.

combining this with the slow down before impact as suggested by Hippy would give a very smooth action and no stress.
 

davidwf

Senior Member
There is also the mechanical option of a compressible bumper
sounds good - I should have known YOU would come up with a smart and simple idea !
....any suggestions as to what to use though.....a piece of foam or sponge would be the obvious but it needs to be perhaps 20mm square by perhaps 50mm long.

ps fridge controller working perfectly thanks to your help

DF
 

davidwf

Senior Member
......... why not go back to your original idea and power the motor for a set time?
Texy
actually my original idea was not to power them for a set time - but I have in fact tried that and it didn't work at all well.... any slight voltage variation or drag on the track would mean they either wouldn't meet or they would crash before stopping.....I know this to my cost !

thanks for the suggestion anyway, it is interesting to see so many different ideas.

DF
 

davidwf

Senior Member
To expand on Texy's idea - It maybe not practical in this instance, but where intertia is a problem with two colliding objects, use a timed period of fastest travel then slow down the winding motor as the collision becomes more imminent.

I have a VCR which does that so when stopping a fast forward or rewind there's no sudden slamming on of the anchors and no tape stretch.
.....sounds like a Panasonic one to me.....if so then it actually reads the tape counter track (along the bottom of the tape) and the tape is only partially laced around the rotating video head so it "sees" the recording start index mark (about 15 seconds of tone).

I don't think a variable speed control would be suitable for this application - the motor is a geared 200:1 so the track tape itself moves quite slowly.

thanks for the idea though

DF
 

BCJKiwi

Senior Member
The bumper needed will depend on loading and how fast you need to stop.

To test I would start with a plunger and spring in a tube. You can fiddle with the spring rate (how stiff it is) and the length of the spring until you establish what works. There are two parameters;
1. the pressure developed on the spring to produce the current level you want to switch at - anything safely above the normal travel current to avoid false stops.
2. how far it travels after it is turned off.

A 'soft' and long spring will build the pressure slowly and provide plenty of travel - start there (the switch point - in terms of position along the track - will not be as precise as a stiffer spring). If the back of the tube has a screw in it you can effectively increase the pressure gradient and reduce the travel simultaneously - well not precisely but near enough for your purposes.

Once you have sorted this out then you can either make a permanent version, or find another material that will do the same job.

Happy to oblige with the fridge - can't bear to think of anyone's sports fridge not working to perfection!
 
Last edited:

Andrew Cowan

Senior Member
The only problem I can see with a bumber (eg a 5cm piece of foam), is that when compressed (maybe to 2.5cm), there will be a gap of 2.5cm between the two parts. Is this no good?

Andrew
 

Dippy

Moderator
Well I can tell you've never put curtains up the Andrew :)

You normally have a bit of curtain protruding in front of the leading glide thingy so that when they close there is a slight overlap of the material - so that neighbours can't peep in and see what your doing with your PICAXE.
 

Andrew Cowan

Senior Member
Fair point - I was thinking about the leading edge of the curtain, not the leading edge of the... er.. roller? hanging thing? (I'm not great on curtain terminology)
 

davidwf

Senior Member
Thanks for all the thoughts on dampers/bumpers etc....I think I will stick with the mechanical design of bumper that I have had for several years - i.e. nothing !
It has worked perfrectly, the inertia isn't that great as the speed is quite slow, the motor stops pretty much instantlly and nothing has got damaged or worn.
The track part is a commercial design (Autoglide) http://www.tracksandpoles.com/elec_autoglide.shtmlthey do a motor unit that is tailored to the task but it cost well over £150 hence my DIY approach of using this small geared motor (919D1481) [url]http://www.mfacomodrills.com/gearboxes/919d_series.html

DF
 
Last edited:

boriz

Senior Member
There is another mechanical trick that I have seen in various other applications. You may or may not be able to use it though, depending on your cord-take-up design.

Add some artificial ‘stretchiness’ to the cord. Some sort of tension-spring between your motor and your cord. Most of the time the spring remains fully contracted, but when the curtain gets to the end (or is fouled), the spring extends a little, spreading out the torque peak seen by the motor and reducing the physical stress on the mechanical linkages.

Replacing a short section of cord with a spring would work, but might not fit with your setup. Or you could mount the take-up drum with a sprung articulated suspension system (similar to a motorcycle rear wheel). Or mount the whole motor assembly using rubber spacers. Lot’s of options.
 

wapo54001

Senior Member
David,

I've been pondering a similar sort of question -- how to use a linear actuator with hard limits before reaching the in-built end-of-travel microswitches.

My thought was to use an 08M to measure current across a resistor exactly as you have planned, but with two differences:

1) Use a separate, dedicated 08M to measure current and cut power to the motor when a specified over-current situation is reached. When watching for the overcurrent, run it in a tight loop at 8MHz so that cutting current is virtually instantaneous. In your case, the curtain rope system should easily absorb the very short (small fraction of a second) overload period.

2) Use the 08M first to determine overload current based upon normal continuous current -- first measure and store the normal running current, then set the overload current trigger at some optimal multiple of the steady current. So if you use readADC10 and find that normal current is 830ma for example, then you could set overload to 830 x 1.5 or whatever multiple you want to use to catch the overload situation at the earliest possible millisecond.

The code could look like this:

1. start motor
2. wait 2 seconds
3. measure average current (take multiple measurements over an adequate period of time, maybe 20 measurements or more at 20ms intervals and then average them).
4. Calculate and store the overload current value which is continuous current times a predetermined constant.
5. start dedicated continuous loop monitoring of current, and break loop to cut power to motor as soon as measured current exceeds precalculated value. I would think that you could cut power within 20ms of reaching the end of travel.

BTW This may be a case where using such a small value resistor is not desirable -- calculate the resistor value to give you a useful voltage range for the readADC10, given whatever the voltage delivered to the motor while not detracting from motor performance.

Furthermore, reducing voltage to the motor will also reduce power, again possibly a good thing if your current motor & gear drive deliver far more power to move the curtains than is necessary to actually move them reliably. In my own case, I use a 10ish-ohm resistor to slow the actuator from 3-second full travel to 6-second full travel to meet my needs, and reap the added benefit of greatly reduced current draw.
 
Last edited:

davidwf

Senior Member
Motor:
high 1

for b3 = 1 to 50 ' loop 50 times
pause 1000
readadc 2,b1

low 1
exit sub
end if
next b3
low 1 ' failsafe to stop motor after 50 sec
return ' back to where you left the program

John
Am I wrong in assuming that, with this code (specifically the "pause 1000" bit), the program will only check the motor current about once a second for 50 seconds ? :confused:

I need it to check the current (read adc 2) as often as is practicably possible - i.e. continuously and respond immediately.

Can't quite see how though.....from what I am reading I can only increase the for / next loop to 255 times....I am wondering if I could use SETINT with a flag to perform a fast interrupt instead.....

Unfortunately this is currently beyond my abilities at present..

Thanks
DF
 
Last edited:

davidwf

Senior Member
...............This may be a case where using such a small value resistor is not desirable
I appreciate that a higher res value will give more voltage to play with but it will appreciably slow the motor down - it is geared at 148:1 and the final output shaft speed is around 160 rpm, reducing this means the curtains take too long to close.

DF
 

davidwf

Senior Member
Have a look at the command "setint".
I just re-read the thread and saw your suggestion (post #9) to use SETINT - as in my post #24...perhaps I am picking some of this up after all !

Any clues as to how can I use setint to monitor the adc voltage.....I had a look through the manuals but the examples seem to point to setint looking for a specific action to happen

Thanks
 

hippy

Ex-Staff (retired)
Unfortunately this is currently beyond my abilities at present..
Don't lose heart and don't fall into trying to over-complicate things to get a solution.

You already have a circuit which determines the current has increased and I expect that the output of that can be interfaced to a PICAXE, what's best is it's tested and worked.

Take the circuit you have and determine ( or ask others to determine ) what can be taken out and be replaced by a PICAXE. Then it's a case of moulding a PICAXE program to fit in the middle. After that it may be possible to remove more of the circuit and bring that into under softwrae control.
 

davidwf

Senior Member
Hippy:

Heeding your advice I have started a new post entitled "Curtains and Lights controller" and have included cct diagrams and my PIC listing so far....

thanks
DF
 
Top