IC2 PWM3
Hall C PWM3
IC3 PWM5
Temp AN8 Driver
PWM2 PWM4
Run/Stop PWM2
PWM1
PWM0
PWM0
C B
FWD/REV Q0 Q2 Q4
Rx
IMOTOR N
Tx RSHUNT S
DC- S N
PC /FaultA IMAX
Amplifier
GUI Comparator
/FaultB
Hall A Hall C
Hall B
1
C
0
+
A 0
-
Phase
+
Current
B 0
-
+
C 0
-
Highside
PWM1 PWM1 PWM5 PWM5 PWM3 PWM3 PWM1 PWM1 PWM5 PWM5 PWM3 PWM3
Switch
Q1 Q1 Q5 Q5 Q3 Q3 Q1 Q1 Q5 Q5 Q3 Q3
Lowside PWM4 PWM2 PWM2 PWM0 PWM0 PWM4 PWM4 PWM2 PWM2 PWM0 PWM0 PWM4
Switch Q4 Q2 Q2 Q0 Q0 Q4 Q4 Q2 Q2 Q0 Q0 Q4
Sequence # 1 2 3 4 5 6
PWM0
PWM1
PWM2
PWM3
PWM4
PWM5
;Reverse sequence
MOVLW POSITION5 ;When Hall Sensor = 000,
MOVWF POSITION_TABLE_REV ;PWM3 & PWM0 should be active
MOVLW POSITION6 ;When Hall Sensor = 001,
MOVWF POSITION_TABLE_REV+1 ;PWM5 & PWM0 should be active
MOVLW DUMMY_POSITION ;When Hall Sensor = 002,
MOVWF POSITION_TABLE_REV+2 ;All PWM outputs should be inactive
MOVLW POSITION1 ;When Hall Sensor = 003,
MOVWF POSITION_TABLE_REV+3 ;PWM5 & PWM2 should be active
MOVLW POSITION4 ;When Hall Sensor = 004,
MOVWF POSITION_TABLE_REV+4 ;PWM3 & PWM4 should be active
MOVLW DUMMY_POSITION ;When Hall Sensor = 005,
MOVWF POSITION_TABLE_REV+5 ;All PWM outputs should be inactive
MOVLW POSITION3 ;When Hall Sensor = 006,
MOVWF POSITION_TABLE_REV+6 ;PWM1 & PWM4 should be active
MOVLW POSITION2 ;When Hall Sensor = 007,
MOVWF POSITION_TABLE_REV+7 ;PWM1 & PWM2 should be active
Yes Yes
Is Fault Activated? Overcurrent Fault? Blink LED1
No No
Yes
Overtemp
Blink LED3
Key Activity? A Fault?
No
Yes
No
Overvoltage Yes
Blink LED2
Fault?
No
No
FWD/REV Key? Run/Stop Key?
Yes Yes
No Motor Speed
Ref = 0?
Yes
Toggle Direction Bit,
Toggle LED4
RETURN
ISR
Forward Reverse
Direction?
Yes
Hall Sensor
Change?
ADC Ready?
Read Value from
Table + Hall (offset) and Load to
Yes OVDCOND Register
VMOTOR PTEPR x 4
PWM Duty Cycle = x x Speed Ref Turn On/Off LED1/2/3
(PDCx Registers) VDCBUS Max. Speed Ref
According to Hall Input
CALCULATE_SPEED_REF
MOVLW LOW(SPEED_REF_RATIO)
MULWF SPEED_REFH ;SPEED_REF_RATIO* speed reference read
MOVFF PRODH,TEMP ;from ADC (SPEED_REFH = 8 MSB’s pf speed reference)
MOVLW HIGH(SPEED_REF_RATIO)
MULWF SPEED_REFH ;For simplifying calculation only 8 bits are taken
MOVF PRODL,W
ADDWF TEMP,F
CLRF WREG
ADDWFC PRODH, W ;Lower 8 bits are discarded = divide result by 0xFF
MOVWF SPEED_REF_RPMH ;Speed reference loaded in
MOVFF TEMP,SPEED_REF_RPML ;SPEED_REF_RPM<H:L>
RETURN
FOSC/4
Speed in RPM = x 60
(S Actual) Timer5 x Timer5 Prescale x Rotor Pole Pairs x 6
PID_Error = K P x E + K I x E + K D x ∆E
Return
The difference between the speed reference and actual amplified error is used to readjust the PWM duty cycles
speed values give the error in speed. The error may be originally calculated as per Equation 2. Figure 7 shows
positive or negative, indicating the speed is more or a block diagram of a control loop for a closed-loop
less than the set reference. This error is passed application. Appendix A: “PID Controller” gives
through a PID algorithm to amplify the error. The some insight on step response and tuning PID gains.
Speed PID
Speed Error
Reference
+ PWM
_
6 3-Phase
Inverter BLDC
Bridge Motor
Speed Feedback
Commutation
Sequence
Hall Sensors
QE
AD0
PWM5 PWM5
IMOTOR AD1
QEA QEA PWM4 PWM4
QEB 3-Phase
PIC18FXX31
QEB Hall A
PWM3 PWM3 Inverter
Index INDX
Hall A INT0
PWM2
Driver
PWM2
Bridge
M Hall B
Hall B INT1 Hall C
Hall C INT2 PWM1 PWM1
Run/Stop
PWM0 PWM0
QE
FWD/REV
/Fault IMOTOR RSHUNT QEA Index
QEB
IMAX Amplifier DC-
Comparator
CONCLUSION
The PIC18F2331/2431/4331/4431 family of micro-
controllers have peripherals that are well suited for
motor control applications. Using these peripherals,
speed control of a BLDC motor can be achieved with
less overhead on the firmware. Closed-loop speed
control is easy to implement as the microcontroller has
a built-in motion feedback module.
Response
Step Input
Speed
TRISE TSETTLE
Time
DS00899A-page 18
AC INPUT
APPENDIX B:
1 ohm 3W 10 µH
11DQ10
SHORTING LINK
2 1
10 µH
11DQ10
216010
GBPC2506C 47 µF 25V
100 µF 25V
470 µF 250v
10 µH
11DQ10
DC- C11 C10
27 ohm R8
100 µF 25V 47 µF 25V 4.7K R6
CIRCUIT SCHEMATICS
DC-
R13 MOC8101
CCP/F8 2.4K
C7 5
56 pF VCC
4 D2
U1 D TL431
3
GND
2 E7
IRIS4009-HORZ
DC- S C13
1 47 pF C12 10 ohm
220 pF
DC-
DC- DC-
R40 470
10K R30
1 0.1 µF 0.1 µF
2 10K U3 300
1
3 1 40
INT0 MCLR/VPP RB7/PGD 2 0.1 µF
4 2 39 1 8
INT1 RA0/AN0 RB6/PGC 3 AN1 VCC
SFH6326
10K
PIC18F4431 PWM0
10K
300
300
0.1 µF
1 8
AN1 VCC
2 7
CA1 V01
3 CA2 V02 6
0.1 µF
4 AN2 GND 5
33 pF PICDEMTM MC
0.1 µF 33 pF
33 pF
DS00899A-page 19
AN899
FIGURE B-3:
AN899
DS00899A-page 20
C28
33 pF
U9 U10
U6
IN6
IN5
IN4
IN6
IN5
IN4
OUT OUT
IN6
IN5
IN4
OUT Load R125 Load R126
0V LTS25-NP 0V LTS25-NP 0.01R. 1/2W
0V LTS25-NP Load R124 0.01R. 1/2W
0.01R. 1/2W +5V instead of U9 instead of
+5V
IN3
IN2
IN1
U10
IN3
IN2
IN1
+5V instead of U6
IN3
IN2
IN1
4.7 µF 25V
0.1 µF
PIC18F4431 DEMO BOARD SHEET 3 OF 7
OPTIONAL
PICDEMTM MC
100K
0.1 µF
4
2
-INA
0.1 µF 100K 1
R109 0.1 µF
100K 0.1 µF
1 8
PIC18F4431 DEMO BOARD SHEET 4 OF 7
TLP2630/
560K 560K 560K SFH6326
R113
1K
0.1 µF
13 -IND
10K 14
12 +IND 300
0.1 µF 30K
DS00899A-page 21
AN899
FIGURE B-5:
AN899
DS00899A-page 22
U15 10 µF 16v
VB3
1
VS3
2
NC
3 10 µF 16v 0.1 µF
VB2
4
VS2
5
8
NC 2 U11:A
6 10 µF 16v
VB1 R117 R118
7 1 6 U20
R111 U11:B 360
VS1 3 R119
8 51K 1% 7 1 -LED N/C 8
4
NC 5 2 7
9 1k MCP6002-DIP8 +LED N/C 51K 1%
V+ 3 6 6
10 R116 +VCCT +VCC2 U4:B
NC 4 5 7
11 FUSE 6.3X32 100 pF I1 I2
DC- 33 pF 4.7 nF R112 91K MCP6002-DIP8 5
12 R110 10K
DC-
13 LOC111-8DIP
DC- 0.05R/3W MCP6002-DIP8 R120
14
DC- 470
H1
15
H2 16
H3 17
L1 18
L2 19
PIC18F4431 DEMO BOARD SHEET 5 OF 7
L3 20
R93
ITRIP 21 R94
VCC 22 300 1K
U16
VSS 23 R115
R108 1 +LED
4.3K COL 4
2 -LED EMT 3 1K
IRAMS10UP60A
SFH618
PICDEMTM MC
J9
1
J7 2
J8
ICD 1 1
3
2 2
VREF 4
3 3
5
4 4 R95
6
5 5 4.7K
7
6
4.7K
D17
R102
PIC18F4431 DEMO BOARD SHEET 6 OF 7
470
R106 D18
50 R103
DS00899A-page 23
AN899
FIGURE B-7:
AN899
DS00899A-page 24
C45
1 µF
C44
16
1 µF
VCC
2 V+
11 T1IN 14
18 T2IN 7
MAX232-DIP16
12 A1OUT A1IN 13
9 A1OUT A2IN 8
1 C1+ C2+ 4
C46 C43
1 µF 1 µF R107
3 C1- C2- 5
10 ohm
6 V-
GND
15
PIC18F4431 DEMO BOARD SHEET 7 OF 7
U19
1 MCLR/RE3 RB7 28
2 RA0/AN0 RB6 27
JP9 3 26
1 RA1/AN1 PWM4
2 4 RA2/VREF- PWM5 25
3 5 RA3/VREF+ PWM3 24
6 RA4/AN4 PWM2 23
7 VDD PWM1 22
8 VSS PWM0 21
9 OSCI/RA7 VDD 20 HC - 49 US
19 C48 C49
10 OSC2/RA6 VSS 33 pF 33 pF
11 RC0 RC7 18
12 RC1/CCP2 RC6 17
13 RC2/CCP1 RC5/INT2 16 PICDEMTM MC
14 RC3 RC4/INT1 15
PIC18F2431
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip's Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.