an 00967a

18
© 2005 Microchip Technology Inc. DS00967A-page 1 AN967 INTRODUCTION Single-phase induction motors are extensively used in appliances and industrial controls. The Permanent Split Capacitor (PSC) single-phase induction motor is the simplest and most widely used motor of this type. The classification, construction and working principle of single-phase induction motors are explained in detail in the application note AC Induction Motor Fundamentals” (AN887) available from Microchip. For VF theory and basic operations, refer to AN887 mentioned above, and Speed Control of 3-Phase Induction Motor Using PIC18 Microcontrollers(AN843). By design, PSC motors are unidirectional, which means they are designed to rotate in one direction. By adding either extra windings, and external relays and switches, or by using gear mechanisms, the direction of rotation can be changed. In this application note we will discuss in detail, how to control the speed of a PSC motor in both directions using a PIC16F72 microcontroller and power electronics. The PIC16F72 microcontroller was chosen because it is one of the simplest and low-cost general purpose microcontrollers Microchip has in its portfolio. Even though it does not have the PWMs in hardware to drive complementary PWM outputs with dead band inserted, all PWMs are generated in firmware using timers and output to general purpose output pins. THEORY OF OPERATION A PSC motor is usually a 2-phase asymmetrically wound motor. The main winding is designed to take the load current. The current flowing through the start winding is much less than the main winding. Therefore, the start winding will have a different electrical characteristic compared to the main winding. In order to produce the Magnetomotive Force (MMF) produced by the start winding very near to the main winding, the start winding has additional turns, higher resistance, and reduced current flowing through it. This makes the motor windings asymmetrical. The motor is energized with a single-phase AC power supply, with a capacitor connected in series with the start winding (also called an auxiliary winding) as shown in Figure 1. The value of the capacitor is chosen so that the total impedance on the auxiliary winding produces sufficient phase shift in current to generate a rotating magnetic field in the air gap. Typically, the current flowing through the start winding leads the current flowing through the main winding by 90 degrees. By adding a microcontroller-based control circuit to the motor, the voltage across the main winding and start winding can be maintained at 90 degrees to each other. The other advantage is that the starting capacitor can be removed from the circuit, thus reducing the total system cost. FIGURE 1: ELECTRICAL EQUIVELANT CIRCUIT OF A PSC MOTOR A multiphase inverter can be used to drive the motor. Two methods are discussed in the next section. Author: Padmaraja Yedamale Microchip Technology Inc. Squirrel Cage Rotor A C L N Starting Winding Main Winding VSTART VMAIN Bidirectional VF Control of Single and 3-Phase Induction Motors Using the PIC16F72

Upload: aapaulos

Post on 18-Jul-2016

5 views

Category:

Documents


2 download

DESCRIPTION

Pic

TRANSCRIPT

Page 1: an 00967A

AN967Bidirectional VF Control of Single and 3-Phase Induction

Motors Using the PIC16F72

INTRODUCTION

Single-phase induction motors are extensively used inappliances and industrial controls. The Permanent SplitCapacitor (PSC) single-phase induction motor is thesimplest and most widely used motor of this type. Theclassification, construction and working principle ofsingle-phase induction motors are explained in detail inthe application note “AC Induction MotorFundamentals” (AN887) available from Microchip. ForVF theory and basic operations, refer to AN887mentioned above, and “Speed Control of 3-PhaseInduction Motor Using PIC18 Microcontrollers”(AN843).

By design, PSC motors are unidirectional, whichmeans they are designed to rotate in one direction. Byadding either extra windings, and external relays andswitches, or by using gear mechanisms, the direction ofrotation can be changed. In this application note we willdiscuss in detail, how to control the speed of a PSCmotor in both directions using a PIC16F72microcontroller and power electronics.

The PIC16F72 microcontroller was chosen because itis one of the simplest and low-cost general purposemicrocontrollers Microchip has in its portfolio. Eventhough it does not have the PWMs in hardware to drivecomplementary PWM outputs with dead band inserted,all PWMs are generated in firmware using timers andoutput to general purpose output pins.

THEORY OF OPERATION

A PSC motor is usually a 2-phase asymmetricallywound motor. The main winding is designed to take theload current. The current flowing through the startwinding is much less than the main winding. Therefore,the start winding will have a different electricalcharacteristic compared to the main winding. In orderto produce the Magnetomotive Force (MMF) producedby the start winding very near to the main winding, thestart winding has additional turns, higher resistance,and reduced current flowing through it. This makes themotor windings asymmetrical.

