DC servo motor using RC (diy)

Hello everyone, Im looking for some help with my project which uses the code below to control a large DC motor as a servo with hobby radio control. I have a potentiometer attached to the drive shaft for position feedback.
arduino sends the pwm signals to the motor controller which then turns the motor. i followed this tutorial on youtube to build my "rc servo" and it works well. How to Make an R/C Servo from a Wiper Motor | James Bruton - YouTube

I am currenty using the motor controller IBT2 BTS7960 it requires 2x pwm pins, 1 is forward and the other is reverse. the enable pins are permently connected to 5v.
I would like to change over to another type of controller like a motomonster which uses only 1 pwm pin for both forward and backward (after enabling either the A or B direction pin.)

does anyone know if this would be possible ? any help to solve this is greatly appreciated and thank you for looking.

[code]
#include <PID_v1.h>  //PID loop from http://playground.arduino.cc/Code/PIDLibrary

double Pk1 = 2;  //speed it gets there
double Ik1 = 0;
double Dk1 = 0;

double Setpoint1, Input1, Output1, Output1a;    // PID variables

PID PID1(&Input1, &Output1, &Setpoint1, Pk1, Ik1 , Dk1, DIRECT);    // PID Setup

volatile unsigned long pwm;
volatile boolean done;
unsigned long start;

int pot;

unsigned long currentMillis;

long previousMillis = 0;    // set up timers
long interval = 20;        // time constant for timers

void setup() {
  pinMode(2, INPUT);
  pinMode(A0, INPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  attachInterrupt(0, timeit, CHANGE);
  
  Serial.begin(115200);

  PID1.SetMode(AUTOMATIC);              // PID Setup - trousers SERVO
  PID1.SetOutputLimits(-255, 255);
  PID1.SetSampleTime(20);

}


void timeit() {
    if (digitalRead(2) == HIGH) {
      start = micros();
    }
    else {
      pwm = micros() - start;
      done = true;
    }
  }


void loop() {

  currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {  //start timed event
      previousMillis = currentMillis;

      pot = analogRead(A0);
      Serial.print(pot);
      Serial.print(" , ");
      Serial.print (pwm);
      Serial.print(" , ");

      Setpoint1 = map(pwm,1000,2000,-255,255);
      Input1 = map(pot,0,1023,-255,255);
      PID1.Compute();

      Serial.println(Output1);    

      if (Output1 > 0) {
        analogWrite(5, Output1);
        analogWrite(6, 0);
      }
      else if (Output1 < 0) {
        Output1a = abs(Output1);
        analogWrite(5, 0);
        analogWrite(6, Output1a);
      }

      
      
      if (!done)
            return;               
            done = false;   
     
  } // end of timed event

}

[/code]

This strange driver module is discussed in many internet pages. It may be possible to apply PWM to the EN pins and control direction with inverse levels on the PWM pins. This way only 1 PWM output is required, at the cost of 2 digital output pins.

If you operate a powerful motor then don't forget to protect against permanent rotation and excess current.

This could be a lot of fun for, you picked a great part. You can connect the PWMR and the PWML together, that eliminates one PWM pin. Then add an inverter between L_EN and R_EN that will give you both directions but always on. If you can spare a digital pin then one for L_EN the second for R_EN. I am just guessing but I think your problem is a lack of PWM pins. Schematic for that module are available on line.

gilshultz:
Then add an inverter between L_EN and R_EN that will give you both directions but always on.

Please read the linked page in #1. It shows that both EN must be ON (HIGH) to enable both half-bridges. Fortunately your suggestion is a harmless experiment because no current will flow.

Come back when you have definitely selected a module to use, not one not to use.

Why 2 Arduinos for 1 motor driver board? How do you want to synchronize the motors?
Okay, servos don't require synchronization.

What is the limit you run into - and which makes you use two boards? Very likely indeed a single Arduino can handle the two motors by itself, but lots more details on your setup are needed.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.