How would I do a Back EMF measurement for a sort of crude cruise control?

premelec

Senior Member
@Joe Paul - schematic in #39 not right - the filter resistor goes to one end of capacitor - other end of capacitor goes to V- and then another series resistor goes to the first resistor to another capacitor to V- then that capacitor resistor 'upper' junction goes to ADC input- that's what BB had in mind...
 

AllyCat

Senior Member
Hi Joe,

Yes, the schematic in #39 is not correct and won't work. Also, note that electrically the 2 Rs and 2 Cs are exactly the same as a single 20k + 0.05uF in series.

The diagram in #28 is very probably "good enough", but do re-read exactly what I said in #23. Personally, I consider Thevenin's Theorem probably the second most useful concept after Ohm's Law. ;)

IMHO the suggestion by BB is not really relevant to your particular application, which I believe is a "trackside" speed controller that might control different motors/engines (at different times) ? BB's compensation method assumes that the motor resistance is "known", but it may not be if/when a different motor is used. And even the same motor may change resistance when the copper wire in its armature heats up. A trackside controller is unlikely to be able to (fully) take into account the temperature inside the motor/engine!

Too many cooks .......

Cheers, Alan.
 

joe paul

Senior Member
Hi Alan, Premelec, and Everyone,

I really appreciate the help!!!!!!!!!!!!

Thanks for the correction. I did put big question marks in red on the diagram because it didn't feel right, but I just am shooting in the dark. Is the following any good?



I don't know electrical theory. I have figured out certain things like transistors, MOSFETS, caps for filtering, diodes, and resistors, but that's about it.
(I am getting tendonitis with all this drawing with the mouse!) :)

In one application, it might be on-board, not just trackside. My fist step is to just get some numbers off of the motor. (The same motor is in most of these smaller items.) Here is what I am thinking: If I can get a reading under normal load then compare that to any increase in demand, I can make an assumption that the speed could be kicked up a couple steps, a crude idea, not precise, just yet. All I would need to know is if the number changes within a certain range.

Once I get some readings, I'll move on to the next step. Fortunately, I have a spare replacement motor (same motor in several things) I used when I first tried to get the PWM code working. So I will build another circuit on the readymade board with the HC-06 module, MOSFET, etc., the see if I can get the Bluetooth module to transmit back to the tablet. So far I only sent from the tablet to the board. Haven't done the SEROUT thing yet. As soon as I get some numbers off of the motor, I'll go from there. I just need a workable circuit for reading the ADC input.

Thanks again!

Take care, Joe.

P.S. I prefer not to have to stop the PWM to take a measurement, so that is why I am looking into BeanieBot's suggestion. J
 
Last edited:

edmunds

Senior Member
Hi Alan, Premelec, and Everyone,

Here is what I am thinking: If I can get a reading under normal load then compare that to any increase in demand, I can make an assumption that the speed could be kicked up a couple steps, a crude idea, not precise, just yet. All I would need to know is if the number changes within a certain range.
The problem I'm currently working with is that this great number is not so great - jumping back and forth a lot. So far I'm unable to find coefficients and math to interpret it so, that it would give good no load performance and acceptable performance under load. But I'm still fiddling :).

Edmunds
 

eggdweather

Senior Member
Hi Joe Paul, you need to move your PICAXE measurement point to the right (horizontally) so it's at the junction of the second 10K resistor/capacitor pair. The two R-C elements are low-pass filters, the first will filter the ripple out of the signal and the second will repeat it some more, giving you closer to a steady value to measure.
 

AllyCat

Senior Member
Hi Joe,