The motor is energized with a single-phase AC powersupply, with a capacitor connected in series with thestart winding (also called an auxiliary winding) asshown in Figure 1. The value of the capacitor is chosenso that the total impedance on the auxiliary windingproduces sufficient phase shift in current to generate arotating magnetic field in the air gap.

Typically, the current flowing through the start windingleads the current flowing through the main winding by90 degrees.

By adding a microcontroller-based control circuit to themotor, the voltage across the main winding and startwinding can be maintained at 90 degrees to each other.The other advantage is that the starting capacitor canbe removed from the circuit, thus reducing the totalsystem cost.

FIGURE 1: ELECTRICAL EQUIVELANT CIRCUIT OF A PSC MOTOR

A multiphase inverter can be used to drive the motor.Two methods are discussed in the next section.

Author: Padmaraja YedamaleMicrochip Technology Inc.

SquirrelCage Rotor

AC

L

N

StartingWinding

MainWinding

VSTART

VMAIN

© 2005 Microchip Technology Inc. DS00967A-page 1

Page 2: an 00967A

AN967

DRIVE TOPOLOGY

Using an H-Bridge Inverter

The first approach is relatively easy as far as thepower circuit and control circuit are concerned. Onthe input side, a voltage doubler is used and on theoutput side an H-bridge, or 2-phase inverter, is usedas shown in Figure 2. One end of the main and startwindings are connected to each half bridge and theother ends are connected together to the neutralpoint of the AC power supply, which also serves asthe center point for the voltage doubler.

The control circuit requires four PWMs with twocomplementary pairs with sufficient dead bandbetween the complementary outputs. PWM0-PWM1and PWM2-PWM3 are the PWM pairs with dead band.The PIC16F72 does not have PWMs designed in thehardware to output the way we need. Therefore, thePWMs should be generated in firmware and output tothe port pins. Using PWMs, the DC bus is synthesizedto give two sine voltages at 90 degrees out of phasewith varying amplitude and varying frequencyaccording to the VF profile. If the voltage applied to themain winding lags the start winding by 90 degrees, themotor runs in one (i.e., forward) direction. To reversethe direction of rotation, the voltage supplied to themain winding should lead the voltage supplied to thestart winding.

Figure 3 and Figure 4 show the main and start windingvoltages in forward and reverse respectively.

FIGURE 2: PSC DRIVE WITH AN H-BRIDGE

AC

PWM3

PWM1

PWM2

PWM0

PWM3PWM1

PWM2PWM0

PIC16F72

Gate

Driver

Main

Winding

StartWinding

VMAIN

VSTART

L

N

Vm

Vm +- /2π

DS00967A-page 2 © 2005 Microchip Technology Inc.

Page 3: an 00967A

AN967

FIGURE 3: MOTOR RUNNING IN FORWARD DIRECTION

FIGURE 4: MOTOR RUNNING IN REVERSE DIRECTION

-150.00

-100.00

-50.00

0.00

50.00

100.00

150.00

0 50 100 150 200 250 300 350 400

Phase Angle

% P

has

e V

olt

age

VMAIN

VSTART

VMAIN = Sin(ωt)

VSTART = Sin(ωt+π/2)

-150.00

-100.00

-50.00

0.00

50.00

100.00

150.00

0 50 100 150 200 250 300 350 400

Phase Angle

% P

has

e V

olt

age

VMAIN

VSTART

VMAIN = Sin(ωt)

VSTART = Sin(ωt-π/2)

© 2005 Microchip Technology Inc. DS00967A-page 3

Page 4: an 00967A

AN967

This method of controlling a PSC type motor has afew disadvantages.

• Because the main winding and start windings have different electric characteristics, the current flowing through each switch is unbalanced. Over time, this may lead to premature breakdown of switching devices in the inverter.

• The common point of the windings is directly connected to the neutral power supply. This may increase the switching signal coming into the mains power supply and increase the noise emit-ted onto the line. This also may limit the EMI level of the product, violating certain design goals and regulations.

• The effective DC voltage handled is high due to the input voltage doubler circuit.

• Lastly, the cost of the voltage doubler circuit itself is high because of two large power capacitors.

A better solution to minimize these problems would beto use a 3-phase inverter bridge, as discussed in thenext section.

Using a 3-Phase Inverter Bridge

The input section is replaced with a standard diodebridge rectifier. The output section has a 3-phaseinverter bridge. The main difference from the previousscheme is the way the motor windings are connectedto the inverter. One end of the main winding and startwindings are connected to one half bridge each. Theother ends are tied together and connected to the thirdhalf bridge, as shown in Figure 5.

