4
$\begingroup$

I'm having trouble with getting this motor to work and could use some help/guidance, please. I have a micro gear motor with encoder which I got from ServoCity (https://www.servocity.com/90-rpm-micro-gear-motor-w-encoder) and am trying to use it for a project which will require some fairly accurate movement. I used a servo before, but it was too loud and too inaccurate for my needs, and burned out after a couple of years.

I haven't yet gotten to the encoder part of the my control (although I intend to use that to mark "top center", eventually) - so right now I'm using an Arduino and a voltage step-up board. I can make the motor turn by setting the Enable pin on the step-up board to high - however I'm unable to fine-tune the control. It seems to do a full-spin and stop, no matter how briefly I make the pin high. Attempting to do this with PWM doesn't seem to help or produce anything.

In my research I haven't found any code specific to this motor, so I don't know if this is a complete limitation of this motor, or if I'm doing something wrong in my approach.

Any help/code/advice you could give would be much appreciated.

Thanks!

$\endgroup$

2 Answers 2

1
$\begingroup$

Edit: please provide information on your step-up board. What you need is an H-bridge driver such as L293DNE, TB6612FNG, DRV8833, ...

This is a regular DC motor, the 6 pins of the connector are shown on the website you linked: Motor pinout

With Arduino, you should connect the Hall Sensor (the encoder) pins to supplies (GND, +5V) and to two interrupt pins (A, B). See the official attachInterrupt() function reference here because this depends on which Arduino you are using. Make sure you set the interrupts to trigger on change and not only on rising or falling signals.

The software processing consists of a) detecting rotation direction, and b) detecting rotation speed, which can be done by b1) counting pulses or b2) timing pulses.

a) to detect the rotation direction, one way to do it is to compare if the A and B signals are the same (HIGH/LOW) or different using digitalRead(...) on interrupt.

b1) detecting speed by counting pulses is then done by incrementing or decrementing a counter variable depending on direction (needs to be global, volatile). Calculating speed in the loop() is done by dividing the number of pulses by the time and multiplying it by a factor that takes into account the encoder cpr, gear ration, and scales this to preferred units (rad/s, rpm, ...).

b2) if your encoder does not have a lot of counts per revolution (cpr), you should consider timing the changes using micros() or using timer1 and timer3 capture modes (more difficult to set up, search for "arduino input capture"). It helps a lot with these encoders to do it as follows: for each change (interrupt), time the whole period of the encoder signal meaning that you need to remember the time stamps of the previous 3 changes. This reduces the variance in the measurement, because you cannot be sure that the encoder A and B signals are 50% of the time up and 50% down, and a quarter of the period apart (check them on an oscilloscope, they are not perfect!). The speed is in this case calculated by dividing a constant by the encoder signal period. The constant again depends on your counts per revolution, gear ratio, and preferred units.

When you have the speed information from the encoders, use e.g. PID control to make sure that the motor rotates at the desired speed.

$\endgroup$
0
$\begingroup$

The motor looks like a regular DC motor with two outputs for feedback from encoder. Looking at the waveform of the encoder output from the datasheet given on the website at https://www.servocity.com/files/index/download/id/1470930141/, it seems to function just like a regular rotary encoder, with two outputs A and B that would tell you the number of pulses recorded by the encoder. Many libraries for Arduino are available for the same, and a very useful tutorial is available at https://playground.arduino.cc/Main/RotaryEncoders. The crux is, you have to connect the hall effect sensor outputs to two pins on your Arduino, and write a simple code to control the position using a feedback loop (the feedback comes from the encoder reading). The encoder is very low resolution though, and you will possibly have to take steps of 30 degrees each. Also make sure you don't supply over 5V to the power pin of the hall sensor VCC and make sure that the ground of Arduino and hall sensor is common. I hope this helps!

$\endgroup$
3
  • $\begingroup$ That motor has a gear ratio of 297.924:1, which means that the finest resolution you will get is (360 / ( 297.924 * 4) ) = 0.302 degrees per encoder change, not 30 deg. $\endgroup$ Nov 7, 2017 at 21:06
  • $\begingroup$ If you are absolutely sure which direction the motor is going in, then you can use each change of either the A or the B signal to allow your control to be finer. According to the datasheet this would give you 12 times the resolution. $\endgroup$
    – NomadMaker
    Apr 6, 2018 at 13:49
  • $\begingroup$ However, the motor has physical properties such as inertia and backlash, and probably can't be controlled with that resolution without a lot of software control to account for these things. $\endgroup$
    – NomadMaker
    Apr 6, 2018 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.