As an Amazon Associate we earn from qualifying purchases.
more data will publish after one month reference –- microchip an970
- http://ww1.microchip.com/downloads/en/AppNotes/00857B.pdf
#define hall_blue 5 //hall sensor not used
#define hall_yellow 7
#define hall_green 6
#define timout_bemf 5000
//order G Y B
#define bemf_blue 8
#define bemf_yellow 9
#define bemf_green 10
#define blue_high A1
#define blue_low A0
#define yellow_high A3
#define yellow_low A2
#define green_high A5
#define green_low A4
int blue, green, yellow;
int count;
int state;
void setup()
{
Serial.begin(115200);
pinMode(bemf_blue, INPUT);
pinMode(bemf_yellow, INPUT);
pinMode(bemf_green, INPUT);
hall_sensor_init();
motor_pin_init();
off_all();
on_low_side_mosfet_and_charge_bootstrap();
Serial.println("haiu");
off_all();
count = 0;
while (count < 2)
{
run_motor_without_sensor_anti_clock ();
count++;
}
off_all(); delay(1);
}
void loop()
{
motor_run_clockwise_using_back_emf();
}
void run_motor_without_sensor_anti_clock(void)
{
off_all();
digitalWrite(yellow_high, HIGH);
digitalWrite(green_low, HIGH);
off_all_delay();
digitalWrite(yellow_high, HIGH);
digitalWrite(blue_low, HIGH);
off_all_delay();
digitalWrite(green_high, HIGH);
digitalWrite(blue_low, HIGH);
off_all_delay();
digitalWrite(green_high, HIGH);
digitalWrite(yellow_low, HIGH);
off_all_delay();
digitalWrite(blue_high, HIGH);
digitalWrite(yellow_low, HIGH);
off_all_delay();
digitalWrite(blue_high, HIGH);
digitalWrite(green_low, HIGH);
off_all_delay();
//
}
void run_motor_without_sensor (void)
{
off_all_delay();
digitalWrite(blue_high, HIGH);
digitalWrite(yellow_low, HIGH);
// off_all_delay();
///digitalWrite(blue_high, HIGH);
// digitalWrite(green_low, HIGH);
off_all_delay();
digitalWrite(yellow_high, HIGH);
digitalWrite(green_low, HIGH);
// off_all_delay();
// digitalWrite(yellow_high, HIGH);
// digitalWrite(blue_low, HIGH);
read_hall_sensors();
off_all_delay();
digitalWrite(green_high, HIGH);
digitalWrite(blue_low, HIGH);
off_all_delay();
// digitalWrite(green_high, HIGH);
// digitalWrite(yellow_low, HIGH);
off_all();
}
void motor_run_clockwise_using_back_emf(void)
{
read_bemf_sensors(); off_all();
count = 0;
while (blue == 1 && yellow == 0 && green == 1 && count < timout_bemf) //101
{
digitalWrite(blue_high, HIGH);
digitalWrite(yellow_low, HIGH);
read_bemf_sensors(); count++;
}
off_all(); count = 0;
while (blue == 1 && yellow == 0 && green == 0 && count < timout_bemf) //100 -byg
{
digitalWrite(blue_high, HIGH);
digitalWrite(green_low, HIGH);
read_bemf_sensors(); count++;
}
off_all(); count = 0;
while (blue == 1 && yellow == 1 && green == 0 && count < timout_bemf) //110
{
digitalWrite(yellow_high, HIGH);
digitalWrite(green_low, HIGH);
read_bemf_sensors(); count++;
}
off_all(); count = 0;
while (blue == 0 && yellow == 1 && green == 0 && count < timout_bemf) //010
{
digitalWrite(yellow_high, HIGH);
digitalWrite(blue_low, HIGH);
read_bemf_sensors(); count++;
}
off_all(); count = 0;
while (blue == 0 && yellow == 1 && green == 1 && count < timout_bemf) //011
{
digitalWrite(green_high, HIGH);
digitalWrite(blue_low, HIGH);
read_bemf_sensors(); count++;
}
off_all(); count = 0;
while (blue == 0 && yellow == 0 && green == 1 && count < timout_bemf) //001
{
digitalWrite(green_high, HIGH);
digitalWrite(yellow_low, HIGH);
read_bemf_sensors(); count++;
}
}
void off_all_delay(void)
{
delayMicroseconds(2000); PORTC = 0;
/*
digitalWrite(blue_low, LOW);
digitalWrite(blue_high, LOW);
digitalWrite(yellow_low, LOW);
digitalWrite(yellow_high, LOW);
digitalWrite(green_low, LOW);
digitalWrite(green_high, LOW);
//delayMicroseconds(1);
*/
}
void read_bemf_sensors(void)
{
blue = digitalRead(bemf_blue);
yellow = digitalRead(bemf_yellow);
green = digitalRead(bemf_green);
//display_sensor_data();
//Serial.println(PINB & 7);
}
void motor_run_clockwise(void)
{
off_all(); read_hall_sensors();
while (blue == 1 && yellow == 0 && green == 1)//101
{
digitalWrite(blue_high, HIGH);
digitalWrite(yellow_low, HIGH);
read_hall_sensors();
}
off_all();
while (blue == 1 && yellow == 0 && green == 0) //100 -byg
{
digitalWrite(blue_high, HIGH);
digitalWrite(green_low, HIGH);
read_hall_sensors();
}
off_all();
while (blue == 1 && yellow == 1 && green == 0) //110
{
digitalWrite(yellow_high, HIGH);
digitalWrite(green_low, HIGH);
read_hall_sensors();
}
off_all();
while (blue == 0 && yellow == 1 && green == 0) //010
{
digitalWrite(yellow_high, HIGH);
digitalWrite(blue_low, HIGH);
read_hall_sensors();
}
off_all();
while (blue == 0 && yellow == 1 && green == 1)//011
{
digitalWrite(green_high, HIGH);
digitalWrite(blue_low, HIGH);
read_hall_sensors();
}
off_all();
while (blue == 0 && yellow == 0 && green == 1)//001
{
digitalWrite(green_high, HIGH);
digitalWrite(yellow_low, HIGH);
read_hall_sensors();
}
off_all();
}
void fault(void)
{
//------------fault-------
if (blue == 1 && yellow == 1 && green == 1) //000
{
off_all();
do
{
Serial.println("fault!!!!!");
read_hall_sensors(); display_sensor_data();
} while (blue == 1 && yellow == 1 && green == 1);
}
else if (blue == 0 && yellow == 0 && green == 0) //111
{
off_all();
do
{
Serial.println("fault!!!!!");
read_hall_sensors(); display_sensor_data();
} while (blue == 0 && yellow == 0 && green == 0);
}
//------------fault-------
}
void off_all(void)
{
PORTC = 0;
/*
digitalWrite(blue_low, LOW);
digitalWrite(blue_high, LOW);
digitalWrite(yellow_low, LOW);
digitalWrite(yellow_high, LOW);
digitalWrite(green_low, LOW);
digitalWrite(green_high, LOW);
//delayMicroseconds(1);
*/
}
void read_hall_sensors(void)
{
blue = !digitalRead(hall_blue);
yellow = !digitalRead(hall_yellow);
green = !digitalRead(hall_green);
// recharge_boot();
//display_sensor_data();
}
void delay_for_phase(void)
{
// Serial.write('a');
// delayMicroseconds(10);
}
void recharge_boot(void)
{ delayMicroseconds(10);
PORTC = 0;
delayMicroseconds(1);
digitalWrite(blue_low, HIGH);
digitalWrite(yellow_low, HIGH);
digitalWrite(green_low, HIGH);
delayMicroseconds(1);
PORTC = 0;
}
void on_low_side_mosfet_and_charge_bootstrap(void)
{
digitalWrite(blue_low, HIGH);
digitalWrite(yellow_low, HIGH);
digitalWrite(green_low, HIGH);
delay(1000); off_all(); delay(1);
}
void motor_pin_init(void)
{
pinMode(blue_high, OUTPUT);
pinMode(blue_low, OUTPUT);
pinMode(yellow_high, OUTPUT);
pinMode(yellow_low, OUTPUT);
pinMode(green_high, OUTPUT);
pinMode(green_low, OUTPUT);
}
void display_sensor_data(void)
{
//Serial.print("b-");
Serial.print(blue);
//Serial.print("-y=");
Serial.print(yellow);
//Serial.print("-g=");
Serial.println(green);
}
void hall_sensor_init(void)
{
pinMode(hall_blue, INPUT_PULLUP);
pinMode(hall_yellow, INPUT_PULLUP);
pinMode(hall_green, INPUT_PULLUP);
}
void test_fan_driver(void)
{
off_all();
digitalWrite(blue_low, HIGH);
digitalWrite(yellow_low, HIGH);
digitalWrite(green_low, HIGH);
delayMicroseconds(1000); off_all();
digitalWrite(blue_high, HIGH);
digitalWrite(yellow_high, HIGH);
digitalWrite(green_high, HIGH);
delayMicroseconds(1000);
}
How Sensorless BLDC Control Works and What to Check When It Fails
A brushless motor needs to know the rotor position so the driver can energize the right pair of phases at the right moment. Hall sensors give that position directly. Without them, the controller uses back-EMF instead. At any moment in a six-step sequence, two phases carry current and the third is left floating. The voltage on that floating phase moves as the rotor magnets pass it, and the point where it crosses a reference level (usually about half the supply voltage) tells the controller where the rotor is. The sketch above reads those three back-EMF signals and picks the next step from the three-bit pattern.
Back-EMF is proportional to speed, so it is too small to read when the motor is stopped or turning very slowly. That is why the sketch first runs a short open-loop start, stepping through the phases with fixed delays, and only then switches to the back-EMF loop. If the start-up steps are too fast or too slow for your motor, it will twitch or stall instead of picking up speed.
The sketch reads the back-EMF pins with digitalRead, so each phase signal must reach the Arduino as a clean logic-level signal. In practice this means scaling the phase voltage down, usually with a resistor divider, and often comparing it with a reference before it reaches the pin. The exact values depend on your supply voltage and motor.
Troubleshooting checklist
- Motor vibrates but does not spin: try a slower open-loop start, or swap two motor phase wires and check that the phase names in the code match your wiring.
- Runs briefly, then stops: the back-EMF signal may be noisy or the timeout may be too short. Check the divider and ground connections.
- Driver or MOSFETs get hot: make sure a high-side and low-side switch on the same phase are never on together, and check your gate driver’s dead-time requirements.
- High side does not switch: if you use bootstrap gate drivers, the bootstrap capacitors must be charged first. The sketch does this by turning on the low-side MOSFETs at start-up.
For first tests, use a current-limited bench supply and keep the motor unloaded with nothing attached to the shaft.