Freescale Speed Controller Application Note
Speed Controller is a component that allows you to control the speed of a motor. It works by taking a desired speed value and calculating the necessary voltage to apply to the motor to achieve that speed. Designed for use with devices that have the eTPU, such as the MCF523x, MPC5500, and MPC5600 families.
Advertisement
Advertisement
Freescale Semiconductor
Application Note
AN2843
Rev. 2, 02/2012
Using the Speed Controller (SC) eTPU Function
Covers the MCF523x, MPC5500, MPC5600 and all eTPU-equipped devices
by: Milan Brejl, Michal Princ
System Application Engineers, Roznov Czech System Center
Andrey Butok
System Application Engineer, Kiev Embedded Software Lab
1 Introduction
The Speed Controller (SC) Enhanced Time Processor
Unit (eTPU) function is one of the functions in the motor-control set of the eTPU functions (set3 and set4).
This application note is intended to provide simple C interface routines to the SC eTPU function. The routines are targeted at the MCF523x, MPC5500, and MPC5600 families of devices, but they can easily be used with any device that has an eTPU.
Table of Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Function Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
3 Function Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
4 C Level API for Function . . . . . . . . . . . . . . . . . . . . . . . . . 4
Initialization Function . . . . . . . . . . . . . . . . . . . . . . . . 6
Change Operation Functions. . . . . . . . . . . . . . . . . . 8
Value Return Function. . . . . . . . . . . . . . . . . . . . . . 11
5 Summary and Conclusions . . . . . . . . . . . . . . . . . . . . . . 12
6 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2 Function Overview
The SC function is not intended to process an input or output signal. The purpose of the SC function is to control another eTPU function’s input parameter. The SC function includes a general controller algorithm. The controller calculates its output based on two inputs: a measured value and a desired value. The measured value
—the actual motor speed—is calculated based on inputs provided by the HD, QD or RSLV function. The desired
© Freescale Semiconductor, Inc., 2004, 2005, 2012. All rights reserved.
2
Function Description
value is an output of a speed ramp, whose input is a SC function parameter, and can be provided by the
CPU or another eTPU function. In the motor-control eTPU function set, this function mostly provides the speed outer-loop.
Omega_actual
SC
Applied_voltage
PI Controller
Omega_actual
Omega_ramp
Scaling_factor period
Revolution_period
Sector_period
Ramp
Omega_desired
Requested_value
Time
Figure 1. Functionality of SC
The controller algorithm is a general Proportional-Integral-Derivative (PID) algorithm. It can be configured as the following:
• P controller
• PI controller
• PD controller
• PID controller
3 Function Description
The SC performs the calculation of the actual angular motor speed. If the Quadrature Decoder (QD) function is used to capture the shaft encoder signals, the speed controller periodically reads the QD parameters “Position Counter” and “TCR Value of The Last Transition,” and uses them to calculate the actual speed. If the Hall Decoder (HD) function is used to capture the Hall sensor signals, the speed controller periodically reads one of the HD parameters, either the “Revolution Period” or “Commutation
Period,” and uses it to calculate the actual speed. If the Resolver (RSLV) function is used to calculate rotor position, the speed is read from the Resolver internal Angle Tracking Observer algorithm.
The desired input is optionally passed through a ramp, in order to refine the step changes towards the desired value. The ramp performs a linear Ramp Generation algorithm (see Figure 2 ). If the desired_value is greater than the actual_value, the ramp output steps up by ramp_increment_up until the desired_value is reached, at which point the desired_value is returned. And vice versa: if the desired_value is less than
actual_value, the ramp output steps down by ramp_increment_down until the desired_value is reached.
Using the Speed Controller (SC) eTPU Function, Rev. 2
Freescale Semiconductor
Direction Down
Function Description
Actual_value
Direction Up
Desired_value
Actual_value
Desired_value
Time
Figure 2. Ramp Generation Algorithm
Time
The controller algorithm included in the SC function calculates the output according to the following equations:
Where:
u(k) = u
P
(k) + u
I
(k) + u
D
(k) e(k) = w(k) – m(k) u
P
(k) = G
P
*e(k) u
I
(k) = u
I
(k-1) + G
I u
D
(k) = G
D
*e(k)
*(e(k) - e(k-1)) u(k)
– PID algorithm output (the output of SC) in step k.
u
P
(k) – Proportional portion in step k.
u
I
(k) – Integral portion in step k.
u
D
(k) – Derivative portion in step k.
e(k) – Input error in step k.
w(k) – Desired value in step k.
m(k)
– Measured value in step k.
G
P
G
I
– Proportional gain.
– Integral gain.
G
D
– Derivative gain.
During SC initialization, a user can set what portion will be calculated and included in the controller output.
The gains are applied with 16-bit precision. The measured and desired values are applied with 24-bit precision. The Integral portion is stored with 14-bit precision.
Like most of the motor-control eTPU functions, the SC function also supports checking the eTPU latencies using an oscilloscope. The SC function channel, if connected to an output pin, turns the output pin high and low, so that the high-time identifies the period of time in which the SC update is executed.
Freescale Semiconductor
Using the Speed Controller (SC) eTPU Function, Rev. 2
3
C Level API for Function
4 eTPU or CPU
Request eTPU or CPU
Request
Slave Mode
Start Offset Period Period
Master Mode
Figure 3. Master Mode and Slave Mode Illustration
The SC function update, in which the actual desired value and the measured value are taken and the control signal is adjusted, can be executed periodically, or by another process:
• Master Mode
The SC update is executed periodically with a given period.
• Slave Mode
The SC update is executed by the Analog Sensing (ASDC or ASAC) eTPU function, other eTPU function, or by the CPU.
4 C Level API for Function
The following routines provide easy access to the SC function for the application developer. Use of these functions eliminate the need to directly control the eTPU registers. There are 13 functions added to the application programming interface (API). The routines can be found in the etpu_sc.h and etpu_sc.c
files, which should be included in the link file along with the top level development file(s).
These routines will be described in order and are listed below:
• Initialization Function: int32_t fs_etpu_sc_init( uint8_t channel,
uint8_t priority,
uint8_t mode,
uint8_t decoder_type,
uint8_t configuration,
uint24_t period,
uint24_t start_offset,
uint24_t services_per_irq,
sc_pid_params_t* p_pid_params,
sc_ramp_params_t* p_ramp_params,
uint8_t HD_QD_RSLV_chan,
uint8_t output_chan,
uint16_t output_offset,
uint8_t link_chan,
uint24_t omega_max_rpm,
uint24_t omega_min_rpm,
Using the Speed Controller (SC) eTPU Function, Rev. 2
Freescale Semiconductor
C Level API for Function
uint8_t pole_pairs,
uint32_t HD_QD_etpu_tcr_freq,
uint32_t rslv_freq,
uint24_t qd_pc_per_rev )
• Change Operation Functions: int32_t fs_etpu_sc_update(uint8_t channel) int32_t fs_etpu_sc_set_configuration(uint8_t channel,
uint8_t configuration) int32_t fs_etpu_sc_set_pid_params(uint8_t channel,
s_pid_params_t* p_pid_params) int32_t fs_etpu_sc_set_ramp_params(uint8_t channel,
s_ramp_params_t* p_ramp_params) int32_t fs_etpu_sc_set_omega_desired(uint8_t channel,
fract24_t omega_desired) int32_t fs_etpu_sc_reset_integral_portion(uint8_t channel)
• Value Return Functions: fract24_t fs_etpu_sc_get_omega_actual( uint8_t channel) uint8_t fs_etpu_sc_get_saturation_flag(uint8_t channel) fract24_t fs_etpu_sc_get_ramp_output(uint8_t channel) fract24_t fs_etpu_sc_get_output(uint8_t channel) fract24_t fs_etpu_sc_get_error(uint8_t channel) fract24_t fs_etpu_sc_get_integral_portion(uint8_t channel)
4.1
Initialization Function
4.1.1
int32_t fs_etpu_sc_init(...)
This routine is used to initialize the eTPU channel for the SC function. This function has the following parameters:
• channel (uint8_t) - This is the SC channel number. This parameter should be assigned a value of
0-31 forETPU_A, and 64-95 for ETPU_B.
• priority (uint8_t) - This is the priority to assign to the SC function. This parameter should be assigned a value of:
— FS_ETPU_PRIORITY_HIGH
— FS_ETPU_PRIORITY_MIDDLE
— FS_ETPU_PRIORITY_LOW
— FS_ETPU_PRIORITY_DISABLED
• mode (uint8_t) -This is the function mode. This parameter should be assigned a value of:
— FS_ETPU_SC_MASTER
— FS_ETPU_SC_SLAVE
Freescale Semiconductor
Using the Speed Controller (SC) eTPU Function, Rev. 2
5
C Level API for Function
• decoder_type (uint8_t) – This is the type of decoder (HD, QD or RSLV). This parameter should be assigned a value of:
—
FS_ETPU_SC_QD
(Quadrature Decoder)
—
FS_ETPU_SC_HD_REV_PERIOD
(any Hall Decoder - Revolution period is measured)
—
FS_ETPU_SC_HD_SEC_PERIOD_1
(1-phase Hall Decoder - Sector period is measured)
—
FS_ETPU_SC_HD_SEC_PERIOD_2
(2-phase Hall Decoder - Sector period is measured)
—
FS_ETPU_SC_HD_SEC_PERIOD_3
(3-phase Hall Decoder - Sector period is measured)
—
FS_ETPU_SC_HD_SEC_PERIOD_4
(4-phase Hall Decoder - Sector period is measured)
—
FS_ETPU_SC_RSLV
(Resolver)
• configuration (uint8_t) – This is the required configuration of SC. This parameter should be assigned a value of:
—
FS_ETPU_SC_RAMP_OFF_PID_OFF
(Ramp algorithm is disabled, PID controller is disabled)
—
FS_ETPU_SC_RAMP_OFF_PID_ON
(Ramp algorithm is disabled, PID controller is enabled)
—
FS_ETPU_SC_RAMP_ON_PID_OFF
(Ramp algorithm is disabled, PID controller is disabled)
—
FS_ETPU_SC_RAMP_ON_PID_ON
(Ramp algorithm is enabled, PID controller is enabled)
• period (uint24_t) - This is the update period, as a number of TCR1 clocks. This parameter applies in master mode only (mode=FS_ETPU_SC_MASTER).
• start_offset (uint24_t) - This parameter is used to synchronize various eTPU functions that generate a signal. The first SC update starts start_offset TCR1 clocks after initialization. This parameter applies in master mode only (mode=FS_ETPU_SC_MASTER).
• services_per_irq (uint24_t) - This parameter defines the number of updates after which an interrupt service request is generated to the CPU. When set to 0, no interrupt service requests are generated.
• p_pid_params (s_pid_params_t*) – This is the pointer to a s_pid_params_t structure. The s_pid_params_t structure is defined in etpu_sc.h: typedef struct {
int32_t P_gain;
int32_t I_gain;
int32_t D_gain;
int32_t positive_limit;
int32_t negative_limit;
} s_pid_params_t;
Where:
• P_gain (int32_t) - This is the proportional gain and its value must be in the 9.15 format that means in the range of (-256, 256). To switch off proportional portion set this parameter to zero.
• I_gain (int32_t) - This is the Integral gain and its value must be in the 9.15 format that means in the range of (-256, 256). To switch off calculation of integral portion set this parameter to zero.
Using the Speed Controller (SC) eTPU Function, Rev. 2
6 Freescale Semiconductor
C Level API for Function
• D_gain (int32_t) - This is the derivative gain and its value must be in the 9.15 format that means in the range of (-256, 256). To switch off calculation of derivative portion set this parameter to zero.
• positive_limit (int32_t) - This is the positive output limit and its value must be in the 9.15 format that means in the range of (-256, 256).
• negative_limit (int32_t) - This is the negative output limit and its value must be in the 9.15 format that means in the range of (-256, 256).
• p_ramp_params (s_ramp_params_t*) – This is the pointer to a s_ramp_params_t structure.
The s_ramp_params_t structure is defined in etpu_sc.h: typedef struct {
fract24_t ramp_incr_up;
fract24_t ramp_incr_down;
} s_ramp_params_t;
Where:
• ramp_incr_up (fract24_t) - This is the step increment up, and its value must be in the range (0, 1).
• ramp_incr_down (fract24_t) - This is the step increment down, and its value must be in the range (0, 1).
• HD_QD_RSLV_chan (uint8_t) – This is the number of the channel the HD, QD or RSLV functions is assigned to. This parameter should be assigned a value of 0-31 for ETPU_A, and
64-95 for ETPU_B.
• output_chan (uint8_t) – SC writes the PID output to a recipient function input parameter. This is the recipient function channel number. This parameter should be assigned a value of 0-31 for
ETPU_A, and 64-95 for ETPU_B.
• output_offset (uint16_t) – SC writes the PID output to a recipient function input parameter. This is the recipient function parameter offset. Function parameter offsets are defined in etpu_<func>_auto.h file..
• link_chan (uint8_t) – This is the channel number of a channel which receives a link after SC updates output. If SC updates PWM duty-cycles it should be a PWMMDC channel. This parameter should be assigned a value of 0-31 for ETPU_A, and 64-95 for ETPU_B.
• omega_max_rpm (uint24_t) – This is the maximum possible motor speed in rpm.
• omega_min_rpm (uint24_t) – This is the minimum possible motor speed in rpm.
• pole_pairs (uint8_t) – This is the number of motor pole-pairs.
• HD_QD_etpu_tcr_freq (uint32_t) – This is the frequency of TCR clock used by the HD or QD channel, in Hz. If Resolver is used (decoder_type=FS_ETPU_SC_RSLV) this parameter value does not apply.
• rslv_freq (uint32_t) – If Resolver is used (decoder_type=FS_ETPU_SC_RSLV), this is the resolver update frequency in Hz.
Freescale Semiconductor
Using the Speed Controller (SC) eTPU Function, Rev. 2
7
8
C Level API for Function
• qd_pc_per_rev (uint24_t) – This is the number of QD position counter increments per revolution. This parameter applies only if quadrature decoder is used
(decoder_type=FS_ETPU_SC_QD).
4.2
Change Operation Functions
4.2.1
int32_t fs_etpu_sc_update(uint8_t channel)
This function executes the SC update. This function has the following parameter:
• channel (uint8_t) - This is the Speed Controller channel number. This parameter must be assigned the same value as was assigned to the channel parameter in the initialization routine. If there are more SCs running simultaneously on the eTPU(s), the channel parameter distinguishes which SC function is accessed.
4.2.2
int32_t fs_etpu_sc_set_configuration(uint8_t channel, uint8_t configuration)
This function changes the SC configuration. This function has the following parameters:
• channel (uint8_t) - This is the speed controller channel number. This parameter must be assigned the same value as was assigned to the channel parameter in the initialization routine. If there are more SCs running simultaneously on the eTPU(s), the channel parameter distinguishes which SC function is accessed.
• configuration (uint8_t) – This is the required configuration of SC. This parameter should be assigned a value of:
—
FS_ETPU_SC_RAMP_OFF_PID_OFF
(Ramp algorithm is disabled, PID controller is disabled)
—
FS_ETPU_SC_RAMP_OFF_PID_ON
(Ramp algorithm is disabled, PID controller is enabled)
—
FS_ETPU_SC_RAMP_ON_PID_OFF
(Ramp algorithm is disabled, PID controller is disabled)
—
FS_ETPU_SC_RAMP_ON_PID_ON
(Ramp algorithm is enabled, PID controller is enabled)
4.2.3
int32_t fs_etpu_sc_set_pid_params(uint8_t channel, s_pid_params_t* p_pid_params)
This function changes the PID parameter values. This function has the following parameters:
• channel (uint8_t) - This is the Speed Controller channel number. This parameter must be assigned the same value as was assigned to the channel parameter in the initialization routine. If there are more SCs running simultaneously on the eTPU(s), the channel parameter distinguishes which SC function is accessed.
• p_pid_params (s_pid_params_t*) - This is the pointer to the PID control structure. The s_pid_params_t structure is defined in etpu_sc.h.
Using the Speed Controller (SC) eTPU Function, Rev. 2
Freescale Semiconductor
C Level API for Function
4.2.4
int32_t fs_etpu_sc_set_ramp_params(uint8_t channel, s_ramp_params_t* p_ramp_params)
This function changes the RAMP parameter values. This function has the following parameters:
• channel (uint8_t) - This is the Speed Controller channel number. This parameter must be assigned the same value as was assigned to the channel parameter in the initialization routine. If there are more SCs running simultaneously on the eTPU(s), the channel parameter distinguishes which SC function is accessed.
• p_ramp_params (s_ramp_params_t*) - This is the pointer to the RAMP params structure. The s_ramp_params_t structure is defined in etpu_sc.h.
4.2.5
int32_t fs_etpu_sc_set_omega_desired(uint8_t channel, fract24_t omega_desired)
This function changes the desired value, as a portion of the maximum value. This function has the following parameters:
• channel (uint8_t) - This is the Speed Controller channel number. This parameter must be assigned the same value as was assigned to the channel parameter in the initialization routine. If there are more SCs running simultaneously on the eTPU(s), the channel parameter distinguishes which SC function is accessed.
• omega_desired (fract24_t) - Desired input value. The value must be in the range MIN24 to
MAX24. This value can be obtained by dividing the desired angular rotor speed in [rpm] by
omega_max_rpm, which was used in initialization. The sign determines the rotor direction.
4.2.6
int32_t fs_etpu_sc_reset_integral_portion(uint8_t channel)
This function sets the integral portion to zero. This function has the following parameters
• channel (uint8_t) - This is the Speed Controller channel number. This parameter must be assigned the same value as was assigned to the channel parameter in the initialization routine. If there are more SCs running simultaneously on the eTPU(s), the channel parameter distinguishes which SC function is accessed.
4.3
Value Return Function
4.3.1
fract24_t fs_etpu_sc_get_omega_actual( uint8_t channel)
This function gets the actual angular value, as a portion of the maximum value. This function has the following parameter:
• channel (uint8_t) - This is the Speed Controller channel number. This parameter must be assigned the same value as was assigned to the channel parameter in the initialization routine. If there are more SCs running simultaneously on the eTPU(s), the channel parameter distinguishes which SC function is accessed.
Using the Speed Controller (SC) eTPU Function, Rev. 2
Freescale Semiconductor 9
C Level API for Function
The value of the actual rotor speed is returned as a fract24_t in the range (-1, 1). The actual angular rotor speed, in [rpm], can be obtained by multiplying of the returned value by omega_max_rpm, which was used in initialization. The sign determines the rotor direction.
4.3.2
uint8_t fs_etpu_sc_get_saturation_flag( uint8_t channel)
This function returns the PID controller saturation flags. This function has the following parameter:
• channel (uint8_t) - This is the Speed Controller channel number. This parameter must be assigned the same value as was assigned to the channel parameter in the initialization routine. If there are more SCs running simultaneously on the eTPU(s), the channel parameter distinguishes which SC function is accessed.
The returned value can be one of the following:
— 0 for no flag
— 1 for positive saturation flag
— 2 for negative saturation flag
4.3.3
fract24_t fs_etpu_sc_get_ramp_output( uint8_t channel)
This function returns the RAMP output. This function has the following parameter:
• channel (uint8_t) - This is the Speed Controller channel number. This parameter must be assigned the same value as was assigned to the channel parameter in the initialization routine. If there are more SCs running simultaneously on the eTPU(s), the channel parameter distinguishes which SC function is accessed.
4.3.4
fract24_t fs_etpu_sc_get_output( uint8_t channel)
This function returns the PID controller output. This function has the following parameter:
• channel (uint8_t) - This is the Speed Controller channel number. This parameter must be assigned the same value as was assigned to the channel parameter in the initialization routine. If there are more SCs running simultaneously on the eTPU(s), the channel parameter distinguishes which SC function is accessed.
4.3.5
fract24_t fs_etpu_sc_get_error( uint8_t channel)
This function returns the PID controller error. This function has the following parameter:
• channel (uint8_t) - This is the Speed Controller channel number. This parameter must be assigned the same value as was assigned to the channel parameter in the initialization routine. If there are more SCs running simultaneously on the eTPU(s), the channel parameter distinguishes which SC function is accessed.
4.3.6
fract24_t fs_etpu_sc_get_integral_portion( uint8_t channel)
This function returns the PID controller integral portion. This function has the following parameter:
Using the Speed Controller (SC) eTPU Function, Rev. 2
10 Freescale Semiconductor
Summary and Conclusions
• channel (uint8_t) - This is the Speed Controller channel number. This parameter must be assigned the same value as was assigned to the channel parameter in the initialization routine. If there are more SCs running simultaneously on the eTPU(s), the channel parameter distinguishes which SC function is accessed.
5 Summary and Conclusions
This application note provides the user with a description of the speed controller (SC) eTPU function. The simple C interface routines to the SC eTPU function enable easy implementation of the SC in applications.
References:
1. “The Essential of Enhanced Time Processing Unit,” AN2353
2. “General C Functions for the eTPU,” AN2864
3. “Using the DC Motor Control eTPU Function Set (set3),” AN2958
4. “Using the AC Motor Control eTPU Function Set (set4),” AN2968
5. Enhanced Time Processing Unit Reference Manual, ETPURM
6. eTPU Graphical Configuration Tool, http://www.freescale.com/etpu, ETPUGCT
7. “3-Phase BLDC Motor Demo Application With Speed Closed Loop,” AN2892.
8. “Permanent Magnet Synchronous Motor Vector Control, Driven by eTPU on MPC5500,”
AN3206
6 Revision history
Table 1. Revision history
Revision number
2
Revision date
02 May 2012
Description of changes
Updated for support of motor drives with resolver position sensor.
Freescale Semiconductor
Using the Speed Controller (SC) eTPU Function, Rev. 2
11
How to Reach Us:
Home Page:
freescale.com
Web Support:
freescale.com/support
Information in this document is provided solely to enable system and software implementers to use Freescale products. There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits based on the information in this document.
Freescale reserves the right to make changes without further notice to any products herein. Freescale makes no warranty, representation, or guarantee regarding the suitability of its products for any particular purpose, nor does Freescale assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. “Typical” parameters that may be provided in Freescale data sheets and/or specifications can and do vary in different applications, and actual performance may vary over time. All operating parameters, including “typicals,” must be validated for each customer application by customer’s technical experts. Freescale does not convey any license under its patent rights nor the rights of others. Freescale sells products pursuant to standard terms and conditions of sale, which can be found at the following address: http://www.reg.net/v2/webservices/Freescale/Docs/TermsandConditions.htm
Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware,
Energy Efficient Solutions logo, Kinetis, mobileGT, PowerQUICC, Processor Expert,
QorIQ, Qorivva, StarCore, Symphony, and VortiQa are trademarks of Freescale
Semiconductor, Inc., Reg. U.S. Pat. & Tm. Off. Airfast, BeeKit, BeeStack, ColdFire+,
CoreNet, Flexis, MagniV, MXC, Platform in a Package, QorIQ Qonverge, QUICC
Engine, Ready Play, SafeAssure, SMARTMOS, TurboLink, Vybrid, and Xtrinsic are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners.
The Power Architecture and Power.org word marks and the Power and Power.org logos and related marks are trademarks and service marks licensed by Power.org.
© 2004, 2005, 2012 Freescale Semiconductor, Inc.
Document Number: AN2843
Rev. 2
02/2012
Download
Advertisement
Key features
PID controller algorithm
Ramp generation algorithm
Master and Slave mode operation
Can be used with HD, QD, or RSLV functions
C-level API for easy interaction
Frequently asked questions
The Speed Controller is used for regulating the speed of a motor based on a desired setpoint and feedback from a sensor measuring the actual motor speed. It ensures smooth, controlled motor operation.
The Speed Controller offers various controller configurations, including Proportional (P), Proportional-Integral (PI), Proportional-Derivative (PD), and Proportional-Integral-Derivative (PID) controllers.
The ramp generation algorithm allows for a gradual change in the desired motor speed. Instead of abruptly switching to the new setpoint, the ramp makes smooth transitions, minimizing unwanted motor behavior.