Refer to Appendix B: “Schematics” for the schemat-ics that reference the PIC16F72 with a 3-phase inverterbridge.

With this drive topology, control becomes more effi-cient; however, the control algorithm becomes morecomplex. The voltages Va, Vb and Vc should be con-trolled to achieve the phase difference between theeffective voltages across the main and start windings tohave a 90 degree phase shift to each other.

The turn ratio of the start winding to the main winding isdefined by:

EQUATION 1:

where α is the turn ratio, and VMAIN and VSTART are theeffective voltage across the main winding and the startwinding.

In order to have equal voltage stress on all devices,thus improving the device utilization and provide themaximum possible output voltage for a given DC busvoltage, all three inverter phase voltages are kept at thesame amplitude as follows:

EQUATION 2:

The effective voltage across the main and start windingis given as:

EQUATION 3:

The voltages are shown in the phasor diagram inFigure 6.

FIGURE 5: CONTROLLING A PSC MOTOR WITH A 3-PHASE INVERTER BRIDGE

α VMAIN

VSTART---------------------=

| Va | = | Vb | = | Vc | = | V1 |

VMAIN = Va – Vc

VSTART = Vb – Vc

AC

PWM5

PWM3

PWM1

PWM4

PWM2

PWM0

PWM5PWM3PWM1

PWM4PWM2PWM0

PIC16F72

Gate

Driver

Main

Winding

StartWinding

Va

Vb

Vc

DS00967A-page 4 © 2005 Microchip Technology Inc.

Page 5: an 00967A

AN967

FIGURE 6: VOLTAGE PHASOR DIAGRAM

As seen in the phasor diagram in Figure 6, the voltagesacross phase A and phase B are out of phase, and thephase difference between phase A and phase C is θdegrees. By applying basic trigonometry, θ can becalculated by:

EQUATION 4:

By applying the Pythagorean Theorem, the voltagevector V1 can be calculated as:

EQUATION 5:

Because the turn ratio remains constant for a givenmotor, α can be a compile time option. With this, θ andV1 can be precomputed for a given motor. This simpli-fies the run time calculation. Based on the phase angle,phase voltages Va, Vb and Vc can be calculated as:

EQUATION 6:

Vdc is the DC bus voltage, and ωt is the angular velocityof the electrical cycle. The direction of rotation can beeasily controlled by adding or subtracting θ in the Vccalculation.

Figure 7 shows the phase voltages Va, Vb and Vc, andFigure 8 shows the effective voltages across the mainwinding (VMAIN) and the start winding (VSTART).

Figure 8 also shows that the effective phase differencebetween the voltages is 90 degrees and the effectivevoltage ratio is α.

FIGURE 7: PHASE VOLTAGES Va, Vb and Vd

Va~

Vc~

Vb~

VMAIN~

Va~

Vc~– =

VSTART~

Vb Vc~

– =~

V1V1

V1VαV

ζ θ

Angle θ = 180° – 2 tan-1 (α).

V1 V1 α2+( )

2------------------------×=

Va V1 ωt( )cos× Vdc2

----------+=

Vb V1 ωt( )cos×–Vdc

2----------+=

Vc V1 ωt θ±( )cos× Vdc2

----------+=

-100

-80

-60

-40

-20

0

20

40

60

80

100

0 50 100 150 200 250 300 350 400

Phase angle

% P

has

e vo

ltag

e

Va

Vb

Vc

© 2005 Microchip Technology Inc. DS00967A-page 5

Page 6: an 00967A

AN967

FIGURE 8: VOLTAGE ACROSS MAIN WINDING (VMAIN) AND START WINDING (VSTART)

-150

-100

-50

0

50

100

150

0 50 100 150 200 250 300 350 400

Phase Angle

% P

has

e V

olt

age

VMAIN

VSTART

DS00967A-page 6 © 2005 Microchip Technology Inc.

Page 7: an 00967A

AN967

IMPLEMENTATION USING THE PIC16F72

In order to control a 3-phase inverter bridge, we needthree PWM pairs with complementary outputs. In addi-tion, each complementary pair of PWMs needs deadtime in between any OFF and ON switch events toavoid a DC bus short circuit. The PIC16F72 does nothave these features in the hardware. However, this canbe easily implemented using a general purpose timerand six output pins as shown in Figure 9.

Generating Software PWMs

