DRM029, 3-Phase PM Synchronous Motor Control with Quadrature

DRM029, 3-Phase PM Synchronous Motor Control with Quadrature

Freescale Semiconductor, Inc.

Designer Reference Manual — 3-Ph PM SMC with Quadrature Encoder

Section 5. Software Design

5.1 Contents

5.2 Software Description

This section describes the design of the software blocks for the drive.

The software will be described in terms of:

• Control Algorithm Data Flow

• Software Implementation

5.3 Data Flow

5.2

Software Description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

5.3

Data Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

5.4

Software Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

5.5

Implementation Notes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

The control algorithm of a close loop PM Synchronous drive is described in

Figure 5-1

. The individual processes are described in the following

sections.

The main data flow can be divided to four parts:

• Speed control

• Velocity calculation

• 3-phase sinewave generation

• DC-Bus voltage measurement

DRM029 — Rev 0

MOTOROLA Software Design

For More Information On This Product,

Go to: www.freescale.com

Designer Reference Manual

41

Software Design

Freescale Semiconductor, Inc.

Speed control starts with the required speed omega_required_mech.

This variable is set by user buttons or remotely by the PC within allowed limits. The variable omega_required_mech is copied to omega_desired_mech

at a defined moment. This variable is used as a shadow variable to avoid change of the required speed from the PC at any time. The variable omega_desired_mech is input to the speed PI controller as a reference value.

MeasuredTime

incorporates a time period of one phase of the

Quadrature Encoder. The time period is used for speed calculation.

Calculated speed, omega_actual_mech, is input to the speed PI controller as a secondary input. The PI controller output determines the amplitude of the generated sinusoidal output signals.

For the rotor position scanning the Timer A0, set as a quadrature counter, is used. The Timer A0 gives the actual rotor position shifted by

90 electrical degrees after initialization. This rotor position

RotorPosition

is input to the 3-phase sinewave modulation together with required amplitude Amplitude. The result of the sinewave modulation is written directly to the PWM block. The rotor position scanning with sinewave modulation is performed by an interrupt routine, which is called each PWM reload (16 kHz). The next task, which is provided by an interrupt routine, is the calculation of the spin direction.

The result, DirectionSpinning, is used for the speed calculation.

The variable u_dc_bus contains the actual DC-Bus voltage. The value is used for an under-voltage detection.

Designer Reference Manual

42 Software Design

For More Information On This Product,

Go to: www.freescale.com

DRM029 — Rev 0

MOTOROLA

SPEED

SETTING by BUTTONS

omega_required_mech

Process

SCI

omega_desired_mech

Freescale Semiconductor, Inc.

Speed Controller

(PI Controller)

Software Design

Data Flow

SCI

.

Communication

POSITION SENSOR

(Quadrature Decoder)

Period

Measuring

MeasuredTime

Velocity

Calculation

omega_actual_mech

Read Latest

Position

DirectionSpinning RotorPosition

Amplitude

3-Phase Sinewave

Generation

Software Block

PWM GENERATION

Hardware Block

Figure 5-1. Main Data Flow

DC-Bus Voltage

(A/D Converter)

u_dc_bus

5.3.1 Read Latest Position

The process Read Latest Position is executed with each PWM Reload interrupt (16 kHz). The process reads the actual rotor position and calculates the direction of spinning.

DRM029 — Rev 0

MOTOROLA Software Design

For More Information On This Product,

Go to: www.freescale.com

Designer Reference Manual

43

Freescale Semiconductor, Inc.

Software Design

5.3.2 Period Measuring and Velocity Calculation

The processes, Period Measuring and Velocity Calculation, read the time between the adjacent edges of one phase of the Quadrature

Encoder and calculates the actual motor speed omega_actual_mech.

5.3.3 Speed Controller

This process compares the required and actual speed and calculates the duty cycle of the PWM output signals. For detailed information see

Section 2.3.4, Speed Control

5.3.4 3-phase Sinewave generation

The process 3-phase Sinewave Generation calculates the PWM output from the actual rotor position and the required sinewave amplitude. The output is written to the PWM module. This process is performed within the PWM Reload interrupt.

5.4 Software Implementation

The general software diagram shows the Main routine entered from

Reset and the interrupt states (see

Figure 5-2

).

The Main routine initializes both the DSP and the application, then enters into an infinite background loop. This loop contains an application

State Machine.

The following interrupt service routines are utilized:

• PWM Reload ISR- services signals generated by the Quadrature

Encoder and generates the 3-phase sinewave output

• Input Capture ISR (TimerA1) - services period measurement for speed calculation

• Timer ISR - services the speed controller and LED diode blinking

• Push Button Up ISR and Push Button Down ISR - service the Up and Down push buttons

Designer Reference Manual

44

DRM029 — Rev 0

MOTOROLA Software Design

For More Information On This Product,

Go to: www.freescale.com

