You are on page 1of 28

BLDC Motor Control

using
dSPIC Microcontroller
How to Guide
PANTECH PROLABS INDIA PVT LTD.
No:41 Santhosh nagar, Rajeshwari street, Kandhanchavadi, Chennai - 600 096
Ph: 044 – 6452 4445/46/47 | Fax: 044 – 4260 6350| www.pantechsolutions.net
BRANCHES @ CHENNAI | COIMBATORE | MADURAI | HYDERABAD | BANGALURU | COCHIN | PUNE
BLDC Motor Control using DSPIC Microcontroller

Table of Contents
Introduction ................................................................................................................. 3
BLOCK DIAGRAM OF BLDC MOTOR SPEED CONTROL ................................. 4
Block Diagram ............................................................................................................ 6
BLDC Motor Specifications........................................................................................ 7
Motor Working Pattern ............................................................................................... 9
Commutation details for BLDC 3 Phase Inverter Card ........................................... 10
3 Phase H-Bridge Inverter (MOSFET/IGBT) BOARD ............................................ 11
TLP 250 DRIVER BOARD ...................................................................................... 12
dSPIC30F4011 Evaluation Board ............................................................................. 14
dSPIC30F4011 connection details ............................................................................ 15
Feedback Block From Motor To Dspic30f4011 ....................................................... 17
Flowchart Of BLDC Motor Speed Control ............................................................... 18
Source Code For BLDC Motor Speed Control ......................................................... 20

www.pantechsolutions.net Page 2
BLDC Motor Control using DSPIC Microcontroller

Introduction

This project describes the speed control of BLDC motor with the
dsPIC30F4011 Digital Signal Controller. By using the Hall effect
sensors of BLDC Motor, the dsPIC30F4011 controller generates the
controlled switching pulses for inverter. The speed control is done by
changing the duty cycle of PWM from dsPIC30F4011. The motor speed
is measured by using the proximity sensor placed on the BLDC Motor
and displayed on LCD.

This development kit used to design and develop controller for BLDC. All the parts
are separately available in the DIY market.

www.pantechsolutions.net Page 3
BLDC Motor Control using DSPIC Microcontroller

BLOCK DIAGRAM OF BLDC MOTOR SPEED


CONTROL

Rotational Phase A
A Phase Comparator Top
Increment PWM Phase A Bottom
Generator Unit A
Push Switch Bottom
3 Phase
Phase B Top
B Phase Comparator
A Unit B Phase B Bottom
Get Hall Bottom
Sensor B Phase C Top
Signals C Phase
C Comparator Phase C Bottom
Unit C Bottom
PWM
Unit

From BLDC
Motor

The Hall Effect sensor signals are read from the BLDC motor and
it fed as inputs to the DSPIC30F4011 device. A 3-bit code can be
obtained with values ranging from 1 to 6 by reading the Hall sensor. The
duty cycle of the PWM is varied by using an rotational increment push
switch. These PWM pulses are enabled as based on the 3-bit code
getting from Hall Effect sensor signal. There are six PWM pulses are
generated to operate the three phase inverter. The BLDC Motor speed is
adjusted by varying the PWM duty cycle.

www.pantechsolutions.net Page 4
BLDC Motor Control using DSPIC Microcontroller

Bundle of Contents

1. 60W BLDC Motor


2. 3Phase Inverter
3. dSPIC30F4011 Evaluation Board
4. 230/24V, 50Hz Transformer
5. 230/12V, 50Hz for Driver Circuit
6. TLP250 based 3 Leg Driver Board
7. 9V Adaptor

www.pantechsolutions.net Page 5
BLDC Motor Control using DSPIC Microcontroller

Block Diagram

In this project the BLDC motor is controlled by dSPIC30F4011 DSP Processor. The
24V BLDC Motor power is converted from 24V AC and Full wave rectifier. The
3Ph Inverter circuit formed using IRFP250 MOSFET and its gate is driven by
TLP250 with separate isolator for TOP and BOTTOM MOSFET from dSPIC
Processor.

230/24V
Rectifier BLDC
AC, 3 Phase Inverter
With Filter Motor
Transformer

230/12V
AC, TLP250 Based Driver
Transforme
r

9V Adaptor dSPIC30F4011
Evaluation Board

www.pantechsolutions.net Page 6
BLDC Motor Control using DSPIC Microcontroller

BLDC Motor Specifications

The BLDC Motor is highly reliable and having torque. In industry the BLDC motor
is used widely. The rotor part of the motor is rotated based on the stator excitation.
The entire operation of BLDC motor can be divided into 6 modes. Each mode has
separated 60 degree. All the Hall Sensors (A,B, C) are mounted at 120 degree phase
shift. And will be HIGH for 180 degree of 360 degree rotation.