The scheme shown here gives a fixed PWM frequencyof approximately 7.9 kHz. Timer1 (1:4 prescale) iscounted up from 00 to 634. At the beginning of the cycle(when Timer1 = 00), the PWMs controlling the upperswitches (i.e., PWM1, PWM3 and PWM5) are turnedON. Based on the individual PWM duty cycle, thecorresponding PWM output is turned OFF.

After five instruction cycles, the complementary PWMis turned ON. This gives a dead time of 1 μs when themicrocontroller is running at 20 MHz. When the countreaches 624, all outputs are turned OFF. A new PWMcycle starts after 10 instruction cycles.

In the source code provided with this application note(see Appendix A: “Source Code”), instead of com-paring the Timer1 values corresponding to the dutycycle values, a relative count is calculated with respectto the previous PWM duty cycle. This count is sub-tracted from 0xFF (Timer1 is configured as an 8-bittimer) and loaded to the Timer1 register. When theTimer1 value overflows, in Timer1 overflow ISR, thecorresponding Odd PWM is turned OFF and the corre-sponding Even PWM is turned ON after five instructioncycles. This is done for all three pairs of PWM. Refer tothe flowcharts in Figure 10 through Figure 11 for moredetails.

FIGURE 9: PWM SOFTWARE IMPLEMENTATION

PWM period = 634 for ~8 kHz PWM frequency @ 20 MHz FOSC

PWM 1/3/5 ON

PWM 1 OFF

PWM 0 ON

PWM 3 OFF

PWM 5 OFF

PWM 2 ON

PWM 4 ON

PWM 0/2/4 OFF

Dead TimeDead Time Dead Time Dead Time

Timer 1 counting UPfrom 00 to 634

00

634624

PWM 1/3/5 ON

Note: The PWMs are numbered with respect to Figure 5.

© 2005 Microchip Technology Inc. DS00967A-page 7

Page 8: an 00967A

AN967

FIGURE 10: MAIN LOOP

Start

InitializePORTB – Fault and toggle switch interface

PORTC – PWMs

MAIN_LOOP

Is S1pressed?

Copy Sine table values toRAM locations

Initialize ADC to read Motor currentand Potentiometer

Initialize Timer0, Timer1, Interruptsand Sine table offsets

Timer0rollover?

Update PWM duty cycles (A)(UPDATE_PWM_DUTYCYCLES)

Prioritize PWM duty cycles (B)(PRIORITIZE_PWMS)

Calculate new speed

Set ADC ‘GO’ bit

Is ADCresult ready? C

AD_CONV_COMPLETE

Yes

No

Yes

No

Yes

No

DS00967A-page 8 © 2005 Microchip Technology Inc.

Page 9: an 00967A

AN967

FIGURE 10: MAIN LOOP (CONTINUED)

Is PWM3<PWM1?

A B

Return

UPDATE_PWM_DUTYCYCLES PRIORITIZE_PWMS

Return

Return

Is PWM5<PWM3?

Is PWM3<PWM1?

AD_CONV_COMPLETE

Read value pointed by TABLE_OFFSET1 fromthe Sine table (corresponds to PWM1/0 pair)

PWM1/0 duty cycle = Sine (TABLE_OFFFSET1) x NEW_FREQ

Read value pointed by TABLE_OFFSET2 fromthe Sine table (corresponds to PWM3/2 pair)

Read value pointed by TABLE_OFFSET3 fromthe Sine table (corresponds to PWM5/4 pair)

PWM5/4 duty cycle = Sine (TABLE_OFFSET3) x NEW_FREQ

PWM3/2 duty cycle = Sine (TABLE_OFFFSET2) x NEW_FREQ

Interchange PWM1 and PWM3 duty cycles

Interchange PWM3 and PWM5 duty cycles

Interchange PWM1 and PWM3 duty cycles

Yes

No

No

No

Yes

Yes

C

NEW_FREQ = ADRES MOTOR_CURRENT = ADRES HEATSINK_TEMP = ADRES

Set limit on NEW_FREQ0x30 < NEW_FREQ < 0xD0

Set ADC mux to read motor current(for next cycle)

Set OVER_CURRENTflag Set OVER_TEMPERATURE flag

Motor current >MAX_MOTOR_CURRENT?

HS Temp>MAX_HEATSINK_TEMP?No No

Yes

© 2005 Microchip Technology Inc. DS00967A-page 9

Page 10: an 00967A

AN967

FIGURE 11: INTERRUPT SERVICE ROUTINES (ISR)

ISR_INT CHECK_FAULT

TIMER1_OVERFLOW

RETFIE