Freescale Semiconductor, Inc.

Software Design

Software Implementation

• SCI ISR - services communication with the PC master software

Reset

Initialization

Interrupts

Main loop

(State Machine)

Figure 5-2. State Diagram - General Overview

5.4.1 Initialization

DRM029 — Rev 0

MOTOROLA

The Main Routine provides initialization of the DSP:

• Disables Interrupts

• Initializes DSP PLL

• Disables COP and LVI

• Initializes the Timer for time base reference 1 ms

• Initializes the LED

• Initializes the PWM module:

– Center-aligned complementary PWM mode, positive polarity

– PWM modulus - defines PWM frequency

– PWM deadtime - defines PWM deadtime

– Disable faults

• Initializes Quadrature Decoder

– Sets on-chip digital filter of the Quadrature Decoder inputs

Software Design

For More Information On This Product,

Go to: www.freescale.com

Designer Reference Manual

45

Software Design

Freescale Semiconductor, Inc.

– Connects Quadrature Decoder signals to QuadTimerA

• Initializes QuadTimerA - channel A0

– set Count Mode to Quadrature Count

– set Input Source to Input 0

– set Input Polarity to Normal

– set Secondary Input Source to Input 1

– set Count Frequency to Repeatedly

– set Count Length to Until Compare

– set Count Direction to Down

– disable Capture Mode

• Initializes QuadTimerA - channel A1

– set Count Mode to Count

– set Input Source to Bus Clock / 128

– set Input Polarity to Normal

– set Secondary Input Source to Input 1

– set Count Frequency to Repeatedly

– set Count Length to Past Compare

– set Count Direction to Up

– set Capture Mode = RisingEdges

– associate Callback On Input Edge to CallbackOnNewEdge

– associate CallbackOnOverflow to CallbackOnOverload

• Sets-up I/O ports (brake, switch, push buttons)

– Brake, LED, switch on GPIO

– Push buttons on interrupts IRQ0, IRQ1

• Initializes the Analog-to-Digital Converter

– ADC set for sequential sampling, single conversion

– Channel 0 = DC-Bus voltage

Designer Reference Manual

46 Software Design

For More Information On This Product,

Go to: www.freescale.com

DRM029 — Rev 0

MOTOROLA

Freescale Semiconductor, Inc.

Software Design

Software Implementation

• Initializes control algorithm (speed controller, control algorithm parameters)

• Enables interrupts

• Starts ADC conversion

5.4.2 Interrupts

The interrupt handlers have the following functions:

PWM Reload reads the actual rotor position, calculates the

3-phase sinewave output and spin direction and updates PWM

Value Registers.

Input Capture Interrupt Handler (Timer A1) reads the time between the two subsequent IC edges one phase of the

Quadrature Encoder, which is used for speed calculation.

Timer Interrupt Handler generates the time base 1ms. The routine, called within this time base, blinks the green LED diode, reads the result of the ADC conversion, calculates the speed and provides the speed controller.

Push Button Interrupt Handler takes care of the push button service. The UpButton Interrupt Handler increments the desired speed, the DownButton Interrupt Handler decrements the desired speed.

PC and SCI Interrupt Handlers provide SCI communication and service routines for the PC master software. These routines are fully independent of the motor control tasks.

5.4.3 Drive State Machine

The drive can be in any of the states shown in

Figure 5-3

, which shows

the transition conditions between the drive states. The user is able to recognize the current state, by a blinking green LED diode. In the case of the init and stop state, the green LED diode blinks at a frequency of

2 Hz. In the fault state, the green LED diode blinks at a frequency of

DRM029 — Rev 0

MOTOROLA Software Design

For More Information On This Product,

Go to: www.freescale.com

Designer Reference Manual

47

Freescale Semiconductor, Inc.

Software Design

8 Hz. During the running state, the green LED diode is continuously turned on.

SwitchState=RUN

Reset

Init

State

u_dc_bus>=MIN_DC_BUS_VOLTAGE

SwitchState=STOP u_dc_bus<MIN_DC_BUS_VOLTAGE

Fault

State

Stopped

State

SwitchState=STOP

SwitchState=RUN

Running

State

Figure 5-3. Drive State Machine Transitions

5.5 Implementation Notes

The following chapter describes calculation of application constans and quantity scaling.

5.5.1 Scaling of Quantities

The PM Synchronous motor control application uses a fractional representation for all real quantities except time. The N-bit signed

Designer Reference Manual

48 Software Design

For More Information On This Product,

Go to: www.freescale.com

DRM029 — Rev 0

MOTOROLA

Freescale Semiconductor, Inc.

Software Design

Implementation Notes fractional format is represented using 1.[N-1] format (1 sign bit, N-1 fractional bits). Signed fractional numbers (SF) lie in the following range:

– 1.0

≤ ≤

[ ]

(EQ 5-1.)

