Wednesday, February 11, 2015

Cd-Rom Brushless DC Motor Control

Sensored BLDC Motor Control Using PIC16F877A
Sensored BLDC Motor Control 

This topic shows how to control sensored brushless dc motor. This motor is three phase motor, it has three stator phases that are excited two at a time to create arotating electric field. This method is fairly easy to implement, but to prevent the permanent magnet rotor from getting locked with the stator, the excitation on the stator must be sequenced in a specific manner while knowing the exact position of the rotor magnets. Position information can be gotten by either a shaft encoder or, more often, by Hall effect sensors that detect the rotor magnet position. For a typical threephase, sensored BLDC motor there are six distinct regions or sectors in which two specific windings are excited.
Related Topics:
Cd-Rom 3 phase Sensored BLDC Motor Arduino Controller
Sensored Cd-Rom BLDC Motor Hall Effect Sensors

Three Phase BLDC Motor Bridge
bldc motor controller

By reading the Hall effect sensors, a 3-bit code can be obtained with values ranging from 1 to 6. Each code value represents a sector on which the rotor is presently located. Each code value, therefore, gives us information on which windings need to be excited. Thus
a simple lookup table can be used by the program to determine which two specific windings to excite and, thus, turn the rotor.
Note that state ‘0’ and ‘7’ are invalid states for Hall effect sensors. Software should check for these values and appropriately make all outputs equal to zero.

Change Notification Input:
Most of the microchip microcontrollers equipped withan interrupt called RB port change interrupt which means that when at least one of the RB7:RB4 pins changed state an interrupt will be occurred. This interrupt allows us to connect our three wires which comes from hall sensors to pins RB4, RB5, and RB6 (RB7 is connected to +Vcc).

bldc motor controller bridge
bldc motor controller com

BLDC motor controller circuit:
The complete circuit is shown in the following image:

bldc brushless dc motor controller driver circuit pic16f877a mikroc code microcontroller

There are tow switches, one for start and the other for stop the motor. The potentiometer is used to control the speed of the motor. The LED is on when the system at on state. RB7 must be connected to +5V because we have RB port change interrupt and we need only 3 inputs.
For the three phase bridge and hall effect sensors boxes are explained on the related topics above.
BLDC motor controller mikroC code:
We have three interrupts in our code:
1- External interrupt: RB0 connected to push button used to stop the motor,
2- RB port change interrupt: used to interrupt when the motor changes its position,
3- Timer1 interrupt: interrupts every 100ms to read the analog value on AN0 and generate its corresponding pwm signal.
The code is written using MikroC for PIC compiler.

//Sensored BLDC Motor Control Using PIC16F877A
//Used microcontroller: PIC16F877A @ 12MHz
//Written by: BENCHEROUDA Okba
//All rights reserved
//Use at your own risk

unsigned short hall;
unsigned char MoveTable[8] = {0, 33, 6, 36, 24, 9, 18, 0};
unsigned   dt, dt0;
void Interrupt(){
  if(INTF_bit){    //External Interrupt occurred
  INTCON = 0;      //Disable all interrupts
  PORTB.F2 = 0;
  PORTD = 0;
  if (TMR1IF_bit){        //Timer1 Interrupt occurred
    TMR1IF_bit = 0;
    TMR1H         = 0x6D;
    TMR1L         = 0x84;
  dt = ADC_Read(0);   //Read analog value
  if (dt != dt0) {
  dt0 = dt;
  dt0 = dt0 >> 2;
  PWM1_Start(); }
  if (RBIF_bit){      //Pin change Interrupt occurred
  RBIF_bit = 0;
  hall = PORTB;
  hall = hall & 112;
  hall = hall >> 4;
  PORTD = MoveTable[hall];
void InitInterrupts(){
  T1CON         = 0x31;
  TMR1IF_bit    = 0;
  TMR1H         = 0x6D;
  TMR1L         = 0x84;
  TMR1IE_bit    = 1;
  INTCON        = 0;     //Disable all interrupts
void main() {
 ADCON1 = 14;                // Configure AN0 as analog
 CMCON  = 7;                //Disable comparators
 PORTB = 0; 
 TRISB = 243;
 PORTD = 0;
 TRISD = 0;

  while(PORTB.F1);   //wait for start key hit
  while(!PORTB.F1);  // wait till key is released
  PORTB.F2 = 1;
  hall = PORTB;
  hall = hall & 112;
  hall = hall >> 4;
  PORTD = MoveTable[hall];
  INTCON        = 0xD8;   //Enable all interrupts

Sensored BLDC Motor Control Using PIC16F877A video:
The following video shows the experiment.

Microchip: Sensored BLDC Motor Control Using dsPIC30F2010 (AN957).
Microchip: Brushless DC Motor Control Made Easy (AN857).