You are on page 1of 76

953 MCL

Motor Control hands-on using PIC18FXX31 Microcontrollers

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

Agenda & Timeline


PIC18FXX31 family overview Training board overview High speed ADC features Initialize ADC : Lab1& discuss answer Motion Feedback Module(MFM) features Initialize MFM : Lab2 & discuss answer Power Control PWM(PCPWM) features Initialize PCPWM : Lab3 & discuss answer Overview of BLDC motor control using PIC18FXX31 BLDC speed control: Lab4 & discuss answer Motor control resources from Microchip Q&A
Class

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

Motor Control PIC MCUs


Mid-Range PIC16 series


PIC16F684/716 14/18 pin


ECCP, ADCs and comparators 3 CCPs, ADCs and Comparators

PIC16F7X7 series 28/40 pin


High end PIC18 series- This class


PIC18FXX31 series 28/40 pin


Power Control PWM (PCPWM), High-speed ADCs and Motion Feedback Module (MFM) dsPIC digital signal controller family

dsPIC2010 to dsPIC6010 28 pin to 80 pin


Power Control PWM (PCPWM), High-speed ADCs and Motion Feedback Module (MFM)
Class

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

You should have.


1) 2) 3) 4) 5) MPLAB IDE V7.10 or higher installed Complete MPLAB ICD2 setup BLDC motor control board(05-60001) 24V power supply for the above board Hurst(NTDynamo) BLDC motor with

Power cable (4 wires with white square connector) and Hall sensor cable (5 wires with 8 pin inline connector)

6) Circuit schematic of BLDC motor control board 7) Datasheet of PIC18F2331/2431/4331/4431

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

PIC18FXX31 Spec. Overview


Features
Packages Program memory bytes RAM bytes EEPROM bytes I/O ports CCP module Timers Serial I/O Failsafe Clock monitor Power manage modes ICSP,PBOR, LVD Max. speed

PIC18F2331 PIC18F2431 PIC18F4331 PIC18F4431


28SP,28SO 8192 768 256 22 2 3-16Bit,1-8bit, 1-WDT EUSART/I2C/SPI Yes RUN, IDLE and SLEEP Yes 40 MHz 28SP,28SO 16384 768 256 22 2 3-16Bit,1-8bit, 1-WDT EUSART/I2C/SPI Yes RUN, IDLE and SLEEP Yes 40 MHz 40P,44L,44PT 8192 768 256 34 2 3-16Bit,1-8bit, 1-WDT EUSART/I2C/SPI Yes RUN, IDLE and SLEEP Yes 40 MHz 40P,44ML, 44L,44PT 16384 768 256 34 2 3-16Bit,1-8bit, 1-WDT EUSART/I2C/SPI Yes RUN, IDLE and SLEEP Yes 40 MHz
Slide 5

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

PIC18FXX31 Features For Motor Control


Features PIC18F2331 PIC18F2431 PIC18F4331 PIC18F4431
Power Control PWM module Timer5 module Input Capture 3 channels w/ complementary outputs yes 3 3 channels w/ complementary outputs yes 3 QEA, QEB, INDX 4 channels w/ complementary outputs yes 3 4 channels w/ complementary outputs yes 3

Quadrature Encoder QEA, QEB, INDX Interface High-Speed ADC 5 10bit channels External Fault 2 Inputs

QEA, QEB, INDX QEA, QEB, INDX

5 10bit 2

9 10bit 2

9 10bit 2

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

PIC18Fxx31 overview

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

Pinout (40-pin devices)


/MCLR/Vpp/RE3 RA0/AN0 RA1/AN1 RA2/AN2/Vref-/CAP1/INDX RA3/AN3/Vref+/CAP2/QEA RA4/AN4/CAP3/QEB RA5/AN5/LVDIN RE0/AN6 RE1/AN7 RE2/AN8 AVdd AVss OSC1/CLKI/RA7 OSC2/CLKO/RA6 RC0/T1OSO/T1CKI RC1/CCP2/T1OSI/~FLTA RC2/CCP1/~FLTB RC3/T0CKI/GPCKI/INT0 RD0/T0CKI/T5CKI RD1/SDO
2005 Microchip Technology Incorporated. All Rights Reserved.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Class

