Hi
I need your help on this project. I built an 12V DC motor with attached external absolute encoder. The motor a 12V 150W Bus Wiper which elevate lift than sink it down to a specific CEP position... I use BTS7960B 12V 43A driver board..
The motor shall rotate between 0...180degree which means 380 to 960 signal in the absolute encoder.
Now the problem is when I try to move the motor into a specific position it does not go smoothly. even if the code looks simple and easy.. What is happening: Motor start rotating from 960 back to the set CEP=870 Position but suddenly stops at 935 than restart rotating to 905 than stop around 865.. so every time at least 3 sub steps happening before it reach the desired value.. I do not understand why... The importance of this system to avoid over rotation of the set CEP value .... if it would stop 5 or 10 value earlier but as fast as possible would be great.... I tried with different PWM values but it did not help a lot...
So I want to move the DC motor from 960 back to 870 position smoothly and quickly in one step:
The entire code as it was asked :
int LPWMpin=5;
int RPWMpin=6;
int L_R_ENpin=7;
int actuatorpin=10;
int BKpin=12;
volatile int MPmax=960;
volatile int MPmin=380;
int a=1;
int CEP =0;
int CES = 0;
volatile int CMPactualext;
volatile int CMPactualint;
volatile int CEPext;
volatile int CMPactual =0;
volatile int MP = 0;
int BKsw;
int actuatorbuttonState;
boolean CMaktiv;
// the setup routine runs once when you press reset:
void setup() {
pinMode(actuatorpin,INPUT);
pinMode(BKpin,INPUT);
pinMode(LPWMpin,OUTPUT);
pinMode(RPWMpin,OUTPUT);
pinMode(L_R_ENpin,OUTPUT);
digitalWrite(LPWMpin,LOW);
digitalWrite(RPWMpin,LOW);
digitalWrite(L_R_ENpin,LOW);
delay(200);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
CEP = analogRead(2);
CEP = map(CEP,0,1023,700,MPmax);
CMPactual = analogRead(5);
CMPactual = map(CMPactual,0, 1023, MPmin, MPmax);
CMPactualext=CMPactual-10;
CMPactualint=CMPactual-5;
CEPext=CEP+15;
actuatorbuttonState = digitalRead(actuatorpin);
BKsw = digitalRead(BKpin);
if (actuatorbuttonState==LOW||BKsw==HIGH){
MP = 1023 - analogRead(0);
if (MP<CMPactualext){
digitalWrite(L_R_ENpin, HIGH);
analogWrite(RPWMpin,255);
analogWrite(LPWMpin,0);
a=1;
while (a<2){
MP = 1023 - analogRead(0);
if (MP>CMPactualint){
digitalWrite(L_R_ENpin, LOW);
analogWrite(LPWMpin,0);
analogWrite(RPWMpin,0);
a=2;
}
}
}
}
actuatorbuttonState = digitalRead(actuatorpin);
BKsw = digitalRead(BKpin);
if ((actuatorbuttonState==HIGH)&&(BKsw==LOW)){
MP = 1023 - analogRead(0);
if (MP>CEPext){
digitalWrite(L_R_ENpin, HIGH);
analogWrite(RPWMpin,0);
analogWrite(LPWMpin,80);
CMaktiv = true;
while (CMaktiv != false){
MP = 1023 - analogRead(0);
if (MP<CEPext){
digitalWrite(L_R_ENpin, LOW);
analogWrite(LPWMpin,0);
analogWrite(RPWMpin,0);
CMaktiv = false;
}
}
}
}
}
The DC motor actually moves for a while than stop than start rotation again but with a shorter time.... The system shall be fast and accurate The major challenge is that the load during MP increment requires 255PWM while when it moves back an 40PWM more than enough however the DC motor getting noisy therefore I increased to 80PWM.
Unfortunately I am not familiar with the PID stuff and I am not sure how make it slow down the routine....
Circuit schematic attached below in the discussion
Please advice how I can improve the accuracy of the DC positioning.
Thanks in advance