STMicroelectronics provides a library of electric motor control functions that can be used as
base blocks for motor control applications.
This application note describes the set of API to manage PWM signals to drive a 3-phase
electric motor with the desired voltage with ST10 microcontrollers.
The PWM driver is a set of functions included in ST10 Electric Motor Control Library (EMCL)
(see Figure 1) useful to generate six PWM signals to drive a 3-phase electric motor by
inverter in electric motor control applications. The document explains how to use and
configure ST10 peripherals in order to produce PWM signals with adjustable pulse width at
the beginning of each new PWM period.
Figure 1.ST10 EMCL structure
ST10 EMCL
Flux
Oriented
Contr o
Sinusoidal
l
Control
Observer
Leunberger
SPI
Driver
oEnc der
Driver
Hall sensors
Driver
Current sensing
Driver
pwm.c
pwm
PWM
Driver
.
h
5/13
PWM overviewAN2499
2 PWM overview
A power inverter is a d.c. to a.c. converter used to apply the desired voltage across the
motor phases. In particular for a 3-phase electric motor it is used an 3-phase full bridge
inverter with 6 switches, MOSFETs in low-voltage applications (i.e. automotive field). The
components of the inverter are impulsed, following a specific switching pattern, producing
the symmetric waveforms necessary to drive the motor (see Figure 2).
Figure 2.Inverter
U
phase
V
phase
W
phase
T
semiperiod
0
T
switching period
s
V
U
W
Phase U
Phase V
Phase W
T
0
T
T
0
s
To obtain the waveforms of Figure 2, it is used the ST10 PWM and XPWM Modules
channels configuring their pulse width (PW) registers with the values calculated by control
algorithm and updated at every PWM period. The upper and lower switches of the same leg
of inverter are driven with two complementary pulsed signals (see Figure 3) with a so called
dead-time to avoid shortcut.
Figure 3.Output waveforms
PPx
Phase U +
Phase U -
Phase V +
Phase V -
Phase W +
PU
PV
PW
T
0
t
Phase W -
6/13
AN2499API specification
3 API specification
The following API allows easy access to the set of functions to configure the PWM and
XPWM modules channels in Center Aligned Mode and to change the pulse width of each
signal simultaneously at every PWM period.
The use of these functions eliminates the need to access directly ST10 registers.
Available functions:
1. void PWM_Init(void);
2. void PWM_start(void);
3. void PWM_Register(PWMFUNCTION pwmfunction);
see file pwm.c in the EMSW_PWM Library.
7/13
API specificationAN2499
3.1 Functions definition
This section describes the functions used by the implemented control algorithm in order to:
–- configure the PWM and XPWM modules;
–- start the PWM and XPWM timers;
–- and change the pulse width of the output signals.
3.1.1 PWM_Init
Prototype definition:
void PWM_Init(void)
Table 1.PWM_Init Parameters:
Configuration ParametersDescription
none
Global Parameters
PU variable to store current PWM U phase value
PVvariable to store current PWM V phase value
PWvariable to store current PWM W phase value
pwmFunction pointer to the control algorithm function
Function Parameters
none
Description:
The PWM_Init function is used to initialize the Pulse Width Modulation (PWM) Module and
the XPWM Module selecting three channels for each module in Center Aligned Mode with
the default values of semi period (PP) and pulse width (PW) and enables interrupt from
PWM channel 0 at the beginning of each new PWM cycle.
PWMpin ( output )
channel 0P7.0
channel 1P7.1
channel 2P7.2
XPWM
channel 0P8.0
channel 1P8.1
channel 2P8.2
8/13
AN2499API specification
3.1.2 PWM_start
Prototype definition:
void PWM_start(void)
Table 2.PWM_start Parameters:
Configuration ParametersDescription
none
Global Parameters
PU variable to store current PWM U phase value
PVvariable to store current PWM V phase value
PWvariable to store current PWM W phase value
pwmFunction pointer to the control algorithm function
Function Parameters
none
Description:
The PWM_start function starts the PWM and XPWM timers simultaneously.
9/13
API specificationAN2499
3.1.3 PWM_Register
Prototype definition:
void PWM_Register(PWMFUNCTION pwmfunction)
Table 3.PWM_Register Parameters:
Configuration ParametersDescription
none
Global Parameters
PU variable to store current PWM U phase value
PVvariable to store current PWM V phase value
PWvariable to store current PWM W phase value
pwmFunction pointer to the control algorithm function
Function Parameters
none
Description:
The PWM_Register function points to the control algorithm function. It is needed to declare
in the main a user function with the algorithm control and to register it so that the algorithm
can be executed at every occurrence of PWM interrupt.
10/13
AN2499API specification
3.2 Resource
For the use of the library the needed resources are:
Table 4.Required library resources
3 PWM channelsPWM
3 XPWM channelsXPWM
1 Bank register (RB10)interrupt
11/13
Revision historyAN2499
4 Revision history
Table 5.Document revision history
DateRevisionChanges
29-Mar-20071Initial release.
12/13
AN2499
Please Read Carefully:
Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the
right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any
time, without notice.
All ST products are sold pursuant to ST’s terms and conditions of sale.
Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no
liability whatsoever relating to the choice, selection or use of the ST products and services described herein.
No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this
document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products
or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such
third party products or services or any intellectual property contained therein.
UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED
WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS
OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.
UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOT
RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING
APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY,
DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE
GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK.
Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void
any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any
liability of ST.
ST and the ST logo are trademarks or registered trademarks of ST in various countries.
Information in this document supersedes and replaces all information previously supplied.
The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.