T1Timer1 ISR?

Context Save: WREG and STATUS

Timer0 ISR?

INT ISR?

Restore: WREG and STATUS

T0

INT

x

TIMER1_OVERFLOW

TIMER0_OVERFLOW

CHECK_FAULT

Yes

No

Yes

No

Yes

No

INT

OVER_CURRENT_COUNT (OC_COUNT) =OVER_CURRENT_COUNT - 1

Is OC_COUNT = 0?

STOP_MOTOR

x

Timer0 = Count for NEW_FREQ

Reset overcurrent filter count

x

T0

TIMER0_OVERFLOW

No

Yes

x

T1

Lowest PWM Duty Cycle Medium PWM Duty Cycle Highest PWM Duty Cycle New PWM Duty Cycle

Turn Off Odd Channel w/leastPWM Duty Cycle value

5 Cycles Delay(Dead Time = 1 μS)

Turn ON ComplementaryChannel

Timer1 = Medium Duty Cycle – Lowest Duty Cycle

Turn Off Odd Channel w/mediumPWM Duty Cycle value

5 Cycles Delay(Dead Time = 1 μS)

Turn ON ComplementaryChannel

Turn Off Odd Channel w/highestPWM Duty Cycle value

Turn Off All 6 Channels

5 Cycles Delay(Dead Time = 1 μS)

5 Cycles Delay(Dead Time = 1 μS)

Turn ON ComplementaryChannel

Turn ON All Odd PWMChannels (1, 3 and 5)

Timer1 = Highest Duty Cycle –Medium Duty Cycle

Timer1 = End of PWM Cycle –Highest Duty Cycle

Timer1 = Lowest Duty Cycle

DS00967A-page 10 © 2005 Microchip Technology Inc.

Page 11: an 00967A

AN967

Initialization

• PORTC<0:5> are initialized to output PWMs.

• Timer1 is initialized with 8-bit operation and 1:4 prescale.

• A/D channels are initialized to read frequency reference (AN0), motor current (AN1) and heatsink temperature (AN2). - Frequency reference is read using a

potentiometer connected to A/D Channel 0. - Motor current is read using a shunt resistor in

the DC return path. The voltage corresponding to the motor current is amplified and connected to A/D channel 1.

• Timer0 is used for setting the motor frequency based on the potentiometer setting. On every Timer0 overflow, new PWM duty cycles are advanced by 10 electrical degrees on the Sine table.

• The Sine table is loaded into RAM• Timer0 overflow, Timer1 overflow and INT

interrupts are enabled.

Main Routine

These tasks are done in the MAIN_LOOP routine:

• New PWM duty cycle is calculated by the subroutine UPDATE_PWM_DUTYCYCLES

Three pointers pointing to three different values onthe Sine table corresponding to the phasedifference between Va, Vb and Vc. The sine table isdrawn to maximum duty cycle available when thesine value reaches 90 degrees. Every value isscaled down based on the frequency input tofollow a linear VF profile.

• PWM duty cycle sorting is handled by the subroutine PRIORITIZE_PWMS

PWM duty cycles calculated earlier are sorted inascending order, so that the duty cycle with mini-mum ON time can be addressed first and PWMwith maximum duty cycle last. CorrespondingFlags are set to indicate which PWM duty cyclecorresponds to which PWM output.

• Timer0 reload value is calculated by the subroutine TIMER0_OVERFLOW

Timer0 is used for setting the motor frequency. TheTimer0 reload value is calculated based on threefactors: first is the frequency reference input fromthe potentiometer, second is the number of sinetable values, and third is the MCU operatingfrequency.

• Polling for the ADC result is handled by the subroutine AD_CONV_COMPLETE

ADC conversion is poled in the main routine.Alternatively, frequency reference (AN0), motorcurrent (AN1) and heatsink temperature (AN2) areselected and converted.

Interrupt Service Routines (ISRs)

• Timer1 ISR: In the first three Timer1 overflow ISRs, the corresponding Odd PWM output is turned off in each ISR. The complementary output is turned on after a dead time of five cycles (1 μs). In the fourth Timer1 overflow ISR, the PWM cycle is restarted. All PWMs are turned OFF and the timer is loaded with the value corresponding to the lowest duty cycle value. This is repeated for each PWM cycle.

• Timer0 ISR: A flag is set to indicate that the Sine output should advance by 10 degrees on the Sine table. The Timer0 registers are reloaded with the value corresponding to the motor frequency reference.

