Servo motor çalışrıken dc motor çalışmaması

Başlatan bbs2006, 23 Aralık 2019, 23:04:10

bbs2006

Merhaba
Arkadaşımın yapmış olduğu bir devrede  dc motoru pwm ile sürmektedir. yazılıma sevo motor kontrolu eklediğimiz zaman dc motor çalışmamaktadır. bununla ilgili deneyimleriniz oldu mu

sezgin05


bbs2006


bbs2006

    const int enA = 9; const int motorPin1 = 4; const int motorPin2 = 5; const int enB = 10; const int motorPin3 = 6;
    const int motorPin4 = 7; const int lo = 1120; //RC transmitter definitions
    const int hi = 1870; const int deadlo = 1470; const int deadhi = 1520; const int center = 1500;
    int ch[6]; int x1 = 0; int y1 = 0; int x2 = 0; int y2 = 0; int y1_pwm = 0; int x2_pwm = 0;
    int x2_reverse_pwm = 0; int x1_pwm = 0; int x1_reverse_pwm = 0; int throttle = 0;
          int sgdn=0;int sldn=0; int gsgdn=0;int gsldn=0;
          #include<Servo.h>
          int serdpwm=0;int serypwm=0;int zd=0;int zy=0;
          Servo seryt;Servo serdk;
void setup() {
  pinMode(A0, INPUT);   pinMode(A1, INPUT);pinMode(A2, INPUT);pinMode(A3, INPUT);pinMode(enA, OUTPUT);
  pinMode(motorPin1, OUTPUT);pinMode(motorPin2, OUTPUT);pinMode(enB, OUTPUT);pinMode(motorPin3, OUTPUT);pinMode(motorPin4, OUTPUT);
          //seryt.attach(11); serdk.attach(12); 
             Serial.begin(9600);
             }