40 RB7/KBI3/PGD 39 RB6/KBI2/PGC 38 RB5/KBI1/PWM4/PGM 37 RB4/KBIO/PWM5 36 RB3/PWM3

PIC18F4431

35 RB2/PWM2 34 RB1/PWM1 33 RB0/PWM0 32 Vdd 31 Vss 30 RD7/PWM7 29 28 27 26 25 24 RD6/PWM6 RD5/PWM4 RD4/~FLTA RC7/RX/DT/SDO RC6/TX/CK/~SS RC5/INT2/SCK/SCL

23 RC4/INT1/SDI/SDA 22 RD3/SCK/SCL 21 RD2/SDI/SDA Slide 8

Pinout (28-pin devices)


/MCLR/Vpp/RE3 1 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 2 3 4 5 6 7 8 9 10 11 12 28 RB7/PGD 27 RB6/PGC 26 RB5/PGM/PWM4 25 RB4/PWM5

PIC18F2431

24 RB3/PWM3 23 RB2/PWM2 22 RB1/PWM1 21 RB0/PWM0 20 VDD 19 Vss 18 RC7/RX/DT 17 RC6/TX/CK 16 RC5/INT2/SDO 15 RC4/INT1/SDI/SDA

RC2/CCP1/~FLTB 13 RC3/T0CKI/T5CKI/INT0 14

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

Training Board Overview

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

10

Training Board
PIC18F2431 Power Supply connector S1 Reset Pot REF S2 FWD/REV S3 RUN/STOP Serial Connector
2005 Microchip Technology Incorporated. All Rights Reserved.

Shunt Resistor

ICD 2 Connector Current Limit Pot


Class

Motor Connectors
Slide 11

Training Board

Power MOSFETs

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

12

Jumpers and LEDs


PIC18F2431 Jumper J2 LEDs PWM0 to PWM5

Jumper J15 D7 Power LED LEDs D1 D2 D3 Jumpers J7, J8, J11, J12, J13, J14
2005 Microchip Technology Incorporated. All Rights Reserved. Class

Slide

13

Default Jumper settings


J2(2 pin) - shorted. J15(3 pin) - shorted between pin 2 & 3


(short link towards the crystal oscillator)

J7, J11 and J13 - shorted between pin 1 & 2


(short link towards the ICD2 connector)

J8, J12, J14, J16 and J17 keep open


Keep Potentiometer REF(R14) completely turned counter clockwise Keep Potentiometer R60 completely turned clockwise
Class

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

14

Hardware Block Diagram


Power supply
AC input Motor current REF
/MCLR AN0 AN1 AN2/IC1 1 2 3 28 27 26 25 RB7/PGD RB6/PGC PWM4 PWM5 PWM3 PWM2 PWM1 PWM0 Vdd Vss RC7/RX RC6/TX RC5/INT2 RC4/INT1

+15V +5V Gnd +24V


B-Low B-High Y-High Y-Low R-High R-Low
M1

PIC18F2431

Hall sensors

4 AN3/IC2 5 AN4/IC3 6 AVdd 7 AVss 8 OSC1 9 OSC2 10 RC0 11 /FLTA/CCP2 12

24 23 22 21 20 19 18 17 16 15

3 phase Inverter bridge


IM Shunt

M2 M3

BLDC Motor

HA HB HC

Motor current IM

/FLTB/CCP1 RC3/INT0

J9

13 14

Hall sensors

R60

IREFERENCE
Class

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

15

Program flow - Main routines


Start

Initialize ADC Initialize MFM Initialize PCPWM

(LAB1-a) (LAB2) (LAB3)

Commutation sequence table

(LAB4-a)

Main_loop