For words and long-word signed fractions, the most negative number that can be represented is -1.0, whose internal representation is $8000 and $80000000, respectively. The most positive word is $7FFF or 1.0 -

2

-15

, and the most positive long-word is $7FFFFFFF or 1.0 - 2

-31

.

The following equation shows the relationship between real and fractional representations:

Fractional Value =

Real Quantity Range

(EQ 5-2.)

where:

Fractional Value is a fractional representation of the real value [Frac16]

Real Value is the real value of the quantity [V, A, RPM, etc.]

Real Quantity Range is the maximum range of the quantity, defined in the application [V, A, RPM, etc.]

5.5.1.1 DC-Bus Voltage Scaling

The DC-Bus voltage sense is defined by the following equation: u_dc_bus =

VMAX

Where:

u_dc_bus = variable of DC-Bus voltage

V

DC_BUS

= measured DC-Bus voltage

V

MAX

= max. measurable DC-Bus voltage.

NOTE:

V

MAX

= 16V for the EVM Motor Board

DRM029 — Rev 0

MOTOROLA Software Design

For More Information On This Product,

Go to: www.freescale.com

Designer Reference Manual

49

Freescale Semiconductor, Inc.

Software Design

5.5.1.2 PI Controller Parameters

The P constant was chosen as 0.2 (26214 * 2

-17

) and the I constant was chosen as 0.3 (31457 * 2

-20

) or 0.12 (31457 * 2

-18

). To get better response to error speed, the I constant is changed according the actual speed. The I constant equals 0.3 from 50 to 200 RPM. Over 200 RPM the I constant equals 0.12. The controller parameters were experimentally tuned.

5.5.1.3 Velocity Calculation

The constant OMEGA_ACTUAL_MECH_CONST is defined by the following equations: position difference = 1/500 rev (given by each rising edge of one phase of Quadrature Encoder and two pole pairs motor) max. period time = 0.008 s (chosen according to required min. speed) v min

= 60*(position difference)/(max. period time) = 15 RPM v max

= 100*v min

= 1500 RPM (chosen according to required max. speed)

OMEGA_ACTUAL_MECH_CONST

= 32767*v min

/v max

= 327

5.5.2 Motor Constant Calculation

The PM Synchronous motor control application uses the constants, which depend on a motor type (number of pole pairs) and on a

Quadrature Encoder type (number of pulses per revolution). The depended constants are:

• PULSES_PER_REVOLUTION

• VOLTAGE_SHIFT

• SIN_TABLE_MULTIPLIER

The following paragraphs explain the constant calculations. The range for all constants is unsigned integer.

Designer Reference Manual

50 Software Design

For More Information On This Product,

Go to: www.freescale.com

DRM029 — Rev 0

MOTOROLA

Freescale Semiconductor, Inc.

Software Design

Implementation Notes

5.5.2.1 Constant PULSES_PER_REVOLUTION

The constant PULSES_PER_REVOLUTION defines the number of pulses of the Quadrature Encoder per electrical revolution. Since the

Quadrature Encoder counts both rising and falling edges, the value is multiplied by four. The resultant value must be an integer.

PULSES_PER_REVOLUTION

= number of pole pairs

(EQ 5-3.)

In the case of presented application the constant is equal:

PULSES_PER_REVOLUTION

=

4 500

2

– = 999

NOTE:

In case that the constant is not an integer, it is necessary to set the constant PULSES_PER_REVOLUTION to a value which is equal to the number of pulses per mechanical revolution minus one. Then the actual rotor position has to be recalculated from the mechanical to electrical revolution.

5.5.2.2 Constant VOLTAGE_SHIFT

The constant VOLTAGE_SHIFT defines the shift of applied voltage by 90 el. degree and is calculated as:

VOLTAGE_SHIFT

=

(

PULSES_PER_REVOLUTION

4

+ 1

)

Then for the presented application the constant is equal to:

(EQ 5-4.)

VOLTAGE_SHIFT

=

(

999 1

4

)

= 250

DRM029 — Rev 0

MOTOROLA Software Design

For More Information On This Product,

Go to: www.freescale.com

Designer Reference Manual

51

Freescale Semiconductor, Inc.

Software Design

5.5.2.3 Constant SIN_TABLE_MULTIPLIER

The constant SIN_TABLE_MULTIPLIER rescales the rotor position, which is defined in pulses per electrical revolution, to the sinewave table, which is scaled from -1 to 1 <-

π; π).The constant is calculated as:

SIN_TABLE_MUTIPLIER

=

PULSES_PER_REVOLUTION

For the presented calculation can be calculated:

SIN_TABLE_MUTIPLIER

=

65535

999

× = 16794

(EQ 5-5.)

Designer Reference Manual

52 Software Design

For More Information On This Product,

Go to: www.freescale.com

DRM029 — Rev 0

MOTOROLA

Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project