953MCL Motor Control Hands-On Using PIC18FXX31 Microcontrollers
-
Upload
duong-phan -
Category
Documents
-
view
70 -
download
1
description
Transcript of 953MCL Motor Control Hands-On Using PIC18FXX31 Microcontrollers
-
2005 Microchip Technology Incorporated. All Rights Reserved. Slide 1
953 MCLMotor Control hands-on
using PIC18FXX31 Microcontrollers
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 2
Agenda & TimelineO PIC18FXX31 family overview O Training board overviewO High speed ADC features O Initialize ADC : Lab1& discuss answerO Motion Feedback Module(MFM) featuresO Initialize MFM : Lab2 & discuss answerO Power Control PWM(PCPWM) featuresO Initialize PCPWM : Lab3 & discuss answerO Overview of BLDC motor control using PIC18FXX31 O BLDC speed control: Lab4 & discuss answerO Motor control resources from Microchip O Q & A
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 3
Motor Control PIC MCUs
O Mid-Range PIC16 seriesO PIC16F684/716 14/18 pin
O ECCP, ADCs and comparatorsO PIC16F7X7 series 28/40 pin
O 3 CCPs, ADCs and Comparators
O High end PIC18 series- This classO PIC18FXX31 series 28/40 pin
O Power Control PWM (PCPWM), High-speed ADCs and Motion Feedback Module (MFM)
O dsPIC digital signal controller familyO dsPIC2010 to dsPIC6010 28 pin to 80 pin
O Power Control PWM (PCPWM), High-speed ADCs and Motion Feedback Module (MFM)
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 4
You should have.1) MPLAB IDE V7.10 or higher installed2) Complete MPLAB ICD2 setup 3) BLDC motor control board(05-60001)4) 24V power supply for the above board5) Hurst(NTDynamo) BLDC motor with
O Power cable (4 wires with white square connector) andO Hall sensor cable (5 wires with 8 pin inline connector)
6) Circuit schematic of BLDC motor control board7) Datasheet of PIC18F2331/2431/4331/4431
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 5
Features PIC18F2331 PIC18F2431 PIC18F4331 PIC18F4431Packages 28SP,28SO 28SP,28SO 40P,44L,44PT 40P,44ML,
44L,44PTProgram
memory bytes8192 16384 8192 16384
RAM bytes 768 768 768 768EEPROM bytes 256 256 256 256
I/O ports 22 22 34 34CCP module 2 2 2 2
Timers 3-16Bit,1-8bit,1-WDT
3-16Bit,1-8bit,1-WDT
3-16Bit,1-8bit,1-WDT
3-16Bit,1-8bit,1-WDT
Serial I/O EUSART/I2C/SPI EUSART/I2C/SPI EUSART/I2C/SPI EUSART/I2C/SPI
Failsafe Clockmonitor
Yes Yes Yes Yes
Power managemodes
RUN, IDLE andSLEEP
RUN, IDLE andSLEEP
RUN, IDLE andSLEEP
RUN, IDLE andSLEEP
ICSP,PBOR,LVD
Yes Yes Yes Yes
Max. speed 40 MHz 40 MHz 40 MHz 40 MHz
PIC18FXX31 Spec. Overview
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 6
Features PIC18F2331 PIC18F2431 PIC18F4331 PIC18F4431Power
Control PWMmodule
3 channels w/complementary
outputs
3 channels w/complementary
outputs
4 channels w/complementary
outputs
4 channels w/complementary
outputsTimer5module
yes yes yes yes
Input Capture 3 3 3 3Quadrature
EncoderInterface
QEA, QEB, INDX QEA, QEB, INDX QEA, QEB, INDX QEA, QEB, INDX
High-SpeedADC
channels5 10bit 5 10bit 9 10bit 9 10bit
External FaultInputs
2 2 2 2
PIC18FXX31 FeaturesFor Motor Control
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 7
PIC18Fxx31 overview
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 8
Pinout (40-pin devices) /MCLR/Vpp/RE3 1 40
2
3
4
5
6
7
9
12
1516
1718
14
39
38
37
36
35
34
3332
3029
26
31
28
RA0/AN0
RA1/AN1
RA2/AN2/Vref-/CAP1/INDX
RA3/AN3/Vref+/CAP2/QEA
RA4/AN4/CAP3/QEB
RA5/AN5/LVDIN
AVss
OSC2/CLKO/RA6RC0/T1OSO/T1CKI
RC1/CCP2/T1OSI/~FLTA
RC2/CCP1/~FLTBRC3/T0CKI/GPCKI/INT0
RB2/PWM2
RB1/PWM1
RB0/PWM0VddVssRD7/PWM7RD6/PWM6RD5/PWM4RD4/~FLTA
RB3/PWM3
RB4/KBIO/PWM5
RB5/KBI1/PWM4/PGM
RB6/KBI2/PGC
RB7/KBI3/PGD
8RE0/AN6
10
13
AVdd
OSC1/CLKI/RA7
1920
RD0/T0CKI/T5CKIRD1/SDO
11
RE1/AN7RE2/AN8
27RC7/RX/DT/SDO
25 RC6/TX/CK/~SS
24 RC5/INT2/SCK/SCL
23 RC4/INT1/SDI/SDA
22 RD3/SCK/SCL
21 RD2/SDI/SDA
P
I
C
1
8
F
4
4
3
1
98
7
6
5
4
3
2
1
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 9
Pinout (28-pin devices)
/MCLR/Vpp/RE3 28
3
4
5
6
7
9
11
12
13
14
10
27
26
25
24
23
22
21
20
18
17
15
19
16
RA0/AN0
RA1/AN1
RA2/AN2/Vref-/CAP1/INDX
RA3/AN3/Vref+/CAP2/QEA
RA4/AN4/CAP3/ QEB
AVdd
AVss
OSC1/CLKI/RA7
OSC2/CLKO/RA6
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2/~FLTA
RC2/CCP1/~FLTB
RC3/T0CKI/T5CKI/INT0
RB2/PWM2
RB1/PWM1
RB0/PWM0
VDD
Vss
RC7/RX/DT
RC6/TX/CK
RC5/INT2/SDO
RC4/INT1/SDI/SDA
RB3/PWM3
RB4/PWM5
RB5/PGM/PWM4
RB6/PGC
RB7/PGD
P
I
C
1
8
F
2
4
3
1
9
1
3
4
5
6
7
2
8
-
2005 Microchip Technology Incorporated. All Rights Reserved. Slide 10
Training Board Overview
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 11
Training Board
ICD 2 Connector Current Limit Pot
S1 Reset
PowerSupply
connector
S3 RUN/STOP
S2 FWD/REV
Pot REF
PIC18F2431
Serial Connector Motor
Connectors
Shunt Resistor
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 12
Training Board
PowerMOSFETs
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 13
Jumpers and LEDs
D7Power LED
PIC18F2431
JumpersJ7, J8, J11, J12, J13, J14
LEDsD1D2D3
Jumper J15
Jumper J2
LEDsPWM0
toPWM5
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 14
Default Jumper settings
O J2(2 pin) - shorted. O J15(3 pin) - shorted between pin 2 & 3
(short link towards the crystal oscillator)
O J7, J11 and J13 - shorted between pin 1 & 2(short link towards the ICD2 connector)
O J8, J12, J14, J16 and J17 keep openO Keep Potentiometer REF(R14) completely
turned counter clockwiseO Keep Potentiometer R60 completely turned
clockwise
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 15
Hardware Block Diagram
P
I
C
1
8
F
2
4
3
1 BLDC
Motor3 phase Inverter bridge
R-LowR-High
Y-Low
Y-HighB-HighB-LowREF
Motor current
IREFERENCE
Hallsensors
Hall sensors
Motor current
Power supply
+24V
Shunt
IM
+
-IM
+15V+5VGnd
J9
M1
M2
M3
HAHBHC
R60
AC input
/MCLR 28
11
12
13
14
10
27
26
25
24
23
22
21
20
18
17
15
19
16
AN0
AN1AN2/IC1
AN3/IC2
AN4/IC3AVdd
AVss
OSC1
OSC2
RC0
/FLTA/CCP2
/FLTB/CCP1
RC3/INT0
PWM2
PWM1
PWM0
Vdd
Vss
RC7/RX
RC6/TX
RC5/INT2
RC4/INT1
PWM3
PWM5
RB6/PGC
RB7/PGD
PWM4
9
87
6
54
32
1
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 16
Program flow - Main routines
StartStart
Initialize ADC (LAB1-a)
Initialize MFM (LAB2)
Initialize PCPWM (LAB3)
Switch S2 and S3 check
Main_loop
Commutation sequence table (LAB4-a)
Exercises you need to do
Calculate PWM duty cycle
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 17
Program flow - ISR routines
IC1/IC2/IC3 ISR?
Updatecommutation
sequence
Read PORTA states and display on
D1/2/3
ADC ISR?
UpdateSpeed Reference
and motor current
Read FIFO
RETFIE
PWMISR?
Filter the FaultAand indicate Motor
Over current Read FaultA status
ISR_HIGH (LAB4-b)
(LAB1-b)
Exercises you need to do
-
2005 Microchip Technology Incorporated. All Rights Reserved. Slide 18
High-speed ADC module
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 19
High-Speed ADCO Up to 9 channelsO Simultaneous two-channel sampling O Two S/H circuits and 1 conversion circuitO Sequential sampling of 1, 2, or 4 channelsO Auto-conversion capabilityO 4-word FIFO with selectable interrupt
frequencyO Selectable external triggersO Programmable acquisition time
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 20
4x10-bit FIFO
MUX
1010
1010
8 bi
t dat
a bu
s
Analog Mux
Analog Mux
S/H1
ADC
1234
ADRESH,ADRESL
Conversion logic
Input mux controlS/H-2 Ch. Sel
S/H-1 Ch. Sel
S/H-1 Ch. Sel
VrefMux
AVddAVssVref+Vref-
Vref select
AVref+AVref-
AN0AN4AN8AN2AN6
AN1AN5AN3AN7
AAACC
BBDD
Not available on 28 pin devices
S/H2
ADC Functional Block Diagram
ADC
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 21
ADC Modes of OperationADC Mode Description
Multi-channel sequential Mode 1 (SEQM1)
A & B are sampled and converted sequentially
Multi-channel sequential Mode 2 (SEQM2)
A,B,C& D are sampled and converted sequentially
Multi-channel simultaneous Mode 1 ( STNM1)
A & B sampled simultaneously and converted sequentially
Multi-channel simultaneous Mode 2 (STNM2)
A & B sampled simultaneously and converted sequentially. Then C & D
sampled simultaneously and converted sequentially.
Single Channel mode 1 (SCM1) A is sampled and converted Single Channel mode 2 (SCM2) B is sampled and converted Single Channel mode 3 (SCM3) C is sampled and converted Single Channel mode 4 (SCM4) D is sampled and converted
Auto conversion Single shot mode The sequence is executed once Auto conversion continuous loop mode The sequence is executed continuously
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 22
ADC Control Registers
SFR Bit7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 ADCON0 --- --- Auto
CONV Auto SCH
Auto Conv mode ACMOD
GO/ Done
ADON
ADCON1 Vref source VCFG
--- FIFOEN
FIFO empty
FIFO Ovrfl
FIFO read pointer
ADCON2 AD format
A/D acquisition time selection ACQT
A/D clock select ADCS
ADCON3 A/D int select --- A/D trigger source select SSRC ADCHS Sample D
SDSEL Sample B
SBSEL Sample C
SCSEL Sample A
SASEL ANSEL0 Pin input select: Analog/digital ANS ANSEL1 Pin input select: Analog/digital ANS
Trigger Sources ADCON3RBO/INT pin xxxx1Timer5 Overflow xxx1xInput Capture 1 xx1xxCCP2 Compare x1xxxPCPWM 1xxxx
Interrupt Options ADCON3Each write to FIFO 002nd & 4th write to FIFO 01Every 4th write to FIFO 10
(These options ignored in single shot mode.)
-
2005 Microchip Technology Incorporated. All Rights Reserved. Slide 23
Lab 1a and 1b
Initializing AD Converter Module
Duration : 20 minutes
Note : Do not connect any of the motor cablesto the board at this time.
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 24
Lab 1a & 1bO Goal : To get familiarized with new high speed A/D moduleO Task : Initialize ADC to read potentiometer(REF) and motor
currentO Steps:
O Create a project in MPLAB IDE V6.42 or higherO Select PIC18F2431 as the target deviceO Add EX1.asm and linker script(18f2431i.lkr) file to the projectO Select ICD2 as debuggerO Open EX1.asm,
O Go to START LAB-1a HERE and initialize ADC O Go to START LAB-1b HERE and read ADC result O Follow the instructions given in the code
Jumper J15 should be between 2-3 (towards crystal)
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 25
Lab 1a & 1b - HintsO REF pot connected to AN1O Motor current feedback connected to AN0O Enable appropriate multi channel conversion mode O Left justified resultO Enable FIFO O Interrupt when 2nd and 4th word written to FIFO O Enable appropriate analog channels for conversion
Note : Do not connect any of the motor cablesto the board at this time.
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 26
Lab 1a & 1b - ResultO Build, program the part and run the programO Rotate clockwise the pot. REF slowlyO LEDs D1, D2 and D3 should turn on @ approx.
30%, 60% and 90% of the pot level respectively O Press either switch S2 or S3O LEDs D1, D2 and D3 should turn ON and OFF
sequentially.
-
2005 Microchip Technology Incorporated. All Rights Reserved. Slide 27
Motion Feedback Module (MFM)
Quadrature Encoder Interface (QEI) Input Captures (IC)
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 28
Quadrature Encoder Interface
O Two phase inputs (QEA, QEB) and one index input interface
O Two level position tracking: x2 and x4 O Direction detectionO Velocity measurement mode :
O Programmable postscaler for high-speed velocity measurement
O Programmable digital filters on each input pin
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 29
ClockDivider
COUNTER
INDEX/IC1
Tcy
Digital FilterLogic
Digital FilterLogic
Digital FilterLogic
QEA/IC2
QEB/IC316-Bit Up/Down
Counter
Direction
QuadratureDecoder
Logic
Clock
ResetComparator
MaxCounter
8 bi
t dat
a bu
s
PostscalerVelocity Velocity capture
Position interrupt
Velocity interrupt
QEI Block Diagram
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 30
QEI Position Tracking Mode
QEA
QEB
Index
Positioncounter
Max counter = 1541
FWD/REV
Direction change
PositionMax count
PositionMax count
PositionIndex
Interrupts
+ + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - -
Forward Reverse
152215231524152515261527152815291530153115321533153415351536153715381539154015410000000100020003
000200010000154115401539153815371536153515341533153215311530152915281527152615251524
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 31
Noise filters
Clock
Filter Input(Pin)
Filter output
3 cycles Noise
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 32
QEI - Velocity Measurement
QEA
QEB
+1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +1+1 +1 +1 +1 +1 +1 +1 +1 +1 +1
Old value
1234
1234
1246
1246
Vel_out
Vel_capture
Timer5
Vel_REG
Interrupt
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 33
Input Capture Block Diagram
ClockDivider
Tcy
DigitalFilterLogic
IC3
Timer 5 Logic
DigitalFilterLogic
DigitalFilterLogic
Prescale &mode select
Prescale &mode select
Prescale &mode select
Timer 5
CAPxBUF
Timer5Reset control
IC2
IC1
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 34
Input Capture Modes
Edge capture mode - Every rising edge
1 2 3 4
Edge capture mode - Every falling edge
Edge capture mode - Every 4th rising edge
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 35
Input Capture Modes
Timer5
Special event trigger modes:a) Trigger on every falling edge of CAP1 input onlyb) Trigger on every rising edge of CAP1 input only
Edge capture mode - Every 16th rising edge
Period measurement mode Rising edge to rising edge
1 2 15 16
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 36
Input Capture Modes
Pulse
Timer5
Pulse
Interrupt
Interrupt
Pulse width measurement mode Falling edge to rising edge
Pulse width measurement mode Rising edge to falling edge
Timer5
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 37
Capture 3
Time Base
CAP1BUF
CAP2BUF
CAP3BUF
0000h
Time Base Reset
1 1 1 0
1
1 1
Capture 2Capture 1
S
t
a
t
e
1
S
t
a
t
e
2
S
t
a
t
e
3
S
t
a
t
e
4
S
t
a
t
e
5
S
t
a
t
e
6
1
0 0 1 1
0 0 0
Capture for Hall SensorsInput capture on state change mode :Time base is capture on every CAPx input state change
-
2005 Microchip Technology Incorporated. All Rights Reserved. Slide 38
Lab 2
Initialization of MFM module
Duration : 20 minutes
DO NOT connect motor power cable to the board at this time
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 39
Lab 2O Goal : To get familiarized with Motion Feedback
Module(MFM)O Task : Initialize MFM to interface with 3 Hall
sensorsO Steps:
O Create a project in MPLAB IDE V6.42 or higherO Select PIC18F2431 as the target deviceO Add EX2.asm and linker script(18f2431i.lkr) file to the
projectO Select ICD 2 as debuggerO Open EX2.asm, go to START LAB-2 HERE and
initialize MFM
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 40
Lab 2 - HintsO IC1, IC2 and IC3 pins are used for Hall sensor interfaceO Enable capture on every CAPx state change modeO Disable QEI modesO Enable interrupt on every IC transitionO Make Hall sensor connections on connector J9 as follows:
O RED : Connect to +5VO BLACK : Connect to O WHITE : Connect to HA (IC1)O BROWN : Connect to HB (IC2)O GREEN : Connect to HC (IC3)
DO NOT connect motor power cable to the board at this time
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 41
Lab 2 - ResultO Build, program the part and run the programO Rotate clockwise the pot. REF slowly and
observe LEDs D1, D2 and D3 should turn on @ approx. 30%, 60% and 90% of the pot level respectively
O Press either switch S2 or S3O Spin the rotor with hand, LEDs D1/D2/D3
should turn on and off every 12 degrees of rotor rotation
O Check the correct sequence:O Rotate the rotor and keep only D1 ONO Turn the rotor by a step (12 degrees) in
clockwise when viewed from driving end and follow the table
ONOFFONStep6
ONOFFOFFStep5
ONONOFFStep4
OFFONOFFStep3
OFFONONStep2
OFFOFFONStep1
D3D2D1
-
2005 Microchip Technology Incorporated. All Rights Reserved. Slide 42
Power Control PWM Module(PCPWM)
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 43
Power Control PWM Module
O Designed for power and motor controlO Single phase and Three-phase AC-Induction
MotorO Multiple DC Brush MotorsO Brushless DC MotorO UPSO Switched Reluctance Motor
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 44
PCPWM FeaturesO Up to 4 channels with complimentary outputO Edge or center-aligned operationO Flexible dead-band generator
O 50 nS to 25.6 uS @ 40 MHzO Hardware fault protection inputsO Simultaneous update of duty cycle and periodO Flexible Special Event trigger outputO Output override features
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 45
PDC compareoutputPWM1/3/5/7PWM0/2/4/6
DT DT
Special Event Trigger
PWM Enable and Mode SFRs
PWM Override
Dead Time Control
PWM5
Fault Pin Control SFR
PWMCON 1
PWM Timer (PTMR)
PWM Generator #1
Dead time Generator
andOverride
logic
PWM4
PWM3PWM2
PWM1PWM0
FLTA
PWM Generator #2
8
b
i
t
d
a
t
a
b
u
s
DTCON
FLTCON
PWMCON 0
OVDCON
PDC2 Buffer
PDC2
ComparatorComparator
Period register (PTPER)
Comparator
SEVTCMP
PTCON PWM Timermodes
PWM Generator #0
Outputdriverblock
PCPWM Functional Block Diagram
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 46
Edge-aligned PWM
PTMR=PTPER
PTMR=0
PWM1
PWM3
PWM5
PWM7
PWM period
PDC0
PDC1
PDC2
PDC3
Interrupt
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 47
Center-aligned PWM
PTMR=PTPER
PTMR=0
PWM1
PWM3
PWM5
PWM7
PWM period
PDC0
PDC1
PDC2
PDC3
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 48
PWM ResolutionPWM period
PTMR n 000 001 n-1 nQ1Q2 Q3 Q4 Q1Q2 Q3 Q4
PWM1
PWM3
PWM5
PWM7
PTPER = 0xn
PDC0 = 0xn(12 bits)+00
PDC1 = 0xn(12 bits)+01
PDC2 = 0xn(12 bits)+10
PDC3 = 0xn(12 bits)+11
Note: When PDCx > PTPER, output will always be active.
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 49
PWM Frequency vs. Resolution
Edge aligned mode:
Center aligned mode: PWMfrequency = 2 x PTPER x (PTMRprescalevalue)Fosc/4
PWMfrequency =(PTPER+1) x (PTMRprescalevalue)
Fosc/4
Resolution = log( )
FoscFpwm
log(2)
Edge aligned mode: Frequency v/s resolutionFosc MIPS PTPER value PWM
resolutionPWM
frequency40 MHz 10 0xFFF 14 bits 2.4 KHz40 MHz 10 0x7FF 13 bits 4.9 KHz40 MHz 10 0x3FF 12 bits 9.8 KHz40 MHz 10 0x1FF 11 bits 19.5 KHz40 MHz 10 0x0FF 10 bits 39.0 KHz40 MHz 10 0x07F 9 bits 78.1 KHz40 MHz 10 0x03F 8 bits 156.2 KHz40 MHz 10 0x01F 7 bits 312.5 KHz40 MHz 10 0x00F 6 bits 625 KHz25 MHz 6.25 0x0FF 10 bits 24.4 KHz10 MHz 2.5 0x0FF 10 bits 9.8 KHz
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 50
Configuration BitsO HPOL : High-side power switch polarity
O Selects PWM1,3,5,7 are active high/lowO LPOL : Low side power switch polarity
O Selects PWM0,2,4,8 are active high/low
O PWMPIN : PWM output pins stateO Selects PWM module to be enabled/disabled upon
resetO PWM4MX : PWM4 mux bit
O PWM4 output multiplexed with RB5 or RD5O FLTAMX : FLTA pin mux
O FLTA pin muxed with RC1 or RD4
-
2005 Microchip Technology Incorporated. All Rights Reserved. Slide 51
Lab 3
Initialization of PCPWM module
Duration : 20 minutes
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 52
Lab 3O Goal :
To get familiarized with Power Control PWM (PCPWM)
O Task : Initialize PCPWM to control a BLDC motorO Steps:
O Create a project in MPLAB IDE V6.42 or higherO Select PIC18F2431 as the target deviceO Add EX3.asm and linker script(18f2431i.lkr) file to the
projectO Select ICD2 as debuggerO Open EX3.asm,
O Go to START LAB-3 HERE and initialize PCPWM
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 53
Important : Enable Fault condition on break point
Lab 3 - HintsO Use PWM0 to PWM5 for the controlO PWM outputs in edge-aligned or center aligned modeO Set PWM outputs in independent modeO Set PWM frequency to 16 kHz (Fosc = 5 MHz X 4 PLL)O Set FaultA in cycle-by-cycle mode O Enable Fault condition on breakpointO Set outputs on PWM pins controlled by the PWM duty cycle
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 54
Lab 3 - ResultO Build, program the part and run O Rotate clockwise the pot. REF slowly and observe LEDs
D1, D2 and D3 should turn on @ approx. 30%, 60% and 90% of the pot level respectively (Lab 1)
O Press either switch S2 or S3O Spin the rotor with hand, LEDs D1/D2/D3 should turn on
and off every 12 degrees of rotor rotation (Lab 2)O Turn the Pot REF clockwise, ONLY ONE LED out of
PWM0-PWM5 should turn ONO When the rotor is rotated, on/off of PWM0-PWM5 LEDs
should scroll. O When the pot REF is rotated, the intensity of PWM0-PWM5
LEDs should vary
-
2005 Microchip Technology Incorporated. All Rights Reserved. Slide 55
BLDC Motor Control
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 56
Drive SequenceVDC+
VDC-
(3)(6)(5)(2)
(1)(4)
H1
L1
H2
L2
H3
L3
P
I
C
1
8
F
x
x
3
1
PWM1PWM3PWM5
PWM0PWM2
PWM4
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 57
6 step-Switching SequenceStep (x) (1) (2) (3) (4) (5) (6) (1) (2) (3) (4)
Phase A
Phase B
Phase C
H2L3
H1L3
H1L2
H3L2
H3L1
H2L1
Hall sensorHall A
Hall B
Hall C
High switchLow switch
101 001 011 010 110 100 101 001 011 010 110
Hall C
Hall B
Hall A
Phase A
Phase B
Phase C
0 0 1 DC+ NC DC- 0 1 1 DC+ DC- NC 0 1 0 NC DC- DC+ 1 1 0 DC- NC DC+ 1 0 0 DC- DC+ NC 1 0 1 NC DC+ DC-
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 58
OVDCOND vs. PWM(1) (2) (3) (4) (5) (6)Step
001 011 010 110 100 101Hall sensor
PWM5
PWM4
PWM3
PWM2
PWM1
PWM0
0001100000010010 00000110 00100100 00100001 00001001OVDCOND
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 59
Control Flow ChartInitialization
Load new step sequence
to the OVDCOND
register from Table
Hall sensor change?
Yes
No
Key scan/
Other application?
Change Speed?
Calculate new PWM
duty cycle
Yes
No Hall C Hall
B Hall
A Phase
A Phase
B Phase
C 0 0 1 DC+ NC DC- 0 1 1 DC+ DC- NC 0 1 0 NC DC- DC+ 1 1 0 DC- NC DC+ 1 0 0 DC- DC+ NC 1 0 1 NC DC+ DC-
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 60
Control with Hall Sensors
BLDC
Motor
3 phase Inverter bridge
R-LowR-High
Y-Low
Y-HighB-HighB-Low
AC in
+ - DC bus
Motor current
Potentiometer
+
Motor current
Reference-
Hallsensors
Hall sensors
USART/I2C/SPI
/FLTA/CCP2
/FLTB/CCP1
RC3/INT0
/MCLR 28
11
12
13
14
10
27
26
25
24
23
22
21
20
18
17
15
19
16
AN0
AN1AN2/IC1
AN3/IC2AN4/IC3
AVdd
AVss
OSC1
OSC2
RC0
PWM2
PWM1
PWM0
Vdd
Vss
RC7/RX/DT
RC6/TX/CK
RC5/INT2
RC4/INT1
PWM3
PWM5
RB6/PGC
RB7/PGD
PWM4
P
I
C
1
8
F
2
4
3
1
9
87
6
54
3
21
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 61
INDX
Vss
OSC1
FLTA/CCP2
INT0/RC3
Vdd
OSC2
RD0RD1
RC7/RX/DTRC6/TX/CK
/MCLR
QEAQEB
AN4
AN5AN6AN7AN8
RC0
FLTB/CCP1 BLDC
Motor
3 phase Inverter bridge
R-LowR-High
Y-Low
Y-HighB-HighB-Low
AC in
+ - DC bus
Hallsensors
INT0
QE
QE interface
Motor current
Temp. sensor
+
Motor current
Reference-
Power factorcorrection
Motor current
40
12
1516
1718
14
39
38
37
36
35
34
3332
3029
26
31
28
PWM2
PWM1
PWM0VddVssRD7RD6RD5RD4
PWM3
PWM5
PWM4RB6/PGC
RB7/PGD
13
1920
11
27
2524 RC5/INT2
23 RC4/INT1
22 RD3
21 RD2
AN0
P
I
C
1
8
F
4
4
3
1
1098765
43
12
Closed Loop Control With QEI
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 62
FLTA/CCP2
INT0/RC3
FLTB/CCP1
3 phase Inverter bridge
R-LowR-High
Y-Low
Y-HighB-HighB-Low
+ - DC busBack EMF sense
Motor current
Temp. sensor
+
Motor current
Reference-
+
-Back EMF sense
BLDC
Motor
USART/I2C/SPI
Power factorcorrection
Motor current
40
12
1516
1718
14
39
38
37
36
35
34
3332
3029
26
31
28
IC1
Vss
OSC1
PWM2
PWM1
PWM0VddVssRD7RD6RD5RD4
PWM3
PWM5
PWM4RB6/PGC
RB7/PGD
10
13
Vdd
OSC2
1920
RD0RD1
11
27RC7/RX/DT
25 RC6/TX/CK
24 RC5/INT2
23 RC4/INT1
22 RD3
21 RD2
/MCLR
AN0
IC2IC3
AN4
AN5AN6AN7AN8
RC0
P
I
C
1
8
F
4
4
3
1
1
98765432
Closed Loop Control With Back EMFAC in
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 63
Sensorless Control Schemes1) Compare with DC bus/2 2) Compare with virtual neutral
3) Using ADChannels
-
2005 Microchip Technology Incorporated. All Rights Reserved. Slide 64
Lab 4
BLDC Motor Speed Control
Duration : 30 minutes
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 65
Lab 4a & 4bO Goal : To drive a BLDC motor O Task : Derive switching sequence from the datasheetO Steps:
O Create a project in MPLAB IDE V6.42 or higherO Select PIC18F2431 as the target deviceO Add EX4.asm and linker script(18f2431i.lkr) file to the projectO Select ICD2 as debuggerO Open EX4.asmO Go to START LAB-4a HERE and follow the instructions to write
the winding energizing sequenceO Go to START LAB-4b HERE and follow the instructions to access
the winding energizing sequence for the Hall sensor state
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 66
Lab 4a & 4b - HintsO Define the active PWMs for the position corresponding to the Hall inputO Write code to access the position tableO Keep in mind that IC1/IC2/IC3 are on PORTAO Use indirect addressingO Hall A, Hall B and Hall C are connected to IC1, IC2 and IC3 respectively
Note: This is not Commutation sequence
Windings Energizing table
Hall A Hall B Hall C Phase A Phase B Phase C0 0 0 --- --- ---1 0 0 DC+ --- DC-0 1 0 --- DC- DC+1 1 0 DC+ DC- ---0 0 1 DC- DC+ ---1 0 1 --- DC+ DC-0 1 1 DC- --- DC+1 1 1 --- --- ---
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 67
Lab 4a & 4b - Hints
O Motor power connections(4 wire white colored connector):Disconnect the 24V power supply from the board before making motor
connectionsO RED : Connect to M1 on J9 on the BLDC motor control boardO BLACK : Connect to M2 on J9 on the BLDC motor control boardO WHITE : Connect to M3 on J9 on the BLDC motor control boardO GREEN : Connect to G on J9 on the BLDC motor control board
Note 1 : Motor windings Phase A,Phase B and Phase C are connected to terminal M1, M2 and M3 respectively
Note 2 : While running the motor with ICD 2 in debug mode, the program mayhalt sometime. To avoid this, use ICD 2 as programmer not debugger
Note 3 : Refer to the circuit schematics to determine which PWM isconnected to which MOSFET
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 68
Lab 4a & 4b - ResultO Build, program the part and run O Rotate clockwise the pot. REF slowly and observe LEDs
D1, D2 and D3 should turn on @ approx. 30%, 60% and 90% of the pot level respectively (Lab 1)
O Press either switch S2 or S3O Spin the rotor with hand, LEDs D1/D2/D3 should turn on
and off every 12 degrees of rotor rotation (Lab 2)O Turn the Pot REF clockwise, motor should rotate !!!!!!!!!!!!!!O Press S3 to toggle between RUN and STOP conditionsO Press S2 to toggle between direction of rotationO If motor STOPs and LED D1 blinks, it indicates that there
was a over current faultO Reduce the speed ref and press either S2 or S3
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 69
ResourcesVisit www.microchip.com\motor
O Application notes onO Theory of Stepper, Brush DC, Brushless DC and
AC Induction motorsO Stepper and Brushed DC motor control using PIC16F684O Brushless DC motor control using PIC18FXX31 and
dsPIC digital signal controller (DSC)O Induction motor control using PIC16F7X7, PIC18FXX31
and dsPIC DSC
O Web seminars on ACIM and BLDC motorcontrol
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 70
Resources - Demo boardsO PICDEM MC motor control demo board
O Part number : DM183011O Completely isolatedO Debug tools can be connected when the board is liveO Low cost design
O dsPICDEM MC motor control dev kitO Low and high voltage versionsO Power module + control boardO Part numbers : DM300020, DM300021, DM300022
O Visit www.microchip.com\motor for all motor control related materials
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 71
PICDEM MC
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 72
Motor Control GUI
Main control window
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 73
Motor Control GUI
ParametersSet up window
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 74
Summary
O New PIC MCUs for motor controlO PIC18FXX31 family features overview O Features of High speed ADC (Lab1)O Features of Motion Feedback Module (Lab2)O Features of Power Control PWM (Lab3)O Overview of motor control using PIC18FXX31 O BLDC motor control (Lab4) O Motor control resources from Microchip
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 75
-
2005 Microchip Technology Incorporated. All Rights Reserved. Class Slide 76