No, that won't work, you've "lost" the potential divider, so will measure nothing useful (ADC = 1023 most of the time, if the PICaxe doesn't die) !

First you need to decide if you plan to measure the back-emf (a voltage) or to compensate for the load current in the motor. Possibly, either method can be made to work, but not using the same circuit diagram.

IMHO to get these methods working needs a 'scope and reasonable understanding of the theory of operation of motors and generators. That's why I recommended the direct KISS method to measure/stabilise speed several pages back.

Cheers, Alan.
 

joe paul

Senior Member
Hi Alan,

Thanks for the correction!

O.K. Is my interpretation/schematic of BeanieBot's idea incorrect? I gather the diagram in post 28 is alright for back EMF. The idea from BeanieBot was not for Back EMF and was supposed to get a reading without stopping the PWM, if I understood correctly. Sort of kicking around 2 different methods at the same time to get some reading that possibly could be used to sense an increased load; I didn't think BB's circuit was supposed replace the one in #28, but rather be an alternative for a different kind of reading.

I guess I shouldn't focus on 2 different approaches at the same time. The idea for measuring the speed by the elapsed time between 2 points is still on the table; I will be using that also.

Thanks!

Take care, Joe.
 

edmunds

Senior Member
IMHO to get these methods working needs a 'scope and reasonable understanding of the theory of operation of motors and generators. That's why I recommended the direct KISS method to measure/stabilise speed several pages back.

Cheers, Alan.
You are certainly right, but both of these things are to be got from some learning or experience or both :).

I have been trying to scope my setup, but the only thing I get is a pwm pattern on my screen. How would you connect the scope and what settings to use to see the actual BEMF?

I have documented the numbers now and clearly, I need to stabilise my circuit electronically, before I do anything software. Besides the fact there is no linear relation between the Back-EMF of my motor to the RPMs (which is expected) there is no stability in measurement either. I get ADC numbers like 0 for duty cycle of 79 and 81 for 80, 139 for 89 and 17 for 90 even with average of 20 measurements, which is about the maximum I can take with the slowest pwm the motor is still turning.


Thank you for your time,

Edmunds
 

AllyCat

Senior Member
Hi,

@Joe: BB's method needs to measure the current in the motor, which typically would be done by inserting a low-valued resistor (perhaps 1 ohm) and measuring the voltage across it (then I = V / R). Strictly, the resistor needs to be directly in series with the motor, but that creates complications in getting the (rather small) analogue voltage accurately down to the PICaxe ADC input. Alternatively, the current in the FET could be measured and then mathematically corrected, from a knowledge of the PWM duty cycle. But ....

@Edmunds and Joe: Note that the original App Note (above) uses the same supply rails for the motor and the microcontroller (and the ADC can measure relative to the +Vdd rail). You have the problem that the motor is "hanging down" from the 12 volt supply rail, whilst the PICaxe can only work "up" 5 volts from ground. Normally, it's best to arrange the analogue signals (particularly if small) to be relative to the same rail (normally earth) as the ADC. That's because it's generally easier to transfer a switching signal (the FET drive) from one rail to another.

One solution would be to turn the output stage "upside down": That would use a P-channel FET on the +12 volt rail and a NPN inverter/driver (because the PICaxe pins cannot rise to +12 volts).

Alternatively, you could define the +12 rail as "ground" with the PICaxe hanging down from it. The PICaxe earth would then be connected to a -5 volt regulator (e.g. 7905) and the FET to the -12 volt rail (which was originally named ground). A PNP transistor then would be needed to couple the PWM drive from the PICaxe output pin down to the FET gate.

Don't forget that the DP (PCB) 'scope is connected/referenced to ground via your computer!

Cheers, Alan.
 
Last edited:

edmunds

Senior Member
Screen Shot 2015-04-03 at 23.44.12.png

My schematics is not the same a Joe's. See above. I have not updated it with the connection from Motor2 output to B.0 where I'm measuring BEMF. It literally does not matter if I add a cap or two, a resistor or two, or just connect it straight into the picaxe. The power is a single LiPo cell with 4.2V fresh to 3.8V discharged.

However, I'm sure we are working with basically the same problem. I tried various arrangements of filters, but with no success. I'm still getting values that go up and down too much. There is a clear pattern of "less when under load (turning slower)", but detecting when it starts to actually happen as compared to the "normal fluctuation of 100 this or that way" is a nightmare.

Reading more crazy complicated stuff about motors and iR Compensation. Need a lot of sugar :).


Thank you for all the help,

Edmunds
 

