use pwm to run bldc motor

Hye guys, i'm doing my fyp on building a spin coater. My supervisor wanted me to use PWM to run a bldc motor. The problem is, i have read and done my research , PWM seem to be able to run only DC motor where it send signals to regulate the voltage the spins the dc motor. But for BLDC motor , i need to use ESC to control the speed and uses the servo library. So my question is, can PWM drive a bldc motor or i just have to use the ESC?

PWM is used to control a brushed DC motor with a transistor to switch power. if you want to reverse the direction you need an H brige. PPM is used as the input signal for an ESC which is essntially an h bridge for each phase of the bldc motor. that is three h bridges that need to be switched on and off at the right frequency in order to get movement. Then for speed detection you need to measure reverse emf on the phase which is not powered.

In short, making a controller fora bldc motor is an artform and unlikely to be succesfull first time. Making a controller for a DC is fairly simple.

The best option is to buy an ESC and feed it the "PWM" signal from the servo library, I have done this and it works.

The Servo library outputs a variable width pulse so you can honestly say "Yes, I used PWM to control the BLDC motor". :)

If you use servo.writeMicroseconds(1000 to 2000) that will make the "PWM" aspect clearer than if you use the servo.write(0 to 180) intended to move a servo control arm.

What do you think an ESC is?

It’s a microcontroller using PWM to control a few MOSFETs. You could roll your own, but as spruce_m00se noted, this is a non-trivial project in and of itself.

Atmel actually makes a few chips specifically designed for controlling BLDC motors, with features like built-in dead time generation, the inverted outputs for all the relevant pwm channels, and the ability to run the timer at an obscene clock rate (up to 64mhz) - all things that you need if you’re directly controlling a BLDC motor (or, for example, building an ESC). The ATTiny85 gives two complementary PWM outputs, while the ATTiny861 has three complementary PWM outputs - both have some specialized PWM modes for using these features for driving BLDC motors, too (though you never hear about this on the tiny85, despite everyone and their mom using them)

DrAzzy

whilst talking about PWM and the attiny85............ does the pwm you mention run faster than a standard analogue write would on the attiny at 1mhz? I see a lot of flicker on a project (the same one I cant get serial to work for)

Maybe an attiny 85 would be better than an 84 for my needs if I can do without the extra pins.

thanks all for the answers… i appreciated it very much…Thanks!!!

Mr John Wasser…

this is my code… not yet complete…i uses minpulse and maxpulse valued 1000 and 2000… does that mean i have apply PWM in my code??

#include <Servo.h>
#include <Keypad.h>
Servo esc;

int escPin = 9;
int minPulseRate = 1000;
int maxPulseRate = 2000;
int throttleChangeDelay = 100;
int currentCommand=0;
int keyIn;

char Data[2];
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{‘1’,‘2’,‘3’},
{‘4’,‘5’,‘6’},
{‘7’,‘8’,‘9’},
{’*’,‘0’,’#’}
};
byte rowPins[ROWS] = {8,7,6,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4,3,2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {

Serial.begin(9600);
Serial.setTimeout(500);

// Attach the the servo to the correct pin and set the pulse range
esc.attach(escPin, minPulseRate, maxPulseRate);
// Write a minimum value (most ESCs require this correct startup)
esc.write(0);

}

void loop() {
char key = keypad.getKey();
if(key != NO_KEY) // Do nothing if no key is pressed, incorporated from PaulS’s example.
{
if (key !=’*’)
{

Data[currentCommand++] = key;
keyIn = atoi(Data);
}

{

// Read the new throttle value
int throttle = keyIn;

// Print it out
Serial.print("Setting throttle to: ");
Serial.print(keyIn);

// Change throttle to the new value
changeThrottle(throttle);

}

}
}

void changeThrottle(int throttle) {

// Read the current throttle value
int currentThrottle = readThrottle();

// Are we going up or down?
int step = 1;
if( throttle < currentThrottle )
step = -1;

// Slowly move to the new throttle value
while( currentThrottle != throttle )

{
esc.write(currentThrottle + step);
currentThrottle = readThrottle();
delay(throttleChangeDelay);
}

}

int readThrottle() {
int throttle = esc.read();

return throttle;
}

// Ensure the throttle value is between 0 - 180
int throttle(int keyIn) {
if( keyIn < 0 )
return 0;
if( keyIn > 180 )
return 180;
return keyIn;
}

raidjoker94: this is my code... not yet complete..i uses minpulse and maxpulse valued 1000 and 2000.. does that mean i have apply PWM in my code??

Yes. The Servo library always uses a form of "PWM".

ok... thanks so much..!!!

raidjoker94:
thanks all for the answers… i appreciated it very much…Thanks!!!

Mr John Wasser…

this is my code… not yet complete…i uses minpulse and maxpulse valued 1000 and 2000… does that mean i have apply PWM in my code??

#include <Servo.h>
#include <Keypad.h>
Servo esc;

int escPin = 9;
int minPulseRate = 1000;
int maxPulseRate = 2000;
int throttleChangeDelay = 100;
int currentCommand=0;
int keyIn;

char Data[2];
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{‘1’,‘2’,‘3’},
{‘4’,‘5’,‘6’},
{‘7’,‘8’,‘9’},
{’*’,‘0’,’#’}
};
byte rowPins[ROWS] = {8,7,6,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4,3,2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {

Serial.begin(9600);
Serial.setTimeout(500);

// Attach the the servo to the correct pin and set the pulse range
esc.attach(escPin, minPulseRate, maxPulseRate);
// Write a minimum value (most ESCs require this correct startup)
esc.write(0);

}

void loop() {
char key = keypad.getKey();
if(key != NO_KEY) // Do nothing if no key is pressed, incorporated from PaulS’s example.
{
if (key !=’*’)
{

Data[currentCommand++] = key;
keyIn = atoi(Data);
}

{

// Read the new throttle value
int throttle = keyIn;

// Print it out
Serial.print("Setting throttle to: ");
Serial.print(keyIn);

// Change throttle to the new value
changeThrottle(throttle);

}

}
}

void changeThrottle(int throttle) {

// Read the current throttle value
int currentThrottle = readThrottle();

// Are we going up or down?
int step = 1;
if( throttle < currentThrottle )
step = -1;

// Slowly move to the new throttle value
while( currentThrottle != throttle )

{
esc.write(currentThrottle + step);
currentThrottle = readThrottle();
delay(throttleChangeDelay);
}

}

int readThrottle() {
int throttle = esc.read();

return throttle;
}

// Ensure the throttle value is between 0 - 180
int throttle(int keyIn) {
if( keyIn < 0 )
return 0;
if( keyIn > 180 )
return 180;
return keyIn;
}

can i get the finished code?