PC817 Integration in Motor Controller Design
PC817 Integration in Motor Controller Design
TECHNOLOGY
SCHOOL OF ELECTRICAL - ELECTRONICS
FACULTY OF AUTOMATON
--------------------------***--------------------------
REPORT
TOPIC: BRUSHLESS DIRECT CURRENT MOTOR
CONTROLLER.
Class: 136218
INSTRUCTOR: Chu Đức Việt
Group: Group 20
Phan Sỹ Nhật Tân 20192247
Vũ Quang Khải 20192218
Nguyễn Thành Hưng 20192211
Hà Nội, 2023
1
TABLE OF CONTENTS
……………………………………………………………………………………
Part 1. Description Design………………………………………………..……...4
1.1 Specifications…………………………………………………….…….4
1.2 Functionality……………………………………………………….…..4
Part 2. Block Diagram……….……………………………………………….…..5
Part 3. Hardware Design……….………………………….…………….………..5
3.1 Overview. ……….……………………………….……………….….....5
3.2 Detail Design…………………………………………………….……...6
1. Source………………………………………………………….……...6
a. Buck Converter 24V-12V,24V-5V……………………………..6
b. Buck Converter 5V-3.3V……………………………………….9
2. LCD, keypad & reset button…………………………………………..9
a. LCD,Keypad………………………………………….…………9
a. Reset button…………………………………………………….11
3. Digital input…………………………………………………………...11
4. Analog input…………………………………………………………..13
5. MCU STM32F101R6T6……………………………………………....14
5.1 Overview……………………………………………………….14
5.2 General pinouts and pin description……………………………15
6. Inverter Circuit………………………………………………………..16
7. Driver Circuit…………………………………………………………17
8. Current Feedback Circuit……………………………………………..19
9. Velocity Feedback…………………………………………………….21
10. Hall sensor……………………………………………………...……22
2
11. Communication RS485…………………………………….……….23
Part 4. Software Design…………………………………………………………..24
4.1 Unit Control……………………………………………………………...24
4.1.1 Idle……………………………………………………………...…..24
4.1.2 Normal Working………………………………………………...….25
4.1.3 Breaking………………………………………………………...…..25
4.2 User interface from keypad……………………………………….………26
4.3 Mode Selection……………………………………………………………27
4.4 Direction Selection…………………………………………………..……27
4.5 Normal Working …………………………………………………...……..28
4.5.1 Constant Value………………………………………………….…28
4.5.2 Acceleration & Deceleration………………………………………29
4.6 Break………………………………………………………………………30
Reference…………………………………………………………………….……30
3
PART 1. DESCRIPTION DESIGN
1.1 Specifications.
- Supply voltage: 24VDC.
- Rated power: 300W.
- Inputs:
+ Hall sensor signal
+ Encoder signal
+ Digital signal: RUN, BREAK, DIRECT,MODE, ACCE,DECE.
+ Analog signal: 0~10V
- Outputs:
+ Displaying LCD
+ Led
+ RS485 communication
1.2 Functionality
4
PART 2. BLOCK DIAGRAM
Source
24 VDC
Buck Buck Buck
12V 5V 3.3V
ncoder
Analog
input
M CU
Keypad, Button, CD B DC Motor
Current
Feedback
Digital
input
Communication
RS485
2. User 5V,3.3V LCD for displaying LCD 2004, Keypad 4x4, https://uk.beta-layout.com/download/rk/RK-
interface data, keypad for user’s Reset button, Led 10290_410.pdf
choices, button, led
https://components101.com/misc/4x4-
keypad-module-pinout-configuration-
features-datasheet
5
5.MCU 3.3V STM32F101R6T6 https://www.alldatasheet.com/datasheet-
pdf/pdf/504990/STMICROELECTRONICS/
STM32F101C6T6.html
6. Inverter 24V Convert DC to AC for 6 mosfets IRF3205 https://www.alldatasheet.com/datasheet-
supplying for BLDC pdf/pdf/68131/IRF/IRF3205.html
motor
7.Driver 5V Drive 6 mosfets IR2110 https://www.alldatasheet.com/datasheet-
circuit pdf/pdf/82795/IRF/IR2110S.html
https://www.alldatasheet.com/datasheet-
pdf/pdf/64642/HP/HCPL-7800.html
1. Source
-Description: buck converter to regulate high voltage to low level voltage; step-
down 24V to Vcc(5V) to supply for others components.
+ Input: 24VDC, output: 5VDC
6
+ Using LM2576:
. Switch mode step-down voltage regulator.
. Output Voltage for fixed voltage regulator: 3.3V, 5V, 12V or 15V.
. Output Current: 3A
. Maximum Input Voltage: 40V
- Choosing components
𝑅2
𝑉𝑂𝑢𝑡 = 𝑉𝑅𝐸𝐹 (1 + ) 𝑤ℎ𝑒𝑟𝑒 𝑉𝑅𝐸𝐹 = 1.23𝑉
𝑅1
𝑉𝑂𝑢𝑡
=> 𝑅2 = 𝑅1 ( − 1) ; 𝑆𝑒𝑙𝑒𝑐𝑡 𝑅1 = 3.6𝑘Ω
𝑉𝑅𝐸𝐹
5
=> 𝑅2 = ( − 1) ∗ 3600 = 11 𝑘Ω
1.23
Inductor L1
𝑉𝑜𝑢𝑡 1000
E x T= ( 𝑉𝑖𝑛 − 𝑉𝑜𝑢𝑡) x = 158,3
𝑉𝑖𝑛 𝐹𝑠
Imax =3A
=>Choose L1=150uH
Capacitor out
𝑉𝑖𝑛
𝐶𝑂𝑢𝑡 ≥ 13.3 = 0.06(µ𝐹)
𝑉𝑂𝑢𝑡 . 𝐿
𝐶ℎ𝑜𝑜𝑠𝑒 𝐶𝑂𝑢𝑡 = 638µ𝐹
Choose C1 =100uF , C2 =638uF
Diode:
𝐼𝐷 = 1.2𝐼𝑚𝑎𝑥 = 1.2 ∗ 3 = 3.6(𝐴)
𝑉𝑟𝑒𝑣𝑒𝑟𝑠𝑒 = 5 ∗ 3.6 = 18(𝑉)
Diode: 1N5824
7
-Description: buck converter to regulate high voltage to low level voltage; step-
down 24V to 12V to supply for mosfet driver.
+ Input: 24VDC, output: 12VDC
+ Using LM2576:
. Switch mode step-down voltage regulator.
. Output Voltage for fixed voltage regulator: 3.3V, 5V, 12V or 15V.
. Output Current: 3A
. Maximum Input Voltage: 40V
- Choosing components
𝑅2
𝑉𝑂𝑢𝑡 = 𝑉𝑅𝐸𝐹 (1 + ) 𝑤ℎ𝑒𝑟𝑒 𝑉𝑅𝐸𝐹 = 1.23𝑉
𝑅1
𝑉𝑂𝑢𝑡
=> 𝑅2 = 𝑅1 ( − 1) ; 𝑆𝑒𝑙𝑒𝑐𝑡 𝑅1 = 1.5𝑘Ω
𝑉𝑅𝐸𝐹
12
=> 𝑅2 = ( − 1) ∗ 1500 = 13 𝑘Ω
1.23
So choose component:
Resistance: 𝑅1 = 1.5𝑘Ω , 𝑅2 = 13𝑘Ω
Input capacitor : C1 =100uF
Output capacitor : C2 = 177uF
Inductor : L1 =150uH
Diode : 1N5824
8
b. Buck Converter 5V-3.3V
In order to supply for MCU, using LM1117 to converter 5V Vcc to 3.3V and that
is isolated with MCU by RSH2-3.33.3S/H3.
𝑅10
+ Vout= Vref (1+ ) + IADJ*R2, (IADJ small)
𝑅9
Where: Vref=1.25V;
=> Select R9=0.8kΩ (<1k);
Vout
=> R10= ( − 1)* R9
Vref
3.3
=> R10 = ( − 1)*0.8= 1.312kΩ
1.25
9
- In order to insert the desired velocity, rotating direction from user, using keypad
4x4.
10
b. Reset button
- The LED is connected to MCU that is active for RESET mode. When
pushing the RESET button, the Led will be turned on.
3. Digital input
11
- Description: digital input for start, stop and choosing direction & control
mode for motor.
+ Input voltage:
. Logic low: 0 - 0.4V
. Logic high: 2.4 – 3.3V
+ Output voltage:
. Logic high: 4.7 – 5V
. Logic low: 0 – 0.2V
- Using PC817 to isolate and protect MCU
+ When Vin= 0 - 0.4V -> Vin < 0.7 -> Diode is at cut off region -> transistor
is at cut off region -> Vout =0.
+ When Vin= 2.4 – 3.3V:
𝑉𝑖𝑛−0.7
I1 =
𝑅1
5
I2 =
𝑅2
12
4. Analog input
13
5. MCU STM32F101R6T6
5.1. Overview
- 12-bit synchronized ADC number of channels: 1-16 channel
- GPIOs: 51
- CPU frequency: 36 MHz
- Operating voltage: 2.0 to 3.6 V
- Operating temperature: ambient temp: -40 to 85Oc, junction tem: -40 to 105Oc
-Packages: LQFP64
14
5.2. General pinouts and pin description
2 PC15-OSC32_OUT OSC32_OUT 4
3 NRST RESET System 7
4 PCO ~ PC7 Led Data Bus 8 ~ 11,
24,25,37,38
5 PC10 Led Register 51
6 PC11 Led Enable 52
7 PB5 ~ PB12 Keyboard pins 57~59,
61,62,29,30,33
8 PA8 HIN1 (PWM) 41
9 PA9 HIN2 (PWM) 42
10 PA10 HIN3 (PWM) 43
11 PB13 LIN1 34
12 PB14 LIN2 35
13 PB15 LIN3 36
14 PC8 Encoder A 39
15 PC9 Encoder B 40
16 PA4 Current Feedback 20
17 PB0 Hall Sensor A 26
18 PB1 Hall Sensor B 27
19 PB2 Hall Sensor C 28
20 PA2 USART_TX 16
21 PA3 USART_RX 17
22 PA5,PA6,PA12,PA13,PA14,PA15 Start, Stop,Direction,
Mode, 21,22,45,46,49,50
Acceleration,Deceleration
23 PA11 Analog input 44
24
25
15
6. Inverter circuit
- Purpose: inverter transfer source 24 VDC into AC source to supply for motor
- The voltage source inverter contains six switches to drive 3-phase BLDC. The
designed order1 to 6 represents the sequence of switch operation in time. It
contains of 3 phase legs which operate in 120o apart. The three phase legs have a
phase shift at 120o among themselves that means phase leg (3-6) switches 120o
after phase leg (1-4) and phase leg (5-2) switches 120o after (3-6). Switch 1 and 4
get turned ON to give the voltage at one phase i.e, Va.Switch 3 and 6 turned ON to
give voltage Vb. Switch 5 and 2 turned ON to give voltage Vc.
16
- Vrms= 24 V => Vmax=24* √2 = 33.94 ; Vreq= 1.5*33.94= 50.91 V
- Power’s Motor: P = 300W, U= 24V -> Irms= 300/24= 12.5(A)
=> Imax= 12.5* √2 = 17.67 => Ireq= 1.5* 17.67= 26.5(A).
VDSS= 55 > Vreq= 50.91
The switches need to withstand the nomial values of the motor -> It could be
mosfet IRF3205
7. Driver circuit
- VCC: Low side fixed supply voltage from 10V to 20V -> using source 12VDC
17
- VDD: logic supply voltage from VSS+3 to VSS+20 (recommend VDD>=+4V) -
> using source VCC (5V)
- VSS: logic supply offset voltage – connected to ground
- COM: Low side return – connected to ground
- HIN: logic input for high side gate driver output (HO), in phase – connected to
MCU.
- LIN: logic input for low side gate driver output (LO), in phase – connected to
MCU.
- Electrolytic capacitor in paralled with ceramic capacitor (12V with C1, C2) is use
as boost trapping capacitor.
- Diode and resistance (R1, R2, D2,D3) are use for protection of from reversal of
supply from switches.
- C1= 22uF, C2=100nF; C3=22uF, C4= 100nF
- R1=R2=10; R3=R4= 1k.
18
8. Current feedback circuit
- Requirement:
+ Input current in range -12.5A to +12.5 A (I = P/V= 300W/24V= 12.5 A)
+ Desired voltage for MCU pin 0-3.3V
➔ In order to feedback current, using IC ACS712, its output will be isolated by
IC HCPL-7800; after that it is gained by IC OP-AMP MCP601 before
sending to MCU.
- IC ACS712
Using ACS712 to detect the DC current. Connecting DC from Ip+ to Ip-, then
Vout will respond voltage 2.5~5VDC, otherwise Vout will get 2.5-0VDC; and
the current will be 0~Max and 0~(-Max) respectively.
+ When supplying 5VDC for IC without current Ip -> Vout= 2.5VDC
+ Ip+ & Ip- connected to feedback current
+ Vcc supply connected to voltage source Vcc(5V)
19
+ Cbyp= 0.1uF reducing disturbances and Cf= 1nF for filter pin, getting
values as datasheet.
+ We have Idm= 12.5A but in order to save motor’s life, using current
80%Idm = 10A
VIOUT= 0.2*IP + 2.5
Thus VIOUT= 0.2*IP + 2.5= 0.2*10+2.5= 4.5V
+ Respect to current 10A is output voltage of 4.5. Using voltage divider ,
voltage before through the IC HCPL is:
𝑅5 100𝑘 1
VA1 = ∗ 𝑉𝑜𝑢𝑡 = ∗ 4.5 = ∗ 4.5
𝑅1+𝑅2+𝑅3+𝑅4+𝑅5 1𝑀+1𝑀+200𝑘+200𝑘+100𝑘 25
= 0.18V
- IC HCPL
20
Because the voltage will be gained 8 times through the IC HPCL thus we get
0.18*8= 1.44V
- The Differential Amplifier:
+ Choosing R7=R8= 10k
𝑅10
+ Vout= (Vout+ - Vout-)*
𝑅8
𝑅8 10𝑘
R10= Vout* = 3.3* = 22.9k(Ohm)
(𝑉𝑜𝑢𝑡+) −(𝑉𝑜𝑢𝑡−) 1.44
9. Velocity Feedback
21
In order to feedback the motor’s velocity, for example using encoder HN3806-AB
Rotary Encoder and using opto PC817 is to isolate encoder and MCU.
22
11. Communication RS485
- Choosing IC MAX485
+ Quantity: 1 port
+ Protocol: Modbus
+ Communication Standard: RS485
+ 3-3.5V supply voltage
+ Transmission speed up to 20 Mbps
+ Isolation to MCU: 6N137A
23
PART 4. SOFTWARE DESIGN
4.1 Unit Control
start
run v=1 & err v=0 run v=0 & err v=1
Reset system
4.1.1 Idle
- Definition: idle- after the system is powered on, the idle is initialized; or waiting
state for master/keypad’s signal command (parameters setting – setpoint,
direction,etc)
- Condition Moving State:
+ Enter:
. From initialization state: the user choosing start signal.
. From breaking state: the user fix all problems and pressing reset system
(rset_v=1) and without errors (err_v=0)
. From normal state: run_v=0 && err_v=0
+ Out:
. To normal state: run_v=1 && err_v=0
24
4.1.2 Normal Working
- Definition: the BLDC motor running at normal operating state. When the motor
is running normally, it can be at situation:
+ Constant Value: motor will work at desired value (speed/torque)
+ Acceleration: motor will increase from present value to desired value in
given time.
+ Deceleration: motor will decrease from present value to desired value in
given time.
- Condition Moving State:
+ Enter:
. From Idle state: getting run signal and without any errors (run_v=1 &&
err_v=0)
. From Break state: (run_v=1 && err_v=0)
+ Out:
. To Idle state: (run_v=0 && err_v=0)
. To Break state: if the system has any problems(such as over current, over
heat,etc) or getting the break signal from user =>the system will be suddenly stop
through break state (break_v=1 || err_v=1)
4.1.3 Breaking
- Definition: if the system happens any troubles the controller will stop the BLDC
motor and displaying warning to LCD or led.
- Condition Moving State:
+ Enter: if the system has any problems(such as over current, over heat,etc) or
getting the break signal from user =>the system will be suddenly stop through
break state (break_v=1 || err_v=1)
+ Out:
. To Normal working state: (run_v=1 && err_v=0)
. To Idle state: (rset_v=1 & err_v=0)
25
4.2 User interface from keypad
Keypad s Menu:
User can directly control B DC Value,Direction,Mode
through keypad 4x4 unless any other’s master
command.
* Menu
The options displayed on the LCD screen menu is in ordered:
Value,Direction,Mode. In order to move to left or right through key * or #
respectively, then user choose one of them, return to menu options by ‘back’
+ Set value: user will insert speed/torque value by keypad’s number
+ Set direction: * respected to speed mode and ; # respected to torque mode
+ Set mode: ‘A’ stand for clockwise direction, ‘B’ stand for counter clock wise
Note: ‘C’ stand for back & ‘D’ stand for enter
* Peripheral’s request
- If there’s any request from peripheral, stop keypad’s command then supplied to
serve master.
26
4.3 Mode Selection
mode v=1
mode v =0
direct v=1
direct v =0
27
- The motor can work in two direction (clock-wise and counterclockwise
direction):
+ Clockwise: it happens when controller get A from keypad or setting input
direction is low logic (respect to direct_v=0).
+ Counter-clockwise: it happens when controller get B from keypad or
setting input direction is high logic (respect to direct_v=1).
4.5. Normal working
4.5.1 Constant Value
- Get Setpoint: the user insert the desired value to controller through keypad or
analog input value to controller.
- Get Encoder value: the controller will receive the feedback value from encoder
- Calculation, Storage, Transmit: from the given data, the MCU will calculate the
suitable duty cycle for driver circuit.
28
4.5.2. Acceleration & Deceleration
- Get acce/dece signal: if the user insert acce signal (respect to acceleration
command) or dece signal (respect to deceleration command) (acce=1 || dece =1)
- Get Setpoint: the user insert the desired value to controller through keypad or
analog input value to controller. If (acce_v=1 & setpoint_v > current_v) ->
acceleration; if (dece_v=1 & setpoint_v < current_v) -> deceleration.
- Get Time Interval: insert the desired time interval (t_v)
- Calculation, Storage, Transmit: from the given data, the MCU will calculate the
suitable duty cycle for driver circuit.
29
4.6. Break
Break state operate as deceleration: the BLDC motor keep decreasing the velocity/
torque until it reaches zero value.
REFERENCE
https://dientutuonglai.com/tim-hieu-lm1117.html
Tahmid's blog: Using the high-low side driver IR2110 - explanation and plenty of example circuits
(tahmidmc.blogspot.com)
https://forum.arduino.cc/t/analog-signal-scaling-both-directions/563452/4
https://electropeak.com/learn/how-to-interface-a-rotary-encoder-with-arduino/
https://dientusangtaovn.com/pc817/
https://blog.mecsu.vn/bo-ghep-noi-optocoupler-toc-do-cao-6n137/
http://wiki.sunfounder.cc/index.php?title=LCD2004_Module
https://khuenguyencreator.com/lap-trinh-stm32-quet-ma-tran-phim-keypad-3x4/
https://blog.xuanthanh.net/2020/07/mach-bao-ve-nhiet-o-cho-thiet-bi.html
https://pdf1.alldatasheet.com/datasheet-pdf/view/530550/TGS/LM2576.html
https://www.alldatasheet.com/datasheet-pdf/pdf/22747/STMICROELECTRONICS/LM117.html
https://uk.beta-layout.com/download/rk/RK-10290_410.pdf
https://components101.com/misc/4x4-keypad-module-pinout-configuration-features-datasheet
https://www.alldatasheet.com/datasheet-pdf/pdf/43368/SHARP/PC817.html
30
https://www.alldatasheet.com/datasheetpdf/pdf/504990/STMICROELECTRONICS/STM32F101C6T6.ht
ml
https://www.alldatasheet.com/datasheet-pdf/pdf/68131/IRF/IRF3205.html
https://www.alldatasheet.com/datasheet-pdf/pdf/82795/IRF/IR2110S.html
https://www.alldatasheet.com/datasheet-pdf/pdf/168326/ALLEGRO/ACS712.html
https://www.alldatasheet.com/datasheet-pdf/pdf/64642/HP/HCPL-7800.html
https://www.alldatasheet.com/datasheet-pdf/pdf/30862/TOSHIBA/6N137.html
https://www.alldatasheet.com/datasheet-pdf/pdf/73463/MAXIM/MAX485.html
31