Calculate PWM duty cycle Switch S2 and S3 check Exercises you need to do

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

16

Program flow - ISR routines


ISR_HIGH IC1/IC2/IC3 ISR? Read PORTA<4:2> states and display on D1/2/3 Update commutation sequence Update Speed Reference and motor current Filter the FaultA and indicate Motor Over current RETFIE
Slide 17

(LAB4-b)

(LAB1-b)
ADC ISR? Read FIFO

PWM ISR?

Read FaultA status

Exercises you need to do


2005 Microchip Technology Incorporated. All Rights Reserved. Class

High-speed ADC module

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

18

High-Speed ADC

Up to 9 channels Simultaneous two-channel sampling Two S/H circuits and 1 conversion circuit Sequential sampling of 1, 2, or 4 channels Auto-conversion capability 4-word FIFO with selectable interrupt frequency Selectable external triggers Programmable acquisition time

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

19

ADC Functional Block Diagram


Vref select AVdd AVss Vref+ VrefVref Mux AVrefAVref+

MUX
S/H-1 Ch. Sel 1 2 3 4
10 10 10 10

AN1 AN5 AN3 AN7

B B D D

Analog Mux

S/H2

4x10-bit FIFO
S/H-1 Ch. Sel

Input mux control

Not available on 28 pin devices


2005 Microchip Technology Incorporated. All Rights Reserved.

S/H-2 Ch. Sel


Slide 20

Class

8 bit data bus

AN0 AN4 AN8 AN2 AN6

A A A C C

ADC ADC
Analog Mux S/H1

Conversion logic ADRESH,ADRESL

ADC Modes of Operation


ADC Mode
Multi-channel sequential Mode 1 (SEQM1) Multi-channel sequential Mode 2 (SEQM2) Multi-channel simultaneous Mode 1 ( STNM1) Multi-channel simultaneous Mode 2 (STNM2)

Description
A & B are sampled and converted sequentially A,B,C& D are sampled and converted sequentially A & B sampled simultaneously and converted sequentially A & B sampled simultaneously and converted sequentially. Then C & D sampled simultaneously and converted sequentially. A is sampled and converted B is sampled and converted C is sampled and converted D is sampled and converted The sequence is executed once The sequence is executed continuously
Class

Single Channel mode 1 (SCM1) Single Channel mode 2 (SCM2) Single Channel mode 3 (SCM3) Single Channel mode 4 (SCM4) Auto conversion Single shot mode Auto conversion continuous loop mode
2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

21

ADC Control Registers


SFR
ADCON0 ADCON1 ADCON2 ADCON3 ADCHS ANSEL0 ANSEL1 Bit7 --Bit 6 --Bit 5 Auto CONV --Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Auto Auto Conv mode GO/ ADON SCH ACMOD<1:0> Done Vref source FIFO FIFO FIFO FIFO read VCFG<1:0> EN empty Ovrfl pointer AD A/D acquisition time selection A/D clock select format ACQT<3:0> ADCS<2:0> A/D int select --A/D trigger source select SSRC<4:0> Sample D Sample B Sample C Sample A SDSEL<1:0> SBSEL<1:0> SCSEL<1:0> SASEL<1:0> Pin input select: Analog/digital ANS<7:0> Pin input select: Analog/digital ANS<15:8>

Trigger Sources ADCON3<4:0> RBO/INT pin xxxx1 Timer5 Overflow xxx1x Input Capture 1 xx1xx CCP2 Compare x1xxx PCPWM 1xxxx
2005 Microchip Technology Incorporated. All Rights Reserved.

Interrupt Options Each write to FIFO 2nd & 4th write to FIFO Every 4th write to FIFO

ADCON3<7:6> 00 01 10

(These options ignored in single shot mode.)


Class

Slide

22

Lab 1a and 1b Initializing AD Converter Module


Duration : 20 minutes Note : Do not connect any of the motor cables to the board at this time.
2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

23

Lab 1a & 1b

