codes to control high torque dc geared motor

i bought a high torque dc geared motor rmcs-2005 and motor drive rmcs-2302....how to connect them to the arduino board mega 2560 ?
how to control the speed of the motor ?

The Speed of the DC motor is controlled by PWM and direction simply by the DIR input

Connect

PWM+ To a PWM enabled pin of your arduino
PWM- to GND
DIR+ To a digital pin you will set to 0/5V for altering DIRECTION
DIR- GND

The PWM pin need to be driven so that the PWM Frequency varies between 1kHz and 20kHz

Note that PWM functions let you play with the duty cycle but not frequency. To understand more about frequency have a look at Arduino-PWM-Frequency and a great article On the Secrets Of Arduino PWM

but in my drive there is no PWM + and PWM - .....i have only PWM/DIR damping, Back emf and maximum speed pins in the bottom left corner and to the top right corner i have PUL+ , PUL-, DIR+ and DIR- pins

can you put a link to the exact rmcs-2302 unit you have?

Is it This one ??

Hi,
Welcome to the forum.

Read that data sheet and the descriptions of PWM+ and PWM-, PWM input signal and GND.
Likewise for Direction.

What is your electronics, programming, arduino, hardware experience?

Thanks Tom... :slight_smile:

J-M-L:
The PWM pin need to be driven so that the PWM Frequency varies between 1kHz and 20kHz

A PWM signal does not vary in frequency, it varies its duty cycle.

but in my drive there is no PWM + and PWM - .....i have only PWM/DIR damping, Back emf and maximum speed pins in the bottom left corner and to the top right corner i have PUL+ , PUL-, DIR+ and DIR- pins

The PUL and DIR pins are labelled so that you know what they do - they are opto osolators.

Connect the - pins to ground.
Connect the +DIR pin to ground or +5v depending.
Connect the +PUL pin to pin 3.

void setup() {
  pinMode(3, OUPUT);
  alalogWrite(3, 127);
}

void loop(){}

@PaulMurrayCbr

A PWM signal does not vary in frequency, it varies its duty cycle.

Yes, agree that's why I wrote just below

Note that PWM functions let you play with the duty cycle but not frequency. To understand more about frequency have a look at Arduino-PWM-Frequency and a great article On the Secrets Of Arduino PWM

i bought my drive from here

can you send me the codes for speed control of the motor and direction control ?

So I don't have a similar one but you can get a lot from just the picture at the top of the documentation:

You have a set of switches that can set Servo Loop gain and Input Multiplier documented on the top label. I suggest you start simple and set things at 1x and 1x so SW1+SW2 are OFF and SW3 and SW4 are both ON

At the bottom you connect your motor wires to Motor + and Motor - and you provide a strong power supply to +Ve and GND (12 to 50V DC, max 20A)

You have a set of potentiometers you can use to tune different Gains. Gain adjustment is carried out to optimize the control according to the load. Just don't mess around with those and leave them as they are.

ENC A and ENC B are for encoders. An encoder is a sensor that notifies the driver of the speed and position of the motor. Unlike step motors which move in discrete position steps, servomotors have no built-in sense of angular position, and thus require a feedback device, such as a quadrature encoder. if your motor provides quadrature encoder then your motor documentation should have X transitions per base motor rotation between outputs A and B. You would connect those wires there (Enc A is GREEN, Enc B is YELLOW)

GND and 5V are output only, you can use that to power the encoders. Don't use that for anything else.

Now how to get this motor to spin:

Looking at the doc and picture you need to drive this simply through PULSES and DIRCTION inputs to the optically isolated connectors you see at the top of your driver.

So you connect the Cathodes (the -) to ground (PUL- and DIR-) and the + (PUL+ and DIR+) to suitable arduino PINs. I think those are 3.3V and 5V compatible PULSE and DIRECTION inputs - so would work with both types of arduinos (3.3 or 5V)

The Direction is easy to set. Send 0V (set the pin to LOW in your arduino) and you will have your motor turning in one direction, set that pin to HIGH and the motor will turn in the other direction.

A servo motor is driven by applying a voltage signal at regular intervals . The servo is sensitive to timing variations. A pulse of specific width has to be applied at specific intervals of time (i.e. a frequency).

The documentation on the web site mentions "PWM Frequency" from 0 to 20kHz for the driver so you need to send a signal at a given frequency into the PUL+ input. 20kHz is the maximum pulse frequency that can be sent to the driver which sets the maximum rotation speed of the motor (limited by the driver).

I could not find the link for your high torque dc geared motor rmcs-2005 so I don't know if it has quadrature encoder or what to feed to it in terms of pulse.

---> CAN YOU PROVIDE A LINK?

In theory each "Pulse" (a full oscillation) of the frequency will get your motor to turn by one tick. if you used the step multiplier switches, then instead of turning 1 step, it will turn by the multiplier. For example if you set SW3 and SW4 both to OFF then you have an 8x multiplier, so each pulse in the frequency will turn the motor 8 steps.

So the motor rotation speed is proportional to the input pulse frequency (and step multiplier)

If you now how many pulses it takes to have one full rotation of the shaft, then formula is easy

Rotation per Minute = "Frequency in Hz" * "Number of pulses needed for 1 rotation" / 60

you could try out building a very simple code assuming that PinDIR is connected to DIR+ and PinPUL is connected to PUL+

this code is very crude as you won't deliver a very precise pulsation due to the for loop, but should get you started. Then you can investigate what stepper and servo libraries are doing.

at the begining of the program

#DEFINE MOTORSPEED 100    // microseconds

in setup()

  pinMode(PinPUL, OUTPUT);
  pinMode(PinDIR, OUTPUT);
  digitalWrite(PinPUL, LOW); 
  digitalWrite(PinDIR, LOW); // will turn in one direction. HIGH the other

// take the motor for a spin in both directions.
// the frequency we send is roughly 1000000 / (2 * MOTORSPEED)
// so if MOTORSPEED is 100, then we have 5000 Hz 
// roughly because in the code below the for and test will take a bit of time
// you can explore other techniques to send a proper square wave

for (int i=0; i<10000;i++) {
     digitalWrite(PinPUL, HIGH); // build the Pulse - High part
     delayMicroseconds(MOTORSPEED);
     digitalWrite(PinPUL, LOW); //build the Pulse - Low part
     delayMicroseconds(MOTORSPEED);
}

  digitalWrite(PinDIR, HIGH); // turn in the other direction

for (int i=0; i<10000;i++) {
     digitalWrite(PinPUL, HIGH); // build the Pulse - High part
     delayMicroseconds(MOTORSPEED);
     digitalWrite(PinPUL, LOW); // build the Pulse - Low part
     delayMicroseconds(MOTORSPEED);
}

then have an empty loop

the code above will execute 10000 times the loop which basically lasts for 200 microseconds each, so will take 10000 x 200 = 2 000 000 microseconds, so 2 seconds in one direction and 2 seconds in the other.

let us know if that does anything...

I'm in a train. I have not tested this. So use judgement and try at your own risks...

1 Like