I've been using this code to drive a BLDC motor with a 150 amp ESC. I was wondering if there is anything that could be adjusted in the code that would make the motor run smoother. It may be mechanical but if there is anything I can try in the code I'd like to start there. Thanks`
#include <Servo.h> //Using servo library to control ESC
Servo esc; //Creating a servo class with name as esc
void setup()
{
esc.attach(10); //Specify the esc signal pin,Here as D10
esc.writeMicroseconds(1000); //initialize the signal to 1000
Serial.begin(9600);
}
void loop()
{
int val; //Creating a variable val
val= analogRead(A0); //Read input from analog pin a0 and store in val
val= map(val, 0, 1023,1000,2000); //mapping val to minimum and maximum(Change if needed)
esc.writeMicroseconds(val); //using val as the signal to esc
}
What is attached to pin A0? Maybe there is some electrical noise there? A simple hardware filter could help, or doing a moving average filter in software. You could try printing val to the serial monitor, or serial plotter, to see if there are any variations.
Thanks for responding, A0 goes to the wiper of a pot, 5v and gnd. the other terminals. D10 is the signal out to the ESC. I mainly wanted to see if changing any of the values in the code would would help to make the motor smoother and start softer.