Pages: [1]   Go Down
Author Topic: Set Speed Control of Brushless DC Motor using Servo Library  (Read 4115 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I am relatively new in using Arduino. I am trying to run a Brushless DC Motor using the Servo library.  I have the correct power supply, ESC, and correctly connected to the arduino pin 9.  I got it to work using many different sketches I have found, however I am trying to set it to a certain speed and have it spin constantly at that speed while turned on.  Eventually, I will incorporate some sort of feedback for the speed.  I would like to avoid using a potentiometer and be able to set the desired speed directly within the code.  Seems like it should be simple, but I am having trouble.  

I am now using the following code:

Code:
#include <Servo.h>

Servo myservo;

void setup()
{
  myservo.attach(9);
  myservo.write(60);  //Sets speed of motor (60 (low) - 180 (high) i think)
}

void loop() {}

Through trial and error, any lower than 60 the motor will stop running, however, it is still relatively fast.  Is this a limitation from my ESC or from my motor?  I would like to understand the process of what is going on better so I can have more precise control over the speed.  Any input would be greatly appreciated!

Thanks
Nick
« Last Edit: July 15, 2013, 06:30:11 pm by rader945 » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am trying to run a Brushless DC Motor
...that you haven't specified...
Quote
the correct power supply
...that you haven't specified...
Quote
ESC
...that you haven't specified...

Quote
Seems like it should be simple, but I am having trouble. 
Where are you arming and calibrating the ESC?

Quote
Is this a limitation from my ESC or from my motor?
Probably. Or the power supply. Or the code (specifically, what is not there). Or the load on the motor. Or the wiring.

Logged

Cape Town, South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, would also like feedback on this.

As I understand it by just reading the sweep.ino code in the example libraries - one should be able to set pos = x (where x is your desired speed) instead of having it increment.

I.e. "for (pos =0; pos <180; pos+- 1)
              {
                  myservo.write (pos);
                  delay (15);
              }
could change to
int pos = 30; //for example
myservo.write (30);

This is probably like a really basic setup because I came across a program to sweep the motor using the command "map" which incorporated speed and angle.

'int angle = map (speed, 0, 100, 0, 180);
  myservo.write (angle)' //sweeps motor from 0 to max

Could you change that 180 (degrees) by the way? I experimented with the speed "100" but it still runs quite high. Doesnt make sense to change the 180 though since that allows a full rotation??

I could also just be way off course, I'm just another new kid on the block  smiley-grin


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi . i am facing exact same problem as one described by rader945.
i am using a 20A emax esc and emax bldc 2213-935kv. its not slow enough even at 65 , the speed is glitchy and motor stops at 60 . what is the proper way to control its speed .
here is the code that im using

#include <Servo.h>
 
Servo myservo; 

int pos = 0;   
void setup()
{
  myservo.attach(9);   

}
 
 
void loop()
{
 for(pos = 0; pos < 180; pos += 1)
  {                           
    myservo.write(pos);           
    delay(50); 


while(1)
{
myservo.write(60);
}
}

please help me out . my final year project is stuck due to this
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Through trial and error, any lower than 60 the motor will stop running, however, it is still relatively fast.  Is this a limitation from my ESC or from my motor?  I would like to understand the process of what is going on better so I can have more precise control over the speed.  Any input would be greatly appreciated!

That is my experience with brushless DC motor/ESC used in R/C airplanes also. They don't control real well at slowest RPMs because the ESC is using electrical feedback pulses sensed on the three motor windings to determine speed and such pulses can be very small at slow speeds. Once above that 'threshold' the speed should be pretty linear Vs the servo.write command values you give it. So I would suggest not trying to attach any kind of external RPM feedback circuitry as the ESC is already a 'speed controller' you just have to characterize it's performance vs your servo write values.

 Also using servo write microseconds rather then servo write degrees will improve the response curve of the motor/esc.

Lastly, know that brushless motor/ESC speed control relationship is dependent on the mechanical load on the motor. Some motor/ESCs work poorly or erratically with no load on the motor. Try to test out using real world motor loads.

Lefty
« Last Edit: November 22, 2013, 01:42:48 pm by retrolefty » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thankyou so much .the above reply was very helpful.
but there is one other issue that im facing .. the code is running fine and motor speed is also controllable through servo.write() between 180-63(min) but at round servo 70-75 the motor speed fluctuates. when i checked the input voltage at the esc it was varying between 8-10V thus the speed keeps going up and down . im powering the esc through a variable dc adapter. what could be the possible issue ? is it the adapter or some fault with the esc ???
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Through trial and error, any lower than 60 the motor will stop running, however, it is still relatively fast.  Is this a limitation from my ESC or from my motor?  I would like to understand the process of what is going on better so I can have more precise control over the speed.  Any input would be greatly appreciated!

That is my experience with brushless DC motor/ESC used in R/C airplanes also. They don't control real well at slowest RPMs because the ESC is using electrical feedback pulses sensed on the three motor windings to determine speed and such pulses can be very small at slow speeds. Once above that 'threshold' the speed should be pretty linear Vs the servo.write command values you give it. So I would suggest not trying to attach any kind of external RPM feedback circuitry as the ESC is already a 'speed controller' you just have to characterize it's performance vs your servo write values.

 Also using servo write microseconds rather then servo write degrees will improve the response curve of the motor/esc.

Lastly, know that brushless motor/ESC speed control relationship is dependent on the mechanical load on the motor. Some motor/ESCs work poorly or erratically with no load on the motor. Try to test out using real world motor loads.

Lefty

i have a stupid Question want to know.
can i use the signal from 3 wires of the ESC to feedback to the CPU to have a close-loop
 i want to know the speed of motor and display in lcd

best regards
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Through trial and error, any lower than 60 the motor will stop running, however, it is still relatively fast.  Is this a limitation from my ESC or from my motor?  I would like to understand the process of what is going on better so I can have more precise control over the speed.  Any input would be greatly appreciated!

That is my experience with brushless DC motor/ESC used in R/C airplanes also. They don't control real well at slowest RPMs because the ESC is using electrical feedback pulses sensed on the three motor windings to determine speed and such pulses can be very small at slow speeds. Once above that 'threshold' the speed should be pretty linear Vs the servo.write command values you give it. So I would suggest not trying to attach any kind of external RPM feedback circuitry as the ESC is already a 'speed controller' you just have to characterize it's performance vs your servo write values.

 Also using servo write microseconds rather then servo write degrees will improve the response curve of the motor/esc.

Lastly, know that brushless motor/ESC speed control relationship is dependent on the mechanical load on the motor. Some motor/ESCs work poorly or erratically with no load on the motor. Try to test out using real world motor loads.

Lefty

i have a stupid Question want to know.
can i use the signal from 3 wires of the ESC to feedback to the CPU to have a close-loop
 i want to know the speed of motor and display in lcd

best regards


 In theory one could but it would be somewhat software challenging analyzing/designing. Also if the motor runs at higher then 5vdc winding voltage then reading them back as analog signals would require external resistor divider networks. 
Logged

0
Online Online
Shannon Member
****
Karma: 222
Posts: 12731
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thankyou so much .the above reply was very helpful.
but there is one other issue that im facing .. the code is running fine and motor speed is also controllable through servo.write() between 180-63(min) but at round servo 70-75 the motor speed fluctuates. when i checked the input voltage at the esc it was varying between 8-10V thus the speed keeps going up and down . im powering the esc through a variable dc adapter. what could be the possible issue ? is it the adapter or some fault with the esc ???

The ESC will probably be pulling current spikes that are overloading the DC adapter.
The drop in voltage then causes the ESC to adjust its behaviour.

Remember these motors have only a few turns of chunky wire, they can easily pull dozens of
amps without flinching, if only for a few microseconds, can your supply cope?  These
ESC/motor combinations are developed to work from high performance LiPo packs
which have little difficulty sourcing extremely high currents without much voltage
drop.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: