The current sensing driver is a set of functions included in ST10 electric motor control library
(EMCL) (see Figure 1) useful to process the measurements of current in electric motor
control. This document explains how to use two ADC channels to sample the currents on 2
shunt resistors at specific instants. In particular on one shunt resistor the current is
measured as instantaneous value and on the other shunt resistor as average value.
A brief overview on current sensing strategy is given in section Chapter 1.1.
Figure 1.ST10 EMCL structure
ST10 EMCL
Flux
Oriented
Control
Sinusoidal
Control
Observer
Leunberger
SPI
Driver
Encoder
Driver
Hall sensors
current_sensing.c
current_sensing.h
1.1 Overview on current sensing strategy
The flux oriented control (FOC) is based on a current controlled voltage source inverter
(VSI) structure to generate a desired voltage space vector that the inverter applies to the
motor phases by means of the measurement of the electric motor phase currents (see
Figure 2) and a continuous modulation method (modulation period T) .
Figure 2.Block diagram of the flux oriented control scheme
Driver
Current sensing
Driver
PWM
Driver
5/13
Functions set overviewAN2501
The transformations from a stator frame to a rotor frame that are the core of FOC need the
sampling of three phase currents in the modulation period T. The sampling can be reduced
to only two phase currents if the motor windings are star-connected.
In this case the acquisition of two current signals can be done with two different A/D
converters or using only one A/D converter multiplexed on two (or more) channels, a
solution less expensive than the first one where the acquisitions are sequential.
Independently from the used current sensor, this second choice introduces some
measurement errors. In order to reduce these errors, one conversion is done at the time 0
(or T/2) where the contribution of harmonic current components is minimum, while the
second current is calculated as average value sampling in two different instants [(0 ±δ) or
(T/2 ±δ)] centred compared with the acquisition on the other phase (see Figure 3) with a gap
δ bigger than the conversion time of the A/D converter. In particular δ is chosen equal to T/2.
So only two measurements for modulation period are needed.
In this document the current sensing strategy with one ADC is described.
Figure 3.Measurement strategy
0 (T/2)
-
x
x
+
x
t
6/13
AN2501API specification
2 API specification
The following API allows easy access to the described current sensing strategy configuring
the ADC channels (c1 and c2) in Injection Mode to sample the motor currents from each
channel sequentially, reading and processing these values.
The use of these functions eliminates the need to access the ST10 registers directly.
see file current_sensing.c in the EMSW_CS Library.
2.1 Synchronization of signals
The sampling of the ADC is synchronized with the PWM. The CAPCOM timer T7 is
synchronized with the PWM semiperiod (i.e. PWM timer and CAPCOM T7 are started in the
same instant with consecutive instructions) so that the Injection Request bit for ADC is set
by CAPCPOM channel CC31 in the instants 0 (channel c1 acquisition) and T/2 (channel c2
acquisition). The current on channel c2 is calculated as average value of the present value
and the value sampled in the previous period.
This means that the current values are available for the control only in the 2nd semiperiod of
the PWM period. If a control function is registered, this function will be performed at each
mid point of the PWM period (t = T/2), i.e. at each end of conversion for the channel c2.
Control Function performing if registered.
Figure 4.Current sensing timing
PWM counter
t
T
m
INT_PWM
A
DC end of conversion interrupt (t = 0) (channel c1)
T7 interrupt to start ADC conversion (hardware)
pw
T
7
ADC end of conversion interrupt (t = T/2) (channel c2)
Control Function performing if registered
T
pwm
t
t
7/13
API specificationAN2501
2.2 Functions definition
In the following the functions for configuring two ADC channels in Injection Mode, to read
and to process the results of ADC conversions so as to implement the currents sensing
strategy with one ADC are described.
2.2.1 Current_sensing_Init
Prototype definition:
void Current_sensing_Init(CS_UINT16 sPeriod)
Parameters:
Table 1.Current_sensing_Init parameters
Configuration ParametersDescription
c1channel number (0, ..., 9)
c2channel number (0, ..., 9)
Global Parameters
csValuevariable to store current value (0)
csValue_tempstatic variable to store current value (T/2)
csFunction pointer to the control algorithm function
Function Parameters
sPeriod sampling period (number of mcu clock tics)
Description:
The Current_sensing_Init function is used to configure two ADC channels (c1 and c2) in
Injection Mode and to convert a specific analog channel triggered via software at every
compare event of compare register CC31 on Timer 7, which sets Injection Request bit
(ADCRQ), synchronizing the sampling of the motor currents with PWM period.
It is needed to set the two ADC channels (0...9) connected to the current sensors by means
of parameters (c1 and c2) inside the function.
8/13
AN2501API specification
2.2.2 Current_sensing_Start
Prototype definition:
void Current_sensing_Start(void)
Parameters:
Table 2.Current_sensing_Start parameters
Configuration ParametersDescription
c1channel number (0, ..., 9)
c2channel number (0, ..., 9)
Global Parameters
csValuevariable to store current value (0)
csValue_tempstatic variable to store current value (T/2)
csFunction pointer to the control algorithm function
Function Parameters
none
Description:
The Current_sensing_Start function is used to start the Timer 7 and the current sensing by
interrupt.
csValue_tempstatic variable to store current value (T/2)
csFunction pointer to the control algorithm function
Function Parameters
none
Description:
The Current_sensing_Register function is used to point to the control algorithm function. It is
needed to declare in the main a user function with the algorithm control and register it so
that the algorithm can be executed at every end of conversion on channel c2.
10/13
AN2501API specification
2.3 Resource
For the use of Current sensing Driver the needed resources are:
ADC (2 channels)ADC
Compare Timer (Timer 7)CAPCOM Timer
Compare register (CC31)CAPCOM register
Bank register (RB08)ADC Interrupt Service Routine
11/13
Revision historyAN2501
3 Revision history
Table 4.Document revision history
DateRevisionChanges
12-Mar-20071Initial release.
12/13
AN2501
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.