Goal : To get familiarized with new high speed A/D module Task : Initialize ADC to read potentiometer(REF) and motor current Steps:

Create a project in MPLAB IDE V6.42 or higher Select PIC18F2431 as the target device Add EX1.asm and linker script(18f2431i.lkr) file to the project Select ICD2 as debugger Open EX1.asm, Go to START LAB-1a HERE and initialize ADC Go to START LAB-1b HERE and read ADC result 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

24

Lab 1a & 1b - Hints


REF pot connected to AN1 Motor current feedback connected to AN0 Enable appropriate multi channel conversion mode Left justified result Enable FIFO Interrupt when 2nd and 4th word written to FIFO Enable appropriate analog channels for conversion

Note : Do not connect any of the motor cables to the board at this time.
2005 Microchip Technology Incorporated. All Rights Reserved. Class

Slide

25

Lab 1a & 1b - Result


Build, program the part and run the program Rotate clockwise the pot. REF slowly LEDs D1, D2 and D3 should turn on @ approx. 30%, 60% and 90% of the pot level respectively Press either switch S2 or S3 LEDs D1, D2 and D3 should turn ON and OFF sequentially.

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

26

Motion Feedback Module (MFM)


Quadrature Encoder Interface (QEI) Input Captures (IC)

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

27

Quadrature Encoder Interface


Two phase inputs (QEA, QEB) and one index input interface Two level position tracking: x2 and x4 Direction detection Velocity measurement mode :

Programmable postscaler for high-speed velocity measurement

Programmable digital filters on each input pin

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

28

QEI Block Diagram


Clock Divider
INDEX/IC1 Tcy

Digital Filter Logic Digital Filter Logic

Velocity Quadrature Decoder Logic

Postscaler Clock

Velocity capture

QEA/IC2

Digital Filter Logic


QEB/IC3

Direction
COUNTER 16-Bit Up/Down Counter

Reset

Comparator Max Counter

Position interrupt

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

8 bit data bus


29

Velocity interrupt

QEI Position Tracking Mode


Forward Reverse

QEA QEB
++++++++++++++++++++++++ - - - - - - - - - - - - - - - - - - - - 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 0000 0001 0002

Position counter

0003 0002 0001 0000 1541 1540 1539 1538 1537 1536 1535 1534 1533 1532 1531 1530 1529 1528 1527 1526 1525 1524 1523 1522
Class

Max counter = 1541 Index FWD/ REV Interrupts


Position Direction Position Max count change Max count
2005 Microchip Technology Incorporated. All Rights Reserved.

Position Index
Slide 30

Noise filters

Clock 3 cycles Filter Input (Pin) Filter output Noise

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

31

QEI - Velocity Measurement

QEA QEB Vel_out Vel_capture


1234 1246

Timer5 Vel_REG Interrupt

+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 1246

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

32

Input Capture Block Diagram


Clock Divider Tcy

IC1

Digital Filter Logic Digital Filter Logic Digital Filter Logic

Prescale & mode select

CAPxBUF

IC2

Prescale & mode select

IC3

Prescale & mode select

Timer 5 Timer5 Reset control

Timer 5 Logic

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

33

Input Capture Modes


Edge capture mode - Every falling edge

Edge capture mode - Every rising edge

Edge capture mode - Every 4th rising edge


1 2 3 4

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

34

Input Capture Modes


Edge capture mode - Every 16th rising edge
1 2 15 16

Period measurement mode Rising edge to rising edge

Timer5

Special event trigger modes: a) Trigger on every falling edge of CAP1 input only b) Trigger on every rising edge of CAP1 input only
2005 Microchip Technology Incorporated. All Rights Reserved. Class

Slide

35

Input Capture Modes


Pulse width measurement mode Falling edge to rising edge
Pulse

Timer5 Interrupt

Pulse width measurement mode Rising edge to falling edge


Pulse

Timer5 Interrupt

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

36

Capture for Hall Sensors


