Reasonable way to detect motor direction in micro - Page 1
Forum section: electronics / beginners

author: akschu
author_rank: Newbie
timestamp: June 11, 2023, 10:51:56 pm
content: Hello All,I'm trying to work out a reasonable way to detect the direction of a motor using 8-17v (wide range automotive) and feed it to a micro. Isolation is important so I'm not referencing ground anywhere on the motor side and feeding it through a optical isolator. I came up with the following circuit. Is this reasonable?I'm using zener diodes because the input range of most isolators isn't wide enough to simply use a voltage divider, and I need diodes there anyway, so I'm trying to figure out if I can use a simple zenor diode based regulator. Mocking this up in circuit lab seems to show that I'll get between 1.34 and 1.466v with around -500mv reverse bias on the opto isolator with my intended voltage range. Everything seems to work in the simulator, but I don't know what I don't know so I'm looking for some feedback.Thanks,Matt

author: Benta
author_rank: Super Contributor
timestamp: June 11, 2023, 10:58:54 pm
content: Not the way I'd do it, but as the optocoupler type is a secret it's hard to say. I expect that what you're actually measuring is the voltage polarity across the motor?

author: Circlotron
author_rank: Super Contributor
timestamp: June 11, 2023, 11:17:28 pm
content: Get rid of the zeners and put the opto leds in inverse parallel and fed them with a single resistor. The forward voltage of one led will be the maximum reverse voltage of the other led.

author: akschu
author_rank: Newbie
timestamp: June 11, 2023, 11:18:02 pm
content: I obviously don't get how this works. Reading this question (https://electronics.stackexchange.com/questions/73299/how-do-i-pick-the-right-resistor-for-an-optoisolator-given-a-desired-current) gives me a sense that I'm not trying to drop the voltage with a regulator as much as selecting the correct current limiting resistor based in my input voltage range.Which isolator is completely open at this point. I'd like something surface mount, but not sure which one is the best for this application.One of the questions I am meaning to ask in the original post is if my diode network was a reasonable path to get what I want....

author: wasedadoc
author_rank: Super Contributor
timestamp: June 11, 2023, 11:18:16 pm
content: You can replace the two resistors with one of twice the value. Though those 10k ones do seem rather high. If you want to keep the symmetry you can put the resistor between the junction of the two zeners and the junction of the two opto LEDs.I don't see why you need zeners instead of ordinary diodes and once the zeners are gone just put the optos in reverse parallel as suggested above.

author: Benta
author_rank: Super Contributor
timestamp: June 11, 2023, 11:26:29 pm
content: Quote from: akschu on June 11, 2023, 11:18:02 pmIt's not.Just do as Circlotron said.

author: Whales
author_rank: Super Contributor
timestamp: June 12, 2023, 12:32:02 am
content: Your original circuit could work.(1) 10K resistors might not be optimum, depending on the optoisolater drive min requirements and max limit(2) Ordinary diodes would be better here, not sure why you're mentioning zeners.(3) The alternative suggested (wire two optoisolator diodes in antiparallel) would work better at lower motor voltages/speeds.(4) You will not be able to sense motor voltages/speeds below a certain amount (I can only guess at the numbers)(5) It might be worth adding some capacitance to reduce flicker? Not sure if it will matter.

author: EPAIII
author_rank: Super Contributor
timestamp: June 12, 2023, 01:46:46 am
content: You do not explain just how the circuit works or just what "Motor Input 1" and "Motor Input 2" actually are. There are many forms of speed/direction feedback from motors. Actually there are many types of motors and we do not even know if this is an AC or a DC motor.So I/we need to ASSUME what is apparently the case in this situation.I am ASSUMING that the motor is either DC and that DC power to it is used as the "Motor Output 1 & 2" or that it has some kind of device that produces A SINGLE, DC Voltage as an indication of it's direction. I have NO CLUE if this Voltage is also indicative of the motor's speed, but I strongly suspect that it is. And this SINGLE, DC signal changes polarity when the motor changes direction.What can go wrong?One thing that I immediately see if that the DC Voltage must overcome TWO diode drops, one of which is an LED (usually a higher forward V), before you get an output from the opto-isolator. So, if this DC Voltage is also indicative of the motor's speed, you will get NO indication of the direction until it becomes greater then that value which is probably over 2 VDC. Any Voltage lower than those two diode drops will be the same as the motor being at a full stop.Perhaps this is OK for your application. Again, I/we have no way of knowing. But this is why people responding to internet questions will often ask for more DETAILS about what you are ACTUALLY doing.If you must have direction information with even the smallest rotational rate (RPM) then I would add a quadrature type, optical encoder and a logic circuit that can detect the direction with just a single change in the two quadrature signals produced. Some motors even come with this type of direction detector/encoder incorporated.