joe paul

Senior Member
Hi Edmunds,

Many thanks for all the attention you have given my many questions and for working this out. I hesitate to post the following because I don't want to muddy the waters or cause more problems, and certainly I don't want to cause confusion. Please ignore this if it is really off-base.

The page:https://sites.google.com/site/hobbydebraj/home/dc-motor-control-using-back-emf-sen

has this schematic:


The voltage divider is across the motor.

Perhaps it is an option?

Thanks again!

Take care, Joe.
 

AllyCat

Senior Member
Hi Joe,

Yes, that's another well-explained article and the circuit should allow you to evaluate the back-emf principle using a PICaxe (but I'd still recommend using at least a simple 'scope). Almost any low-power NPN can be used in place of the BC547, but the TIP needs to be a PNP with a current rating comfortably above the stall current of the motor.

Also, if you put a resistor of about 1 ohm in series with the lower connection to the motor, then you can monitor the motor current (e.g. for BB's method). But the voltage (which is proportional to current) will probably need low-pass filtering, perhaps with something like 10k (to an ADC pin) and 1 uF (from the ADC pin to ground).

Cheers, Alan.
 

joe paul

Senior Member
Hi Alan,

Thanks for the info! First thing I need to do is hook up some resistors, etc., off the MOSFET circuit and get some readings with my cheap multi-meter to prevent over-voltage. Then it is "fly by the seat of my pants" with the ADC!

Every approach is under consideration. Surprised to see so many forum members into the model trains! Is there a "working relationship" with the MERG group?

Take care, Joe.
 

BeanieBots

Moderator
Sorry for not getting back earlier.
You're getting there and AllyCat knows what I'm trying to explain.
Your diagram in post#53 is almost right.
As AllyCat says, you need to measure the CURRENT. You can do that as he suggests by fitting a low value resistor between the motor and ground.
The RC/RC arrangement you had in post#47 is correct for the input to the ADC but it needs to connect to the current measuring resistor.

So, what to do with the number you get back from ReadADC....

You are supplying the PWMout command with a "value" for the duty to get a certain speed.
When your motor see a load increase, the speed for that PWM duty value will slow down.
To get back to the same speed, you need to ADD an amount to the PWM duty value.

How much do add? You need to add an amount proportional to the current drawn by the motor (to compensate for the IR loss in the armature).
In other words, an amount proportional to the ADC value that you read from the current sense resistor.
How much you need to multiply (or divide) that number by will depend on the resistance of your armature and the value of the resistor.
As I mentioned before, if you add too much, it will go into a horrible oscillation (called positive feedback), if it's too small, the compensation will not be as good as it could be.
We could try and do the sums but I think that will be a painful process as there are still quite a few unknowns.

Just give it a try.
I don't know how much current your motor pulls but from the general conversation I get the impression it's about an Amp or so, so about 1 ohm for the sense resistor sounds about right.
 

joe paul

Senior Member
Hi BeanieBot,

Thanks for your help, but I am confused! So, am I correct that the diagram below is not complete?
You said: "The RC/RC arrangement you had in post#47 is correct for the input to the ADC but it needs to connect to the current measuring resistor."

Where do I place this current measuring resistor?

Another question up for grabs:

With the READADC10 command, I plan on using pin C.2 (which is an ADC pin) on the 18M2 chip. Do I need to define a "channel 1" or will the line
"readadc10 1,w1" be suffice?

Many thanks again to everyone!!!

Take care, Joe.
 

AllyCat

Senior Member
Hi Joe,

No, it's the diagram in #53 which needs to be modified or added to:

Put the "Current Sense" resistor in the lower side of the motor as I explained in para 2 of #54 and connect the input of BB's filter to the junction of the motor and the CS resistor. For BB's method you will probably need a higher PWM frequency and/or larger filter values, e.g. 1 uF capacitor(s).

For a M2 PICaxe, I believe you should use: READADC10 c.2,w1

Cheers, Alan.
 

joe paul

Senior Member
Hi Alan,

Thanks, but I am more confused. #53 is not my diagram or circuit; I only posted it because it shows a voltage divider across the motor as a possible option. I am going to try to figure some way to get some numbers off of this circuit and then I'll get back to everyone here.

Thanks!

Take care, Joe.
 

AllyCat

Senior Member
Hi,

But the diagram in #53 is the "proper" way to do it (i.e. with the motor towards ground and a "high side" switching Transistor/FET.

IMHO you will really struggle to get any "usable" measurements if using a "low-side" FET as shown in all the other diagrams.

Cheers, Alan.
 

fernando_g

Senior Member
I also second beaniebot's suggestion to use IR compensation....there is a reason why commercial DC motor controllers use it (whenever a proper tachometer is not available).

Back-EMF control is straightforward in theory, but has several caveats to implement properly. One of them is that the brush noise can create erratic behavior.
 

joe paul

Senior Member
Hi Folks,

Please indulge me here.

In the diagram below, if the motor is suddenly placed under a heavier demand, does the magnetic field at the head of the nail (point A) increase, decrease, or stay the same? This would be regulated DC, no PMW.



Thanks!

Take care, Joe.
 

premelec

Senior Member
Increase with load- however it's easier to measure current with a small resistor than a hall effect device though that can give you isolation - see Allegro hall effect measuring devices... so many ways to do the same thing! - Yes you could 'regulate' current by having a magnetically interrupting switch [more current opens feed to motor].
 

joe paul

Senior Member
Hi Premelec and Everyone,

I am not trying to disagree or ignore advice, I just don't understand these variations everyone has proposed or know where to put these components, but it seems obvious to everyone else here. I like the MOSFET circuit I have used because it also works well with the AC/DC open-frame old-school toy train motors that draw up to 18 VAC, so you can see why I think I found an ideal circuit. I don't have an electronics background; some things are just over my head. I WAS good with math and algebra, but that ship has sailed. I understand the Hall Effect devices a little and if I get some useful readings, I can work with that, perhaps. Don't want to take this in a different direction (not Back EMF) but if it works for me, it will be useful for others also. Imagine my frustration that after 7 pages of posts, I still don't know what I am doing or what will work without a new circuit design (with the MOSFET on top of the motor in the schematic).

Again, thanks everyone!

Take care, Joe.
 

premelec

Senior Member
@Joe Paul - too many words - schematics - I'm lost... concisely what are you wanting to do - at what current maximum, do you need to drive motor in forward, reverse and stop. Do you just want to get a job done or understand all the usual possibilities? I suggest an H bridge with resistor from the bridge to V- so you can measure forward and reverse current just looking at the voltage across this resistor which will roughly give you motor torque if not speed. I'm an advocate of trying stuff... with a current limited power supply so you don't burn stuff out when you make a mistake... Versatility of electronics can be interesting or frustrating... and basic principles [ohm's law...] must be understood...
 

edmunds

Senior Member
Start another thread consolidating the things you (we) already have learned about the subject? :)

Edmunds
 

joe paul

Senior Member
@Joe Paul - too many words - schematics - I'm lost... concisely what are you wanting to do - at what current maximum, do you need to drive motor in forward, reverse and stop. Do you just want to get a job done or understand all the usual possibilities? I suggest an H bridge with resistor from the bridge to V- so you can measure forward and reverse current just looking at the voltage across this resistor which will roughly give you motor torque if not speed. I'm an advocate of trying stuff... with a current limited power supply so you don't burn stuff out when you make a mistake... Versatility of electronics can be interesting or frustrating... and basic principles [ohm's law...] must be understood...
Hi Premelec,

Everything you asked I have already answered. Too many schematics and words? You're lost? I apologize!

My original topic line says it all.

I don't like the "hiccup" the motor does when I have to stop it for the ADC reading. So I will try a Hall Effect circuit then report back to everyone in a new thread. Fortunately the ADC and Serout works.

Thanks, everyone!!!

Take care, Joe.
 

premelec

Senior Member
Ok - I'm not clear why a motor running on PWMOUT would be affected by READADC... hope you get it working!
 
Top