Input capture on state change mode : Time base is capture on every CAPx input state change
State 3 State 4 State 5 1 1 1 State 2 State 6 State 1

Capture 1 Capture 2 Capture 3 Time Base


0000h

1 0 1

1 0 0

1 1 0

0 1 0

CAP1BUF CAP2BUF CAP3BUF Time Base Reset


2005 Microchip Technology Incorporated. All Rights Reserved. Class

Slide

37

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.

Slide

38

Lab 2

Goal : To get familiarized with Motion Feedback Module(MFM) Task : Initialize MFM to interface with 3 Hall sensors Steps:

Create a project in MPLAB IDE V6.42 or higher Select PIC18F2431 as the target device Add EX2.asm and linker script(18f2431i.lkr) file to the project Select ICD 2 as debugger Open EX2.asm, go to START LAB-2 HERE and initialize MFM
Class

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

39

Lab 2 - Hints

IC1, IC2 and IC3 pins are used for Hall sensor interface Enable capture on every CAPx state change mode Disable QEI modes Enable interrupt on every IC transition Make Hall sensor connections on connector J9 as follows:

RED : Connect to +5V BLACK : Connect to WHITE : Connect to HA (IC1) BROWN : Connect to HB (IC2) 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

40

Lab 2 - Result

Build, program the part and run the program 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 Press either switch S2 or S3 Spin the rotor with hand, LEDs D1/D2/D3 should turn on and off every 12 degrees of rotor rotation Check the correct sequence:

D1 Step1 Step2 ON ON

D2 OFF ON ON ON OFF OFF

D3 OFF OFF OFF ON ON ON

Step3 OFF Step4 OFF Step5 OFF Step6 ON

Rotate the rotor and keep only D1 ON Turn the rotor by a step (12 degrees) in clockwise when viewed from driving end and follow the table

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

41

Power Control PWM Module (PCPWM)

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

42

Power Control PWM Module


Designed for power and motor control


Single phase and Three-phase AC-Induction Motor Multiple DC Brush Motors Brushless DC Motor UPS Switched Reluctance Motor

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

43

PCPWM Features

Up to 4 channels with complimentary output Edge or center-aligned operation Flexible dead-band generator 50 nS to 25.6 uS @ 40 MHz Hardware fault protection inputs Simultaneous update of duty cycle and period Flexible Special Event trigger output Output override features

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

44

PCPWM Functional Block Diagram


PWMCON 0 PWMCON 1 DTCON FLTCON OVDCON<D/S> PTCON PWM Enable and Mode SFRs Dead Time Control Fault Pin Control SFR PWM Override PWM Timer modes PWM Generator #2

PDC compare output PWM 1/3/5/7 PWM 0/2/4/6

DT

DT

8 bit data bus

PDC2 Buffer PWM Timer (PTMR) Comparator Period register (PTPER) PDC2 Comparator PWM Generator #1 PWM Generator #0 Comparator SEVTCMP
Slide 45 Special Event Trigger

Dead time Generator and Override logic

PWM5 PWM4

Output driver block

PWM3 PWM2 PWM1 PWM0 FLTA

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Edge-aligned PWM
PWM period
PTMR=PTPER PDC0 PDC1 PDC2 PDC3 PTMR=0

PWM1 PWM3 PWM5 PWM7 Interrupt


2005 Microchip Technology Incorporated. All Rights Reserved. Class

Slide

46

Center-aligned PWM
PWM period
PTMR=PTPER PDC0 PDC1 PDC2 PDC3 PTMR=0

PWM1 PWM3 PWM5 PWM7

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

47

PWM Resolution
PWM period PTMR PWM1 PWM3 PWM5 PWM7 Q1Q2 Q3 Q4 n PTPER = 0xn 000 001 Q1Q2 Q3 Q4 n-1 n

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

48

PWM Frequency vs. Resolution