• INT ISR: The INT pin is used to interface hard-ware overcurrent fault. Motor current is compared with a fixed voltage reference using an op amp comparator. Each time the motor current exceeds the reference, in INT ISR a count (0C_COUNT) is decremented. If the count reaches zero in one Timer0 cycle, then the motor is stopped and overcurrent is indicated. This count is reset in every Timer0 ISR.

© 2005 Microchip Technology Inc. DS00967A-page 11

Page 12: an 00967A

AN967

Controlling a 3-Phase Induction Motor

The advantage of the drive topology shown in Figure 5is the same hardware can be used to control thespeed of a 3-phase induction motor. In order to controla 3-phase induction motor with a Variable Frequency(VF) technique, three pairs of complementary PWMswith dead band are required.

The DC bus is modulated with these PWMs to givethree Sine voltage outputs with 120 degrees phaseshift to each other as shown in Figure 12. This can bedone by changing the offset pointers on the Sine table.Firmware needs to be recompiled and the part shouldbe reprogrammed. To reverse the motor direction, thePWM loaded to two of the phases should beinterchanged.

FIGURE 12: PHASE VOLTAGE FOR 3-PHASE INDUCTION MOTOR CONTROL

PIC16F72 LIMITATIONS

Using the PIC16F72 for control has the followinglimitations:

• MIPS: Generating a software PWM takes significant processing power. This limits any other application that may be required to run on the same MCU.

• PWM Frequency Range: The PWM frequency range is limited and requires firmware changes. The safe PWM frequency range is from 6 kHz to 10 kHz with an operating frequency of 20 MHz. The PWM cycle may have an error up to ±5%. The resolution is also limited between 6 to 8 bits. In addition to this, generating PWM outputs in firmware uses the on-chip Timer, program and data memory.

CONTROL USING A PIC18F2431/4431

The PIC18FXX31 MCUs have a state-of-the-art PowerControl PWM (PCPWM) module on-chip. This modulecan provide three pairs of complementary PWMs withprogrammable dead band. Programming is greatlysimplified using PIC18FXX31 devices, because itreduces the task of generating the software PWMs,which takes most of the processor resource on aPIC16F72. The source code included with thisapplication note (see Appendix A: “Source Code”)also includes single-phase VF control using thePIC18F2431.

To learn more about using PIC18FXX31microcontrollers for different types of motor controls,refer to application notes AN899, Brushless DC MotorControl Using PIC18FXX31 Microcontrollers(DS00899) and AN900, Controlling 3-Phase ACInduction Motors Using the PIC18F4431 (DS00900)available from Microchip.

-150

-100

-50

0

50

100

150

0 50 100 150 200 250 300 350 400

Phase Angle

% P

has

e V

olt

age

Sin(wt)

Sin(wt+120)

Sin(wt+240)

Sin(ωt+240)Sin(ωt) Sin(ωt+120)

DS00967A-page 12 © 2005 Microchip Technology Inc.

Page 13: an 00967A

AN967

CONCLUSION

Microcontroller-based control for a PSC motor makesthe system easy to implement and have control overthe motor in two directions. Implementing thealgorithm using a 3-phase inverter bridge givesflexibility and efficiency of control. In addition, a 3-phase induction motor can be controlled using thesame hardware by making minor modifications to thefirmware. The PIC16F72 is a popular low cost generalpurpose microcontroller from Microchip, that can beused to implement the control algorithm. To a greatextent, PIC18FXX31 devices can provide flexibility inimplementing motor control algorithms.

APPENDIX A: SOURCE CODE

The complete source code is available for download asa single archive file from the Microchip corporate website at:

www.microchip.com

© 2005 Microchip Technology Inc. DS00967A-page 13

Page 14: an 00967A

AN967

APPENDIX B: SCHEMATICS

FIGURE B-1: PIC® INTERFACE AND POWER SUPPLY (SHEET 1 OF 2)

Po

we

r

Su

pp

ly

DC

+

R6

47

0K

, 0

.5W

+ C11

R9

15

KC

10

0.1

μF

VC

C

RT

CT

CO

M

VB

HO

VS

LO

IR2

15

3-D

IP8

DC

-R

10

0.0

C1

2

22

0 p

F

1 2 3 4

8 7 6 5

U3

D1

D2

1E

MU

06

1N

41

48

IRF

R4

20

A

3

1

2

C6

0.1

μF

R7

22

Q1

D3

1E

MU

06

TL

43

1-T

09

2D4

31

22

K7

R1

2

L1

56

0 μ

H,

0.5

A R8

11

K

+1

5V

+

10

0 μ

