speed control of bldc motor using arduino

How can we use arduino mega 2560 to initiate bldc motors ?
how is it's speed control ? Do we need to use PWM signals for the connection or not ?
Thank you for your help ...

Which motors do you mean?

MarkT:
Which motors do you mean?

MarkT:
Which motors do you mean?

brushless DC motor

Currently I am also working on such a project. As I could understand this is a very complicated mathematical procedure to process. I don’t want to say that mega2560cannot handle such mathematics but i say that they are veeeery complicated. It includes the Space Vector Pulse Width Modulation model and thus the Field Oriented Control algorithm. from other controller.
The model is rather simple. I have some abstract schematic with a IGBT module and other doohickies on power board. And I have 6 inputs for positive edge and negative edge PWM. Don’t forget about deadtime between positive edge forming and negative edge forming. It should be at approximately 3 microseconds to allow the transistors open and close the collector to avoid straight through current It is needed for three Phases to be formed by transistors to construct a sinusoidal wave. After that some movement could be achieved.

The code so far i could have achieved.

#include <TimerOne.h>

const float pi = 3.14;
const float squ = 1/sqrt(3);
//const int amplitude = 511;
const int fanPin1 = 5;
const int fanPin2 = 6;
const int fanPin3 = 9;

const int fanPin4 = 10;
const int fanPin5 = 11;
const int fanPin6 = 13;

const int fanPin7 = 29;
const int fanPin8 = 30;
const int fanPin9 = 31;
float degree = 0;



void setup(void)
{
  Timer1.complementaryEnable();
  Timer1.initialize(20);  // 40 us = 25 kHz
  Serial.begin(9600);
  
}

void loop(void)
{
   
   float sensorValue = analogRead(A0);
   sensorValue =  sensorValue/10000;   
   int amplitude = analogRead(A2)/2;
   //float voltage = sensorValue * (5.0 / 1023.0);
   degree = sensorValue+degree;// * (360.0 / 1023.0);
   if(degree>=360)
   {
     degree = 0;
   }
   float rads = degree*(pi/180);
   int PWM1 = squ*amplitude*(sin(rads)+1/6*sin(3*rads))+511; //OM
   int PWM2 = squ*amplitude*(sin(rads-(2*pi/3))+1/6*sin(3*rads))+511; //OM
   int PWM3 = squ*amplitude*(sin(rads-(4*pi/3))+1/6*sin(3*rads))+511; //OM

   
   
   //MOTOR1
    Timer1.pwm(fanPin1, PWM1);
    Timer1.pwm(fanPin2, PWM2); 
    Timer1.pwm(fanPin3, PWM3); 
    //MOTOR2
    Timer1.pwm(fanPin4, PWM1);
    Timer1.pwm(fanPin5, PWM2); 
    Timer1.pwm(fanPin6, PWM3); 
    //MOTOR3
    Timer1.pwm(fanPin7, PWM1);
    Timer1.pwm(fanPin8, PWM2); 
    Timer1.pwm(fanPin9, PWM3); 
//    Serial.println(PWM1);
//    Serial.println(PWM2);
//    Serial.println(PWM3);
//    delay(1000);

    
   
}

To make the code work you should use two potentiometers to provide amplitude and speed control of your pwm. The amplitude in fact represents the torque of the motor and the speed is simulated here because I haven’t succeeded in attaching a resolver to the motor. In fact that is not the fully correct formula because it lacks a lot of calculations from feed back.

Here is a flow chart of the process itself.

In fact this is a very interesting topic and I wanted to start it for a couple of weeks already trying to finish my project. I have managed to drive the motor with this code but the model still lacks a lot of mathematics I have no idea to get from.

mohamadreza_mohamadi:
brushless DC motor

What kind of brushless DC motor, sensored, sensorless, slotless, slotted, what power level,
what nominal voltage...