Edge aligned mode: PWMfrequency = (PTPER+1) x (PTMRprescalevalue)
Fosc/4 Center aligned mode: PWMfrequency = 2 x PTPER x (PTMRprescalevalue) Fosc log( Fpwm Resolution = log(2) Fosc/4

Edge aligned mode: Frequency v/s resolution

Fosc 40 MHz 40 MHz 40 MHz 40 MHz 40 MHz 40 MHz 40 MHz 40 MHz 40 MHz 25 MHz 10 MHz
Class

MIPS 10 10 10 10 10 10 10 10 10 6.25 2.5

PTPER value 0xFFF 0x7FF 0x3FF 0x1FF 0x0FF 0x07F 0x03F 0x01F 0x00F 0x0FF 0x0FF

PWM resolution 14 bits 13 bits 12 bits 11 bits 10 bits 9 bits 8 bits 7 bits 6 bits 10 bits 10 bits

PWM frequency 2.4 KHz 4.9 KHz 9.8 KHz 19.5 KHz 39.0 KHz 78.1 KHz 156.2 KHz 312.5 KHz 625 KHz 24.4 KHz 9.8 KHz
Slide 49

2005 Microchip Technology Incorporated. All Rights Reserved.

Configuration Bits

HPOL : High-side power switch polarity


Selects PWM1,3,5,7 are active high/low


Selects PWM0,2,4,8 are active high/low

LPOL : Low side power switch polarity


PWMPIN : PWM output pins state


Selects PWM module to be enabled/disabled upon reset PWM4 output multiplexed with RB5 or RD5 FLTA pin muxed with RC1 or RD4
Class

PWM4MX : PWM4 mux bit


FLTAMX : FLTA pin mux


2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

50

Lab 3 Initialization of PCPWM module


Duration : 20 minutes

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

51

Lab 3

Goal : To get familiarized with Power Control PWM (PCPWM) Task : Initialize PCPWM to control a BLDC motor Steps:

Create a project in MPLAB IDE V6.42 or higher Select PIC18F2431 as the target device Add EX3.asm and linker script(18f2431i.lkr) file to the project Select ICD2 as debugger Open EX3.asm, Go to START LAB-3 HERE and initialize PCPWM
Class

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

52

Lab 3 - Hints

Use PWM0 to PWM5 for the control PWM outputs in edge-aligned or center aligned mode Set PWM outputs in independent mode Set PWM frequency to 16 kHz (Fosc = 5 MHz X 4 PLL) Set FaultA in cycle-by-cycle mode Enable Fault condition on breakpoint Set outputs on PWM pins controlled by the PWM duty cycle

Important : Enable Fault condition on break point

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

53

Lab 3 - Result

Build, program the part and run 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) Press either switch S2 or S3 Spin the rotor with hand, LEDs D1/D2/D3 should turn on and off every 12 degrees of rotor rotation (Lab 2) Turn the Pot REF clockwise, ONLY ONE LED out of PWM0-PWM5 should turn ON When the rotor is rotated, on/off of PWM0-PWM5 LEDs should scroll. When the pot REF is rotated, the intensity of PWM0-PWM5 LEDs should vary
Class

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

54

BLDC Motor Control

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

55

Drive Sequence
VDC+

PWM1 PWM3 PWM5

H1

H2

H3

PIC18Fxx31

(5) (2) (4) (1)


PWM0 PWM2 PWM4

(6) (3)

L1

L2

L3
VDC-

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

56

6 step-Switching Sequence
Step (x) (1) (2) (3) (4) (5) (6) (1) (2) (3) (4) Hall sensor 101 001 011 010 110 100 101 001 011 010 110 Hall A Phase A Hall B Phase B Hall C Phase C High switch H2 H1 H1 H3 H3 H2 Low switch L3 L3 L2 L2 L1 L1
Hall C 0 0 0 1 1 1 Hall B 0 1 1 1 0 0 Hall A 1 1 0 0 0 1 Phase A DC+ DC+ NC DCDCNC Phase B NC DCDCNC DC+ DC+ Phase C DCNC DC+ DC+ NC DC-

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

