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:

Leave a Reply

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