I have a project where I'm getting a signal from a DC motor driver that swaps polarity, and I would like to plug that into GPIO pins so that I can use the microcontroller to drive a stepper motor.
I see that you can drive a DC motor from a micro using an H-bridge, but do they work in reverse? Can I have the DC motor signal turn pin A high for one direction and pin B high for another direction, or simply have pin A be turn on, and pin B be high or low?
I know it could be resolved with a relay and a diode, where if the relay is on turn on, and depending on the polarity through the diode set direction, but I'm thinking there is a more correct way.
The more correct way is to just use a diode to detect the voltage and another two diodes to clamp the voltage to the power rail and finally a seriese resistor to limit the current and a pull down resistor on the input.
Gives on and off information but not any direction information. You still have to clamp the voltage to the rails with two more diodes and have the two resistors.
So you are using a DC motor as a sensor of some kind? You turn the DC motor and generate a voltage, then use that information to turn a stepper, is that correct?
This question came up before. Here is what I came up with:
Connect a voltage divider from Vcc to ground. At the junction, connect one terminal of the DC motor. Connect a loading resistor across the DC motor. Connect the other terminal of the DC motor to an analog input.
With no motion, voltage is Vcc/2. Turn one way, >Vcc/2. Turn the other way, <Vcc/2. I'd also use a 1k resistor between the motor and the analog input pin and a couple of diodes for a bit more protection. Size of the resistor across the motor depends on the motor and the maximum speed that you can spin it.
The motor polarity is direction dependent. Sensing motor polarity is effectively sensing motor direction, whether you use diodes and resistors or an op amp.
I have a project where I'm getting a signal from a DC motor driver that swaps polarity, and I would like to plug that into GPIO pins so that I can use the microcontroller to drive a stepper motor.
What motor driver, what voltage, what stepper, what stepper driver, do you have control of
the DC motor driver (I'd guess not as you are wanting to sense it).
More information will yield more useful advice....
I see that you can drive a DC motor from a micro using an H-bridge, but do they work in reverse?
Of course not. What a silly question. A simple Google of "H-bridge" would yield a functional schematic which would show that it is nothing more than transistors or mosfets driven using a specific truth table designed to prevent "Shoot-through".
If you using electronics by now you should know that a transistor or mosfet has inputs and outputs and that the H-bridge drives the motor , not the other way around. Please have the courtesy to take 2 minutes to google your subject before posting to avoid asking stupid questions.
If you want a correct solution to your problem you need to provide correct information in your initial post.
ie:
Hi all, my project is the following:
Objective: Drive stepper motor to ___________ based on direction of a dc motor. Equipment required:
1- DC motor direction sensor
DC motor is a ______________
vendor link: ______________
DC motor driver is a __________
2- Stepper motor is a _______________________
Stepper motor SPECS:
VOLTAGE: _________
CURRENT: _________
Stepper motor driver is a ___________
3- uP (arduino)
Project Criteria:
Sense motor direction using uP and sensor circuitry.
Stepper must __________ when dc motor ____________
The ability of an H-bridge to function "in reverse" as a synchronous rectifier, is absolutely critical to the operation of regenerative braking in transport systems.
Of course, it is a little more complex, as it also involves symmetric voltage conversion systems as well - which also use reversible H-bridges.
Thanks for the help!!! I'll try and post something more complete, or at least more specific.
The stepper motor driver, code to drive it, and all of that is done. That part doesn't matter and seems to be confusing things. Lets reduce it down to this:
I want to build a circuit that can detect if an external controller turns on a 12vdc motor, and if it is, which direction it's running. An even simpler example would be to detect if there is potential between two leads and which direction it's going.
Once I have that, the rest is already mocked up and working fine.
I didn't think an H-bridge would work in reverse, and I know I can break out the directions with diodes to get a voltage high from one diode or the other in regards to which direction it's working, then a voltage divider to get the correct voltage, but the part that I don't understand is what that voltage is referenced to, since the pos/neg switch sides, and I have no other gnd reference.
A dc motor driving forward has a positive voltage across it. Measuring each motor terminal with a voltage divider (Terminal-1 (+) to => A1 , Terminal-2 (-) => A0)
If you subtract A0 analog reading from A1 (both of which have been reduced using voltage dividers) , A1 will be some positive value, A0 will be 0V because it is the (-)
Terminal. Can you use S//W to compare A1 to A0 to test for A1> A0 ?
When you change motor direction, will not A0 be "+" and A1 (0V) ? Can you not test for A0 > A1 to detect reverse ? Can you not add IF statements to perform actions based on which is 0V and which is a positive voltage ? Do you need diodes to do that ?
All you should need is four resistors for the two voltage dividers.
Polymorphs suggestion is a variation of the same idea, albeit more complex:
Connect a voltage divider from Vcc to ground. At the junction, connect one terminal of the DC motor. Connect a loading resistor across the DC motor. Connect the other terminal of the DC motor to an analog input.
With no motion, voltage is Vcc/2. Turn one way, >Vcc/2. Turn the other way, <Vcc/2. I'd also use a 1k resistor between the motor and the analog input pin and a couple of diodes for a bit more protection. Size of the resistor across the motor depends on the motor and the maximum speed that you can spin it.
@Paul,
Your answer about reversing an H-bridge is not what the OP was asking. We know you can short both motor terminals to +Vcc or both to GND which causes the motor to resist rotation but the OP was asking if you could sense motor direction which is something completely different.
Yes, raschemmel's answer. Mine is if you had a motor that you were only turning by hand, I missed the part where you had driver circuits providing power to it.
Regenerative braking is not motor direction feedback to a uP for the purpose of detecting motor direction. (not to mention the H-bridge is not working in reverse , the energy is being transferred from the motor to the battery, which is not the same thing) The OP needs direction information , not energy transfer. At best, it is a loose interpretation of the phrase "Can an H-bridge work in reverse ?". The energy is indeed returned to it's source, but that is due to the fact the battery effectively part of the load for the H-bridge because the load includes every between the left side and the right side of the h-bridge, but that's a different topic.
I think raschemmel has a good solution. If the DC motor is being driven by an H bridge and it can share a common ground with the Arduino, it is simple. If one side of the motor goes positive, motor is turning one way, if the other side goes positive, motor is turning the other way. Neither side goes below ground. A resistor divider can handle the motor voltage being greater than Vcc, and a series resistor and protection diodes should protect against spikes.
As to the OP's question if the Arduino's ground is truly not common the the motors power supply then the answer is to use two opto isolators to detect the direction.