57

OVDCOND vs. PWM


Step Hall sensor
OVDCOND

(1)

(2)

(3)

(4)

(5)

(6)

001 011 010 110 100 101 00010010 00000110 00100100 00100001 00001001 00011000

PWM5 PWM4 PWM3 PWM2 PWM1 PWM0


2005 Microchip Technology Incorporated. All Rights Reserved. Class

Slide

58

Control Flow Chart


Initialization
Load new step sequence Hall sensor change?
No Yes Calculate new PWM Yes

to the OVDCOND register from Table

Change Speed?
No

duty cycle
Hall C 0 0 0 1 1 1
Class

Key scan/ Other application?

Hall B 0 1 1 1 0 0

Hall A 1 1 0 0 0 1

Phase A DC+ DC+ NC DCDCNC

Phase B NC DCDCNC DC+ DC+


Slide

Phase C DCNC DC+ DC+ NC DC59

2005 Microchip Technology Incorporated. All Rights Reserved.

Control with Hall Sensors


AC in
Potentiometer
/MCLR AN0 1 2 28 RB7/PGD 27 RB6/PGC 26 PWM4 25 PWM5

+
B-Low B-High Y-High Y-Low R-High R-Low

- DC bus

Motor current Hall sensors

Motor current Reference

AN1 3 AN2/IC1 4 AN3/IC2 5 AN4/IC3 6 AVdd 7 AVss 8 OSC1 9 OSC2 10 RC0 11 /FLTA/CCP2 12 /FLTB/CCP1 RC3/INT0 13 14

PIC18F2431

24 PWM3 23 PWM2 22 PWM1 21 PWM0 20 Vdd 19 Vss

BLDC Motor

18 RC7/RX/DT 17 RC6/TX/CK 16 RC5/INT2 15 RC4/INT1

3 phase Inverter bridge

Hall sensors

USART/ I2C/SPI

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

60

Closed Loop Control With QEI


AC in
/MCLR 1 AN0 2 INDX 3 QEA 4 QEB 5 AN4 6 AN5 7 AN6 8 AN7 9 AN8 10 Vdd 11 Vss 12 OSC2 13 OSC1 14 RC0 15 FLTA/CCP2 16 FLTB/CCP1 17 INT0/RC3 18 RD0 19 RD1 20 40 RB7/PGD 39 RB6/PGC PWM4 B-Low 38 B-High 37 PWM5

- DC bus

QE interface

PIC18F4431

Motor current Temp. sensor

36 PWM3 35 PWM2

Y-High Y-Low

Motor current Reference

34 PWM1 R-High R-Low 33 PWM0 32 Vdd 31 Vss 30 RD7 29 RD6 28 RD5 27 RD4 26 RC7/RX/DT 25 RC6/TX/CK 24 RC5/INT2 23 RC4/INT1 22 RD3 INT0 21 RD2

3 phase Inverter bridge


BLDC Motor Hall sensors

Motor current

Power factor correction


2005 Microchip Technology Incorporated. All Rights Reserved. Class

QE
Slide 61

Closed Loop Control With Back EMF


AC in
/MCLR AN0 IC1 IC2 IC3 AN4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 40 RB7/PGD 39 RB6/PGC PWM4 B-Low 38 B-High 37 PWM5

- DC bus

Back EMF sense Motor current Temp. sensor

PIC18F4431

AN5 AN6 AN7 AN8 Vdd Vss OSC2 OSC1

36 PWM3 35 PWM2

Y-High Y-Low

Motor current Reference

RC0 15 FLTA/CCP2 16 FLTB/CCP1 17 INT0/RC3 18 RD0 19 RD1 20

34 PWM1 R-High R-Low 33 PWM0 32 Vdd 31 Vss 30 RD7 29 RD6 28 RD5 27 RD4 USART/ 26 RC7/RX/DT I2C/SPI 25 RC6/TX/CK 24 RC5/INT2 23 RC4/INT1 22 RD3 21 RD2

