ebeowulf17
- Joined Aug 12, 2014
- 3,307
Agreed on all counts.Funny how people see different things in the same post!
Position data is best taken from endstops like you mentioned or some sort of rotary encoder. Even a disk with a hole in it and some sort of optosensor to read it works. You might be able to detect a blockage by measuring current draw on the motor driver (easier at the ground return of the driver). If you see the stall current, stop the motor. You'll need to characterize your motor for stall current.
Note also that feeding any microcontroller and a motor off the same power rail is going to have problems due to the electrical noise the motor puts out. Also current draw fluctuations of the motor can be problematic. I'd use a separate LDO regulator with a blocking diode for microcontroller. This to prevent sag on the motor pulling the LDO output down. Use a largish cap as a reservior on the regulator side of the diode. Getting power distribution right is a key, but often ignore, part of any project.
I'd definitely go with low-side current sensing on the motor driver negative line to detect end positions. The signal coming from the shunt resistor, despite being very low voltage, might still have bizarre noise of some sort, so a small cap and a couple of clamping diodes to protect the analog inputs might still be a good idea.
And yeah, isolating the power supplies as much as possible is a good idea too. The Arduino will *probably* be happy using its own regulator straight off the battery, but running the motor driver separately (either straight from the battery or through its own dedicated regulator) seems like a really good idea. Big and little caps at the input to each board (Arduino and motor controller) will probably help as well.
I think the low side current sensing could be brutally simple. This is all off the top of my head, so I could get this all wrong, but I think you can just put a 1 ohm resistor between the motor controller negative power supply input and ground, then measure voltage on the high side of that resistor with the Arduino. At 150mA, the resistor would drop 150mV. If I remember right, 5V supply and 1024 steps means roughly 5mV ADC resolution. So 150mA should be ~30LSB, which should be more than enough to work with since we're just looking for stall current as an indication of end points, not trying to get an accurate, precision measurement. A little experimentation would be needed to find reliable real world running current and stall current values, but it should be easy enough to pull off.