F, 25V

10

μF, 25V

C7

1C5

0.1

μF

U2

LM

34

0T

-5

.0V

INO

UT

COM 2

3

+ C8

+5

V

C9

0.1

μF

R11

10

0

4.7

μF, 25V

PIC

® I

nte

rfa

ce

PIC16F72

FR

EF

2

13CW

CC

W

+5

V

R5

2K

0.1

μF

S1

C2

4 3

1 2

+5

V

10

K

R1

R3

2K

+5

V

C1

0.1

μF

20 1

VD

D

MC

LR

RA

0

RA

1R

A2

RA

3

RA

4

RA

5

OS

C1

OS

C2

VS

S

VS

S

FR

EF

MO

TO

R

TE

MP

2 3 4 5 6 7 1989

10

C4

22

pF

20

MH

z

Y1

C3

22

pF

RC

7R

C6

RC

5

RC

4

RC

3

18

17

16

15

14

RC

2

RC

1

RC

0

13

12

11

PW

M5

PW

M4

PW

M3

PW

M2

PW

M1

PW

M0

RB

7

RB

6

RB

5

RB

4

RB

3R

B2

RB

0

RB

1

FA

ULTA

SW

1

28

27

26

25

24

23

22

21

SW

1

S2

4 3

1 210

K

+5

V

R2

R4

10

K

DS00967A-page 14 © 2005 Microchip Technology Inc.

Page 15: an 00967A

AN967

FIGURE B-2: POWER SECTIONS AND MOTOR CURRENT MEASUREMENT (SHEET 2 OF 2)

Mo

tor

Co

nn

ecto

r

+15V

M1

0.0

1 μ

F 270 V

AC

VB

3

VS

3

NC

VB

2

VS

2

NC

VB

1

VS

1

NC

V+

NC

DC

-

DC

-

DC

-

H1

H2

H3

L1

L2 L3

ITR

IP

VC

C

VS

S

PW

M1

U4

IRA

MS

10U

P60A

1 2 3 4 5 6 7 8 9 10

11

12

13

14

15

16

17

18

19 20

21

22

23

C13

10 μ

F16V

DC

+

PW

M3

PW

M5

PW

M0

PW

M2

PW

M4

M2

M3

C15

10 μ

F

10 μ

FC

16

16V

16V

TE

MP

R22

300

R23

4.3

K

R20

0.0

5R

/3W

DC

-

R16

1K

C18

33 p

F

C19

4.7

nF

R18

10K

R19

91K2 3

MC

P6002

4

+-

8

1

1K

R15

U5:A

+5V

C14

0.1

μF

IMO

TO

R

C17

33 p

F

R21

5K

56

+-R

17

MC

P5002

+5V

R13

2K

4

R14

1M

U5:B

FA

ULTA

7300

M2

M3

M1

1 2 3 4

J2

EA

RT

H

MA

IN

AU

X

PS

C

MO

TO

R

470 μ

F 250V

EA

RT

H12

3

J1

AC

IN

PU

T

R24

NT

C

F1

RV

1

C21

DC

+ C20

D5

DC

-

+

+ -

1

2

3

4A

C1

AC

2

© 2005 Microchip Technology Inc. DS00967A-page 15

Page 16: an 00967A

AN967

NOTES:

DS00967A-page 16 © 2005 Microchip Technology Inc.

Page 17: an 00967A

Note the following details of the code protection feature on Microchip devices:

• Microchip products meet the specification contained in their particular Microchip Data Sheet.

• 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 ourproducts. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such actsallow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.

Information contained in this publication regarding deviceapplications and the like is provided only for your convenienceand may be superseded by updates. It is your responsibility toensure that your application meets with your specifications.MICROCHIP MAKES NO REPRESENTATIONS OR WAR-RANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED,WRITTEN OR ORAL, STATUTORY OR OTHERWISE,RELATED TO THE INFORMATION, INCLUDING BUT NOTLIMITED TO ITS CONDITION, QUALITY, PERFORMANCE,MERCHANTABILITY OR FITNESS FOR PURPOSE.Microchip disclaims all liability arising from this information andits use. Use of Microchip’s products as critical components inlife support systems is not authorized except with expresswritten approval by Microchip. No licenses are conveyed,implicitly or otherwise, under any Microchip intellectual propertyrights.

© 2005 Microchip Technology Inc.

Trademarks

The Microchip name and logo, the Microchip logo, Accuron, dsPIC, KEELOQ, microID, MPLAB, PIC, PICmicro, PICSTART, PRO MATE, PowerSmart, rfPIC, and SmartShunt are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