BLDC Motor

3 phase Inverter bridge

Motor current

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide 62

Power factor correction

Back EMF sense

Sensorless Control Schemes


1) Compare with DC bus/2 2) Compare with virtual neutral

3) Using ADChannels

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

63

Lab 4 BLDC Motor Speed Control


Duration : 30 minutes

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

64

Lab 4a & 4b

Goal : To drive a BLDC motor Task : Derive switching sequence from the datasheet Steps:

Create a project in MPLAB IDE V6.42 or higher Select PIC18F2431 as the target device Add EX4.asm and linker script(18f2431i.lkr) file to the project Select ICD2 as debugger Open EX4.asm Go to START LAB-4a HERE and follow the instructions to write the winding energizing sequence 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

65

Lab 4a & 4b - Hints


Define the active PWMs for the position corresponding to the Hall input Write code to access the position table Keep in mind that IC1/IC2/IC3 are on PORTA<4:2> Use indirect addressing Hall A, Hall B and Hall C are connected to IC1, IC2 and IC3 respectively
Hall A 0 1 0 1 0 1 0 1 Hall B 0 0 1 1 0 0 1 1 Hall C 0 0 0 0 1 1 1 1 Phase A Phase B Phase C ------DC+ --DC--DCDC+ DC+ DC--DCDC+ ----DC+ DCDC--DC+ -------

Windings Energizing table Note: This is not Commutation sequence


2005 Microchip Technology Incorporated. All Rights Reserved. Class

Slide

66

Lab 4a & 4b - Hints


Motor power connections(4 wire white colored connector): Disconnect the 24V power supply from the board before making motor connections RED : Connect to M1 on J9 on the BLDC motor control board BLACK : Connect to M2 on J9 on the BLDC motor control board WHITE : Connect to M3 on J9 on the BLDC motor control board 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 may halt sometime. To avoid this, use ICD 2 as programmer not debugger Note 3 : Refer to the circuit schematics to determine which PWM is connected to which MOSFET

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

67

Lab 4a & 4b - Result


Build, program the part and run 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) Press either switch S2 or S3 Spin the rotor with hand, LEDs D1/D2/D3 should turn on and off every 12 degrees of rotor rotation (Lab 2) Turn the Pot REF clockwise, motor should rotate !!!!!!!!!!!!!! Press S3 to toggle between RUN and STOP conditions Press S2 to toggle between direction of rotation If motor STOPs and LED D1 blinks, it indicates that there was a over current fault Reduce the speed ref and press either S2 or S3
Class

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

68

Resources
Visit www.microchip.com\motor

Application notes on

Theory of Stepper, Brush DC, Brushless DC and AC Induction motors Stepper and Brushed DC motor control using PIC16F684 Brushless DC motor control using PIC18FXX31 and dsPIC digital signal controller (DSC) Induction motor control using PIC16F7X7, PIC18FXX31 and dsPIC DSC

Web seminars on ACIM and BLDC motor control


Class

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

69

Resources - Demo boards


PICDEM MC motor control demo board


Part number : DM183011 Completely isolated Debug tools can be connected when the board is live Low cost design Low and high voltage versions Power module + control board Part numbers : DM300020, DM300021, DM300022

dsPICDEM MC motor control dev kit


Visit www.microchip.com\motor for all motor control related materials


Class

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

70

PICDEM MC

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

71

Motor Control GUI

Main control window

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

72

Motor Control GUI

Parameters Set up window

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

73

Summary

New PIC MCUs for motor control PIC18FXX31 family features overview Features of High speed ADC (Lab1) Features of Motion Feedback Module (Lab2) Features of Power Control PWM (Lab3) Overview of motor control using PIC18FXX31 BLDC motor control (Lab4) Motor control resources from Microchip
Class

2005 Microchip Technology Incorporated. All Rights Reserved.

Slide

74

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

75

2005 Microchip Technology Incorporated. All Rights Reserved.

Class

Slide

76

You might also like