Hello, I am trying to run to BLDC motors at either end of a balance to work on a single axis PID loop tutorial I found on youtube.
I have the hardware built, and was testing the motors to be sure they were spinning in the correct direction.
I used a potentiometer to vary the writeMicroseconds value to the Servo object and found that both ESCs turned on about 1250 us . There as some small variation but not much.
The issue develops when I try to write the values to two ESC in the same program.
When I run the program , only one ESC will spin reliably. The 2nd will not turn or won't start until much higher in the potentiometers range. If they are both spinning, they will sputter and slow down without a change in speed value from the potentiometer.
There is also a behavior, in which one will operate flawlessly while the speed input is in a lower range, while the other lags and sputters, but when the speed input gets above a cetain value(example 1450 Microseconds) they swap and the second starts working great wile the first begins to slow and sputter. They are receiving the same value over writeMicroseconds().
Occasionally, after many seconds, they will briefly be near the same speed. But this occurs rarely.
If I disconnect each ESC's control pin individually, each runs exactly as expected, very smooth from 1250 us to 1800us. I swapped the PWM pins , to see if it was related to who received the writeMicroseconds() value first, but the problem remained.
I am using a 12V 30A power supply to run this , and if it were a power issue, I would expect the two ESC to work fine in the low speed ranges, then sputter when the speeds approached the high end.
I am using the Little Bee 20A ESC. I must be getting old because I cannot decipher the beeps. I hear a three tone rising signal, the two lower tones.
#include <Servo.h>//Using servo library to control ESC
Servo esc; //Creating a servo class with name as esc
Servo esc1; //Creating a servo class with name as esc1
int escPin = 12;
int escPin1 = 13;
int minPulseRate = 1000;
int maxPulseRate = 1800;
int throttleChangeDelay = 50;
void setup()
{
Serial.begin(9600);
//Init escs
initEscs();
delay(1000);
startUpMotors();
delay(4000); // Deay for 4 seconds to let ESC power UP correctly
while(Serial.available() == 0) { } //-snip- // Wait for operator input before going to the loop()
startUpMotors();
}
void loop()
{
int val; //Creating a variable val
val= analogRead(A0); //Read input from analog pin a0 and store in val
int mappedValOne= map(val, 0, 1023,1250,1700); //mapping val to minimum and maximum(Change if needed)
Serial.print(val); // Write to the serial monitor so I can see what is happening
Serial.print("\t");
Serial.print("New ESC One Speed is : ");
Serial.println(mappedValOne);
writeTo2Escs(mappedValOne);
delay(throttleChangeDelay); // delay so we don' t make changes tooo quickly
}
//Change velocity of the 2 escs at the same time
void writeTo2Escs(int throttle) {
esc.writeMicroseconds(throttle);
esc1.writeMicroseconds(throttle);
}
//Init escs
void initEscs() {
esc.attach(escPin, minPulseRate, maxPulseRate);
esc1.attach(escPin1, minPulseRate, maxPulseRate);
//Init motors with 0 value
writeTo2Escs(0);
}
//Start the motors
void startUpMotors() {
writeTo2Escs(maxPulseRate );
delay(1000);
writeTo2Escs(minPulseRate );
delay(1000);
}