SPECIFICATION
 Power : 60W
 Voltage : 24V
 Speed : 3000 RPM

Motor Terminal Identification

Sensor output RMC:


Black GND
Yellow +Ve
Brown (Hall A) IC 5th Pin
Orange (Hall B) IC 6th Pin
Red (Hall C) IC 7th Pin

www.pantechsolutions.net Page 7
BLDC Motor Control using DSPIC Microcontroller

PWM Outputs

Pulse 1 H1
Pulse 2 L1
Pulse 3 H2
Pulse 4 L2
Pulse 5 H3
Pulse 6 L3

Phase Winding

Red Phase1
White Phase2
Black Phase3

Pulse Truth Table

Forward:

Hall A Hall B Hall C H1 L1 H2 L2 H3 L3


0 0 1 0 1 0 0 1 0
1 0 1 0 0 0 1 1 0
1 0 0 1 0 0 1 0 0
1 1 0 1 0 0 0 0 1
0 1 0 0 0 1 0 0 1
0 1 1 0 1 1 0 0 0

Reverse:

Hall A Hall B Hall C H1 L1 H2 L2 H3 L3


0 0 1 1 0 0 0 0 1
0 1 0 0 0 0 1 1 0
0 1 1 1 0 0 1 0 0
1 0 0 0 1 1 0 0 0
1 0 1 0 0 1 0 0 1
1 1 0 0 1 0 0 1 0

www.pantechsolutions.net Page 8
BLDC Motor Control using DSPIC Microcontroller

Motor Working Pattern

HALL A
60 120 180 240 300 360 degree
HALL B

HALL C

PWM1

PWM2

PWM 3

PWM4

PWM5

PWM 6

VAB

VBC

VCA

www.pantechsolutions.net Page 9
BLDC Motor Control using DSPIC Microcontroller

Commutation details for BLDC 3 Phase Inverter Card

The inverter card comes with inbuilt full bridge rectifier and filter capacitor. 6 Nos
of IRFP250 MOSFETs are mounted with Heat sink. The output of the inverter is
terminated with 3 pin PTB Connector. The user should get soldered on back side of
the board for gate pulse interface.
 6 Nos of IRFP250 MOSFET are mounted with proper Heat sink
 5A Bridge Rectifier with DC Filter Capacitor(1000uF/100V)
 3 Pin PTB Connector provided to connect Motor

INVERTER SCHEMATIC DIAGRAM

www.pantechsolutions.net Page 10
BLDC Motor Control using DSPIC Microcontroller

3 Phase H-Bridge Inverter (MOSFET/IGBT) BOARD

INVERTER BOARD
Specification
 6 Nos of IRFP250 MOSFET with Heatsink
 Input Voltage 100V/AC/50Hz
 Operating Frequency 25 KHz
 Input and Outputs are terminated with PTB Connectors

TLP 250 DRIVER BOARD


Specification
 6 Nos Opto-Isolated Gate Drive
 Input Voltage 12V/AC/50Hz
 Output pulse Voltage: 15V
 Operating Frequency 25 KHz
 All input and outputs are terminated with RMC Male Connectors

www.pantechsolutions.net Page 11
BLDC Motor Control using DSPIC Microcontroller

TLP 250 DRIVER BOARD

www.pantechsolutions.net Page 12
BLDC Motor Control using DSPIC Microcontroller

Tlp 250 Driver Schematic Diagram

Block Diagram

12V
AC
G1
11
S1
2VA 11
G2
C 1
S2

12V
AC
G3
S3
12V G4
AC1
S4
GND
PWM1
Pulse G5
PWM2
From S5
PWM3
MCU/DSP G6
PWM4
PWM5 /FPGA S6
PWM6

PIN Details

SI.No Header Description


1 J1, J3, J4, J6 Input 12VAC Power Supply
2 J7 Input Pulses (+3V or +5V) for Driver
PWM Output corresponds to
3 J2 PWM1(G1,S1)
PWM2(G2,S2)
PWM Output corresponds to
4 J5 PWM3(G3,S3)
PWM4(G4,S4)
PWM Output corresponds to
5 J8 PWM5(G5,S5)
PWM6(G6,S6)

www.pantechsolutions.net Page 13
BLDC Motor Control using DSPIC Microcontroller