author: EPAIII
author_rank: Super Contributor
timestamp: June 12, 2023, 01:56:25 am
content: As for those input resistors, with my ASSUMPTIONS in the post above, it appears that both of them will be in the circuit for both directions of rotation. And only ONE LED in the opto-coupler will be lit at a time. So the effective resistance value will be their sum or 20K. And again, you give too few details for me/us to know if this is the correct value.But YES, in any case they can be replaced with a single resistor. And the value of that single resistor would be the same as you would calculate for just one of the sides of the opto-coupler.

author: akschu
author_rank: Newbie
timestamp: June 12, 2023, 05:24:36 am
content: Thank you EPAIII and others,I thought I posted enough information, but looking back, there are details missing.The motor being driven is a simple DC motor in a linear actuator with a limit switch to disable it when it reaches it's travel. Basically a straight DC motor. The system driving the motor is unknown, but I suspect that it's using a motor driver IC like a DRV8871 or similar. Motor speed is almost certainly not controlled, and even if it was, I'd expect PWM, not variable voltage. The linear actuator says 12-14v, but I'd bet that it gets whatever voltage the alternator is putting out, which is why I had a very wide input voltage. I've seen alternators up in the 15v range, but I should never see anything below 12v as that means the alternator isn't working.One thing I was missing is that the forward voltage on the optoisolator is the voltage drop (like and LED, duh) not what voltage is expected which is why I originally had a zener diode and what I thought was a voltage divider to regulate the voltage to something more normalized.Suppose I use a fairly common optoisolator like the MOCD213M (https://rocelec.widen.net/view/pdf/lvwtxnrklh/ONSM-S-A0006351795-1.pdf?t.download=true&u=5oefqw) could the same resistor values work at 12v as 15v? If not, what is the best way to regulate this voltage?I guess I could boil my question down to:Given a straight DC circuit that reverses polarity and has a voltage range of 12-15v, is there a optoisolator that can work with that voltage range using a single resistor, or will I need other forms of regulation?

author: wasedadoc
author_rank: Super Contributor
timestamp: June 12, 2023, 07:27:15 am
content: Quote from: akschu on June 12, 2023, 05:24:36 amYes, a pair of almost any optos and suitable resistor will work.

author: Infraviolet
author_rank: Super Contributor
timestamp: June 12, 2023, 07:45:22 pm
content: The wisest way is always to use some physical sensor on the motor shaft (an encoder or something) to verify it is indeed turning, you can't put much trust in any ways of trying to follow motor speed/position which don't use this kind of feed-back method. Feed-forward type methods where you measure the time a motor turns for, or voltages on its terminals and current through it, can give errors in lots of ways. If position control is required then be very cautious of any time of position tracking which gives, say, " a pulse every n degrees" but isn't a quadrature signal, analogue value or set of digital signals forming an absolute value. Trying to track motor position just by counting single events will lose accuracy whenever the motor reverses direction or gets backdriven by forces from the load, the logic which tries to decide whether to ad or subtract the single pulses from your present position will be really vulnerable to going the wrong way.Any tracking via a physical measurement of the shaft will probably already give you isolation from the motor's power terminals, so you might not need the optocoupler then.If you are desperate to avoid phsyically measuring the shaft's motion then this:https://www.microchip.com/en-us/application-notes/an3049might interest you, it discusses the principle of counting current ripples (that is one of those single pulse counting techniques I'd advise against as it won't tell you direction by feedback alone). You could built something to follow that principle on the motor's side of your isolation barrier, have a microcontrolelr in there somewhere and just pass a digital data signal through the isolation barrier to processors on the outside which would make whatever decisions are necessary based on the readings from the motor.