AmpLab, FilterLab, Migratable Memory, MXDEV, MXLAB, PICMASTER, SEEVAL, SmartSensor and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A.

Analog-for-the-Digital Age, Application Maestro, dsPICDEM, dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR, FanSense, FlexROM, fuzzyLAB, In-Circuit Serial Programming, ICSP, ICEPIC, MPASM, MPLIB, MPLINK, MPSIM, PICkit, PICDEM, PICDEM.net, PICLAB, PICtail, PowerCal, PowerInfo, PowerMate, PowerTool, rfLAB, rfPICDEM, Select Mode, Smart Serial, SmartTel and Total Endurance are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.

All other trademarks mentioned herein are property of their respective companies.

© 2005, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved.

Printed on recycled paper.

DS00967A-page 17

Microchip received ISO/TS-16949:2002 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona and Mountain View, California in October 2003. The Company’s quality system processes and procedures are for its PICmicro® 8-bit MCUs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory and analog products. In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001:2000 certified.

Page 18: an 00967A

DS00967A-page 18 © 2005 Microchip Technology Inc.

AMERICASCorporate Office2355 West Chandler Blvd.Chandler, AZ 85224-6199Tel: 480-792-7200 Fax: 480-792-7277Technical Support: http://support.microchip.comWeb Address: www.microchip.com

AtlantaAlpharetta, GA Tel: 770-640-0034 Fax: 770-640-0307

BostonWestford, MA Tel: 978-692-3848 Fax: 978-692-3821

ChicagoItasca, IL Tel: 630-285-0071 Fax: 630-285-0075

DallasAddison, TX Tel: 972-818-7423 Fax: 972-818-2924

DetroitFarmington Hills, MI Tel: 248-538-2250Fax: 248-538-2260

KokomoKokomo, IN Tel: 765-864-8360Fax: 765-864-8387

Los AngelesMission Viejo, CA Tel: 949-462-9523 Fax: 949-462-9608

San JoseMountain View, CA Tel: 650-215-1444Fax: 650-961-0286

TorontoMississauga, Ontario, CanadaTel: 905-673-0699 Fax: 905-673-6509

ASIA/PACIFICAustralia - SydneyTel: 61-2-9868-6733 Fax: 61-2-9868-6755

China - BeijingTel: 86-10-8528-2100 Fax: 86-10-8528-2104

China - ChengduTel: 86-28-8676-6200 Fax: 86-28-8676-6599

China - FuzhouTel: 86-591-8750-3506 Fax: 86-591-8750-3521

China - Hong Kong SARTel: 852-2401-1200 Fax: 852-2401-3431

China - ShanghaiTel: 86-21-5407-5533 Fax: 86-21-5407-5066China - ShenyangTel: 86-24-2334-2829Fax: 86-24-2334-2393

China - ShenzhenTel: 86-755-8203-2660 Fax: 86-755-8203-1760

China - ShundeTel: 86-757-2839-5507 Fax: 86-757-2839-5571

China - QingdaoTel: 86-532-502-7355 Fax: 86-532-502-7205

ASIA/PACIFICIndia - BangaloreTel: 91-80-2229-0061 Fax: 91-80-2229-0062

India - New DelhiTel: 91-11-5160-8631Fax: 91-11-5160-8632

Japan - KanagawaTel: 81-45-471- 6166 Fax: 81-45-471-6122

Korea - SeoulTel: 82-2-554-7200 Fax: 82-2-558-5932 or 82-2-558-5934

SingaporeTel: 65-6334-8870 Fax: 65-6334-8850

Taiwan - KaohsiungTel: 886-7-536-4818Fax: 886-7-536-4803

Taiwan - TaipeiTel: 886-2-2500-6610 Fax: 886-2-2508-0102

Taiwan - HsinchuTel: 886-3-572-9526Fax: 886-3-572-6459

EUROPEAustria - WeisTel: 43-7242-2244-399Fax: 43-7242-2244-393Denmark - BallerupTel: 45-4450-2828 Fax: 45-4485-2829

France - MassyTel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79

Germany - IsmaningTel: 49-89-627-144-0 Fax: 49-89-627-144-44

Italy - Milan Tel: 39-0331-742611 Fax: 39-0331-466781

Netherlands - DrunenTel: 31-416-690399 Fax: 31-416-690340

England - BerkshireTel: 44-118-921-5869Fax: 44-118-921-5820

Worldwide Sales and Service

10/20/04