dSPIC30F4011 Evaluation Board

 3 Nos. of switches for interrupt study


 USB 2.0 ISP Programming Facility
 1 No of 10-Pin Expansion Connector
 2 Nos. of 40 Pin Expansion Connector
 On-Board 5V Regulator @ 1.5A
 Reset Circuit
 Power-on LED Indication
 40-pin ZIF Socket for MCU
 2x16 LCD Socket
 2 Nos. of USART (RS232)
 ADC Analog Input (Potentiometer)
 General purpose area

www.pantechsolutions.net Page 14
BLDC Motor Control using DSPIC Microcontroller

dSPIC30F4011 connection details

Input to dSPIC30F4011 Evaluation Board


Black GND
Yellow +Ve
Brown (Hall A) IC 5th Pin
Orange (Hall B) IC 6th Pin
Red (Hall C) IC 7th Pin

Output From dSPIC30F4011 Evaluation


Board
IC 4011 Driver Board J7
GND 1
th
IC 38 Pin 2
th
IC 37 Pin 3
th
IC 36 Pin 4
th
IC 35 Pin 5
th
IC 34 Pin 6
th
IC 33 Pin 7

www.pantechsolutions.net Page 15
BLDC Motor Control using DSPIC Microcontroller

HALL EFFECT SENSOR SWITCHING SEQUENCE OF


INVERTER

A Hall-effect position sensor is used to sense the rotor position on a


span of 60◦, which is required for the electronic commutation of the
BLDC motor. There are six steps are used to cause a full revolution (6
steps x 60° = 360°). For each step, positive position means high side
MOSFET on and low side off, negative position means high side
MOSFET off and low side on, and neutral position means both
MOSFET’s are on.

www.pantechsolutions.net Page 16
BLDC Motor Control using DSPIC Microcontroller

Feedback Block From Motor To Dspic30f4011

BLDC
Motor

Hall Effect
Sensor

dsPIC30F4011
Controller

RPM and Duty


Cycle values
display in LCD

The BLDC Motor actual speed is measured in dsPIC30F4011 by


using a feedback signal. The feedback signal is getting from BLDC
Motor by using Hall Effect sensor. The dsPIC30F4011 controller
displays the motor speed as a RPM value in LCD.

www.pantechsolutions.net Page 17
BLDC Motor Control using DSPIC Microcontroller

Flowchart Of BLDC Motor Speed Control

START

PWM, Capture and Port pins


Initialization

Read Hall Effect Sensor


Display in LCD

Is Increment switch
pressed?

Increase the PWM duty cycle


Display in LCD

PWM Enables based on Hall


Effect Sensor signals

Generate PWM Top and


Bottom pulses

BLDC Motor

www.pantechsolutions.net Page 18
BLDC Motor Control using DSPIC Microcontroller

First, Initialize the PWM, Capture, Ports and the Change


Notification inputs. After initializing, the capture and change
notification pins are read the hall sensor signals. It detects the input
signal of hall sensor and allowed to enable the corresponding phase of
PWM pulses. At this point the motor starts spinning. The Motor speed is
varied depending on the PWM duty cycle which is adjusted by using a
rotational increment key. The duty cycle and speed measurement values
are displayed in LCD.

Steps To Check BLDC Motor Control

 Connect the Hall Sensor inputs to 5, 6 and 7th pins of


dsPIC30F4011 controller
 Connect six PWM output signals to BLDC Motor Drive
 Download BLDC inverter.hex file to dsPIC30F4011 controller
using MPLAB Software.
 Press the increment button to increase the PWM duty cycle
 Display the speed value in RPM in LCD

www.pantechsolutions.net Page 19
BLDC Motor Control using DSPIC Microcontroller

Source Code For BLDC Motor Speed Control

#define POVD1H OVDCONbits.POVD1H


#define POVD1L OVDCONbits.POVD1L
#define POVD2H OVDCONbits.POVD2H
#define POVD2L OVDCONbits.POVD2L
#define POVD3H OVDCONbits.POVD3H
#define POVD3L OVDCONbits.POVD3L

#define POUT1H OVDCONbits.POUT1H


#define POUT1L OVDCONbits.POUT1L
#define POUT2H OVDCONbits.POUT2H
#define POUT2L OVDCONbits.POUT2L
#define POUT3H OVDCONbits.POUT3H
#define POUT3L OVDCONbits.POUT3L

#define cap5 _RB3


#define tcap5 _TRISB3
#define cap7 _RB4
#define tcap7 _TRISB4
#define cap8 _RB5
#define tcap8 _TRISB5

void forward();
void reverse();

unsigned int
duty,deg,Set_point=556,duty_value,frequen,flag=0,flag1=0,flag2,
Speed,direction=0,cap2_count,Prev_cap5;
unsigned long int count,count1;

