Sensorless BLDC motor control with PIC microcontroller and mikroC

This post shows how to control a sensorless brushless DC (BLDC) motor using PIC16F887 microcontroller. The compiler used in this project is MikroElektronika mikroC PRO for PIC.

Basically there are two types of brushless motors: sensored and sensorless. Sensored BLDC motors come with three hall effect sensors which are used to detect (know) the position of the rotor (where it is located) at any moment, that’s why they called sensored.
The second type is: sensorless BLDC motors. Sensorless BLDC motor has no sensor to detect the rotor position, it has only 3 wires for power (3-phase). The commutation of sensorless BLDC motor is based on the BEMF (Back Electromotive Force) produced in the stator windings.

The main advantage of the sensorless BLDC motor control is lower system cost and the main disadvantage is the motor must be moving at minimum rate to produce sufficient BEMF to be sensed.

The following page contains a brief information about the BEMF technique:
Brushless DC motor control with PIC16F887 microcontroller

Components Required:

  • PIC16F887 microcontroller – datasheet
  • Brushless DC motor
  • 6 x 06N03LA N-type mosfet (or equivalent)  – datasheet
  • 3 x IR2101 (or IR2101S) gate driver IC  – datasheet
  • 6 x 33k ohm resistor
  • 3 x 10k ohm resistor
  • 6 x 10 ohm resistor
  • 3 x IN4148 diode
  • 3 x 10uF capacitor
  • 3 x 2.2uF capacitor
  • 20 MHz crystal oscillator
  • 2 x 22pF ceramic capacitor
  • 10k ohm potentiometer
  • 12V source
  • 5V source
  • Breadboard
  • Jumper wires

Sensorless BLDC motor control with PIC16F887 circuit:
Project circuit schematic diagram is shown below.

PIC16F887 Brushless dc motor controller DIY ESC circuit

All grounded terminals are connected together.

Sensorless BLDC motor control with PIC16F887 code:
The following C code is for mikroC PRO for PIC compiler. Configuration words are:
CONFIG1 = 0x2CD2
CONFIG2 = 0x0700

Timer2 module is configured to give a PWM signal with frequency of 19.53 KHz and resolution of 10 bits (prescaler = 1 and preload value = 255).
PWM frequency and resolution can be calculated using the functions below (Fosc = 20 MHz):
PWM_freqency = Fosc/{[(PR2) + 1] * 4 * (TMR2 Prescaler Value)} = 19.53 KHz
Resolution = log[4(PR2 + 1)]/log(2) = 10 bits

mikroC PRO for PIC code:

Finally this video shows a simple hardware circuit of the project:

20 thoughts on “Sensorless BLDC motor control with PIC microcontroller and mikroC”

  1. Trying to convert the code to MPLAB and I get Function Interrupt() is never used. How does this function get triggered?

  2. Buenas tardes, excelente proyecto, felicitaciones. Disculpe, tengo una consulta, quizás me puede ayudar. Yo estoy implementando ese mismo proyecto pero con un LPC1769, este microcontrolador no posee la interrupción de comparación que usa usted, habrá alguna manera de hacer eso mismo sin interrupciones? Desde ya, muchas gracias.

  3. Where i can get proteus bldc motor used in this simulation i am getting only sensord motor but i am not able to find sensorless motor in proteus.help me.

  4. The program work corect but the DEBOUNCING of feed back not work corect . the PWM high frecventi distorsion the EMF . I put 3x 100n cond paralel to 3x 10K resistor to filtrate the EMF. , and now work very nice.
    I want in the future to add a START subrutine for start with mechanical load.
    The second wish is to convert the code for PIC16F15344 or appropiate in 16F153xx family. Can you help me for this ?? the comparator module is diferent for this faamily.

  5. I constructed all the circuits correct way, but when I give the power to the system, motors just making some sound and not turning. What should I do ?

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top