void loop() {
  ch[0] = pulseIn (A0, HIGH); //x2
  ch[1] = pulseIn (A1, HIGH); //y2
  ch[2] = pulseIn (A2, HIGH); //y1
  ch[3] = pulseIn (A3, HIGH); //x1 //stabilizing transmitter data
      ch[4] = pulseIn (A4,HIGH);
      ch[5] = pulseIn (A5,HIGH);
  for (int i = 0; i < 6; i++){ ch[i] = constrain(ch[i], lo, hi);
  if (ch[i] <= deadhi && ch[i] >= deadlo) { ch[i] = center;}}
                                                                  //redefinitions transmitter joysticks
  x1 = ch[3];y1 = ch[2];x2 = ch[0];y2 = ch[1]; 
        
        zy = ch[4]; zd = ch[5]; 

                                                                  //getting pwm for motor control
  x1_pwm = map(x1, 1500, 1870, 0, 255);
  x1_reverse_pwm = map(x1, 1500, 1120, 0, 255);
  x2_pwm = map(x2, 1500, 1870, 0, 255);
  x2_reverse_pwm = map(x2, 1500, 1120, 0, 255);
  y1_pwm = map(y1, 1120, 1870, 0, 255);
          serdpwm=map(zd,1120,1870,0,180);
          serypwm=map(zy,1120,1870,0,180);
    if (y1 > 1120) throttle = 1; else throttle = 0;
    if (throttle && y2 == 1500 && x2 == 1500 && x1 == 1500){stop_all();}
    if (throttle && y2 > 1500 && x2 == 1500){forward();}
    if (throttle && y2 < 1500 && x2 == 1500){backward();}
    if (throttle && x1 > 1500){right_on_its_axis();}
    if (throttle && x1 < 1500){left_on_its_axis();}
    if (throttle && x2 > 1500 && y2 == 1500){right_spin();}
    if (throttle && x2 < 1500 && y2 == 1500){left_spin();}
    if (throttle && y2 > 1500 && x2 > 1500){right_forward();}
    if (throttle && y2 > 1500 && x2 < 1500){left_forward();}
    if (throttle && y2 < 1500 && x2 > 1500){right_backward();}
    if (throttle && y2 < 1500 && x2 < 1500){left_backward();}
        if (throttle&&serdpwm>=1){servodikey();}
        if (throttle&&serypwm>=1){servoyatay();}
        Serial.print("serisag:");Serial.println(y1);
         Serial.print("serisol:"); Serial.println(x1);
        delay(50);                                                        }

 void forward()  {
                analogWrite(enA, y1_pwm);
                digitalWrite(motorPin1, HIGH);
                digitalWrite(motorPin2, LOW);
                analogWrite(enB, y1_pwm);
                digitalWrite(motorPin3, HIGH);
                digitalWrite(motorPin4, LOW);         }

 void backward() {
                 analogWrite(enA, y1_pwm);
                 digitalWrite(motorPin1, LOW);
                 digitalWrite(motorPin2, HIGH);
                 analogWrite(enB, y1_pwm);
                 digitalWrite(motorPin3, LOW);
                 digitalWrite(motorPin4, HIGH);       }

 void right_on_its_axis() {
                          analogWrite(enA, x1_pwm);
                          digitalWrite(motorPin1, LOW);
                          digitalWrite(motorPin2, HIGH);
                          analogWrite(enB, x1_pwm);
                          digitalWrite(motorPin3, HIGH);
                          digitalWrite(motorPin4, LOW);    }

 void left_on_its_axis() {
                          analogWrite(enA, x1_reverse_pwm);
                          digitalWrite(motorPin1, HIGH);
                          digitalWrite(motorPin2, LOW);
                          analogWrite(enB, x1_reverse_pwm);
                          digitalWrite(motorPin3, LOW);
                          digitalWrite(motorPin4, HIGH);      }

 void right_spin(){
                  analogWrite(enA, x2_pwm);
                  digitalWrite(motorPin1, LOW);
                  digitalWrite(motorPin2, LOW);
                  analogWrite(enB, x2_pwm);
                  digitalWrite(motorPin3, HIGH);
                  digitalWrite(motorPin4, LOW);      }

 void left_spin(){
                  analogWrite(enA, x2_reverse_pwm);
                  digitalWrite(motorPin1, HIGH);
                  digitalWrite(motorPin2, LOW);
                  analogWrite(enB, x2_reverse_pwm);
                  digitalWrite(motorPin3, LOW);
                  digitalWrite(motorPin4, LOW);       }

 void stop_all(){
                  analogWrite(enA, 0);
                  digitalWrite(motorPin1, LOW);
                  digitalWrite(motorPin2, LOW);
                  analogWrite(enB, 0);
                  digitalWrite(motorPin3, LOW);
                  digitalWrite(motorPin4, LOW);       }

 void right_forward(){
                      sgdn=y1_pwm-x2_pwm;
                      if (x2_pwm>=y1_pwm){sgdn=0;}
                      analogWrite(enA, sgdn);
                      digitalWrite(motorPin1, HIGH);
                      digitalWrite(motorPin2, LOW);
                      analogWrite(enB, y1_pwm);
                      digitalWrite(motorPin3, HIGH);
                      digitalWrite(motorPin4, LOW);     }

 void left_forward(){
                      
                     sldn=y1_pwm-x2_reverse_pwm;
                     if (x2_reverse_pwm>=y1_pwm){sldn=0;}
                      analogWrite(enA, y1_pwm);
                      digitalWrite(motorPin1, HIGH);
                      digitalWrite(motorPin2, LOW);
                      analogWrite(enB, sldn);
                      digitalWrite(motorPin3, HIGH);
                      digitalWrite(motorPin4, LOW);     }

 void right_backward(){
                      gsgdn=y1_pwm-x2_pwm;
                       if (x2_pwm>=y1_pwm){gsgdn=0;}
                      analogWrite(enA, gsgdn);
                      digitalWrite(motorPin1, LOW);
                      digitalWrite(motorPin2, HIGH);
                      analogWrite(enB, y1_pwm);
                      digitalWrite(motorPin3, LOW);
                      digitalWrite(motorPin4, HIGH);    }

 void left_backward(){
                      gsldn=y1_pwm-x2_reverse_pwm;
                     if (x2_reverse_pwm>=y1_pwm){gsldn=0;}
                      analogWrite(enA, y1_pwm);
                      digitalWrite(motorPin1, LOW);
                      digitalWrite(motorPin2, HIGH);
                      analogWrite(enB, gsldn);
                      digitalWrite(motorPin3, LOW);
                      digitalWrite(motorPin4, HIGH);    }


 void servoyatay(){ seryt.write(serypwm);}
 void servodikey(){ serdk.write(serdpwm);}


                     




gerekli yazılım kodları.  arduino nano

sezgin05

DC motorun ürettiği parazitlerden kaynaklanıyor olabilir. Diyot ve RC filtre ile parazitleri gidermeyi deneyebilirsiniz. Tabii beslemeyi de ayırabilirsiniz.

ibocakir

Hayır hocam problem yazılımsal, servoyu sürebilmek için arduino kütüphanesi 50Hz Pwm üretmek için ve DC'yü sürerken PWM üretmek için aynı TIMER'ı kullanıyor.

https://github.com/voodootikigod/voodoospark/issues/32

Konuyla alakalı örnek ve çözüm aratınca bulabilirsiniz.

https://www.google.com/search?q=arduino+pwm+servo+timer+dont+work&rlz=1C1CHBD_trTR777TR777&oq=arduino+pwm+servo+timer+dont+work&aqs=chrome..69i57j33.18218j0j7&sourceid=chrome&ie=UTF-8

sezgin05

@ibocakir : Haklısınız ben zaten ters anlamışım. Servo varken DC çalışmıyor demiş arkadaş. DC varken servo çalışmıyor şeklinde yorumlamışım.