void __attribute__((__interrupt__)) _CNInterrupt(void)


{
IFS0bits.CNIF = 0;
if(cap5 && !Prev_cap5)
{
TMR1 = 0;
PR1 = 277;
T1CON = 0x8000;
Prev_cap5 = 1;

www.pantechsolutions.net Page 20
BLDC Motor Control using DSPIC Microcontroller

if(direction == 1) {POVD1H = 0;POUT2L = 0;}


else if(direction == 2) {POUT1L = 0;POVD2H = 0;}
}
else if(!cap5 && Prev_cap5)
{
TMR1 = 0;
PR1 = 277;
T1CON = 0x8000;
Prev_cap5 = 1;
if(direction == 1) {POUT1L = 0;POVD2H = 0;}
else if(direction == 2) {POUT1H = 0;POVD2L = 0;}
}
}

void __attribute__((__interrupt__)) _IC7Interrupt(void)


{
IFS1bits.IC7IF = 0;
TMR1 = 0;
PR1 = 277;
T1CON = 0x8000;
if(cap7)
{
if(direction == 1) {POUT1L = 0;POVD3H = 0;}
else if(direction == 2) {POVD1H = 0;POUT3L = 0;}
}
else if(!cap7)
{
if(direction == 1) {POVD1H = 0;POUT3L = 0;}
else if(direction == 2) {POUT1L = 0;POVD3H = 0;}
}
}

void __attribute__((__interrupt__)) _IC8Interrupt(void)


{
IFS1bits.IC8IF = 0;
TMR1 = 0;
PR1 = 277;
T1CON = 0x8000;
if(cap8)
{
if(flag1 == 0)

www.pantechsolutions.net Page 21
BLDC Motor Control using DSPIC Microcontroller

{
cap2_count = 0;
TMR2 = 0;
count1 = 0;
PR2 = 65535;
T2CON = 0x8000;
flag1 = 1;
}
else if(flag1 == 1)
{
T2CON = 0x0000;
count = TMR2 + (count1 * 65535);
flag1 = 0;
}
if(direction == 1) {POVD2H = 0;POUT3L = 0;}
else if(direction == 2) {POUT2L = 0;POVD3H = 0;}
}
else if(!cap8)
{
if(direction == 1) {POUT2L = 0;POVD3H = 0;}
else if(direction == 2) {POVD2H = 0;POUT3L = 0;}
}
}

void __attribute__((__interrupt__)) _T1Interrupt(void)


{
if(direction == 1) {deg++;forward();}
else if(direction == 2) {deg++;reverse();}
POVD1L = 0;
POUT1H = 0;
POVD2L = 0;
POUT2H = 0;
POVD3L = 0;
POUT3H = 0;
IFS0bits.T1IF = 0;
}

void __attribute__((__interrupt__)) _T2Interrupt(void)


{
count1++;
IFS0bits.T2IF = 0;

www.pantechsolutions.net Page 22
BLDC Motor Control using DSPIC Microcontroller

void __attribute__((__interrupt__)) _T5Interrupt(void)


{
T5CONbits.TCKPS = 3;
PR5 = 195; // 10ms.
cap2_count++;
if(cap2_count >= 200) // 2Sec.
{
cap2_count = 0;
count = 0;
Speed = 0;
}
IFS1bits.T5IF = 0;
}

int main(void)
{
cmd_write();
ADPCFG = 0xFFFF;
ADPCFGbits.PCFG3 = 1;
TRISBbits.TRISB3 = 1;
ADPCFGbits.PCFG4 = 1;
TRISBbits.TRISB4 = 1;
ADPCFGbits.PCFG5 = 1;
TRISBbits.TRISB5 = 1;
tcap5 = 1;
cap5 = 0;
tcap7 = 1;
cap7 = 0;
tcap8 = 1;
cap8 = 0;
PTCON = 0x8002;
PTPER = 250;
PDC1 = 50;
PDC2 = 50;
PDC3 = 50;
OVDCON = 0x0000;
CNEN1 = 0x0020;
CNPU1 = 0x0020;
IFS0bits.CNIF = 0;

www.pantechsolutions.net Page 23
BLDC Motor Control using DSPIC Microcontroller

IEC0bits.CNIE = 1;
IC7CON = 0x0001;
IEC1bits.IC7IE = 1;
IC8CON = 0x0001;
IEC1bits.IC8IE = 1;
IEC0bits.T1IE = 1;
T1CON = 0x8000;
PR1 = 277;
IEC0bits.T2IE = 1;
T5CON = 0x8000;
T5CONbits.TCKPS = 3;
PR5 = 195; // 10ms.
IEC1bits.T5IE = 1;
data_write("PANTECH PROLABS ",0x80,16);
data_write(" INDIA PVT LTD ",0xc0,16);
delay(1000);
data_write(" BLDC MOTOR ",0x80,16);
data_write(" CONTROL ",0xc0,16);
delay(1000);
Init_Keys();
delay(500);
while(1)
{
if(flag == 0)
{
direction = 1;
flag = 1;
data_write("D.CYCLE = % ",0x80,16);
data_write("SPEED = RPM",0xc0,16);
LCDDisp_INT(duty,0x89,2);
LCDDisp_INT(Speed,0xc9,4);
delay(500);
PWMCON1 = 0x0077;
}
else if(flag == 1)
{
if(!key1) {if(Set_point < 3000) Set_point += 10;else Set_point =
556;}
duty_value = Set_point * (float)(0.1125); // 90%
On time.
duty = duty_value * (float)(0.2);

www.pantechsolutions.net Page 24
BLDC Motor Control using DSPIC Microcontroller

Speed = ((long)3000 * 23310 / count); //


Speed=(Max_Motor_Speed*Pulse_Time_in_ms*count_per_ms)/Measur
ed_count(T2)
if(count==0) Speed = 0;

PDC1 = duty_value; // 10 - 90%.


PDC2 = duty_value;
PDC3 = duty_value;

LCDDisp_INT(duty,0x89,2);
LCDDisp_INT(Speed,0xc9,4);
delay(100);
}
}
}

void forward()
{
deg = 0;
if(!cap5 && !cap7 && cap8) // 001.
{
POUT1L = 1;
POVD1H = 0;
POUT2L = 0;
POVD2H = 0;
POUT3L = 0;
POVD3H = 1;
}
else if(!cap5 && cap7 && !cap8) // 010.
{
POUT1L = 0;
POVD1H = 0;
POUT2L = 0;
POVD2H = 1;
POUT3L = 1;
POVD3H = 0;
}
else if(!cap5 && cap7 && cap8) // 011.
{
POUT1L = 1;

www.pantechsolutions.net Page 25
BLDC Motor Control using DSPIC Microcontroller

POVD1H = 0;
POUT2L = 0;
POVD2H = 1;
POUT3L = 0;
POVD3H = 0;
}
else if(cap5 && !cap7 && !cap8) // 100.
{
POUT1L = 0;
POVD1H = 1;
POUT2L = 1;
POVD2H = 0;
POUT3L = 0;
POVD3H = 0;
}
else if(cap5 && !cap7 && cap8) // 101.
{
POUT1L = 0;
POVD1H = 0;
POUT2L = 1;
POVD2H = 0;
POUT3L = 0;
POVD3H = 1;
}
else if(cap5 && cap7 && !cap8) // 110.
{
POUT1L = 0;
POVD1H = 1;
POUT2L = 0;
POVD2H = 0;
POUT3L = 1;
POVD3H = 0;
}
T1CON = 0x0000;
}

void reverse()
{
deg = 0;
if(!cap5 && !cap7 && cap8) // 001.
{

www.pantechsolutions.net Page 26
BLDC Motor Control using DSPIC Microcontroller

POUT1L = 0;
POVD1H = 1;
POUT2L = 0;
POVD2H = 0;
POUT3L = 1;
POVD3H = 0;
}
else if(!cap5 && cap7 && !cap8) // 010.
{
POUT1L = 0;
POVD1H = 0;
POUT2L = 1;
POVD2H = 0;
POUT3L = 0;
POVD3H = 1;
}
else if(!cap5 && cap7 && cap8) // 011.
{
POUT1L = 0;
POVD1H = 1;
POUT2L = 1;
POVD2H = 0;
POUT3L = 0;
POVD3H = 0;
}
else if(cap5 && !cap7 && !cap8) // 100.
{
POUT1L = 1;
POVD1H = 0;
POUT2L = 0;
POVD2H = 1;
POUT3L = 0;
POVD3H = 0;
}
else if(cap5 && !cap7 && cap8) // 101.
{
POUT1L = 0;
POVD1H = 0;
POUT2L = 0;
POVD2H = 1;
POUT3L = 1;

www.pantechsolutions.net Page 27
BLDC Motor Control using DSPIC Microcontroller

POVD3H = 0;
}
else if(cap5 && cap7 && !cap8) // 110.
{
POUT1L = 1;
POVD1H = 0;
POUT2L = 0;
POVD2H = 0;
POUT3L = 0;
POVD3H = 1;
}
T1CON = 0x0000;
}

www.pantechsolutions.net Page 28

You might also like