FOC Position Interface Details
Motivation
Following PROFIdrive AC4 requirements, the FOC must provide to user with the position information of the encoder integrated into the motor.
Introduction
In the relevant FOC example, the motor using the quadrature encoder is currently supported. There, this documentation will only focus on quadrature encoder-based motors. The encoder mounted on the motor enables the implementation of Field-Oriented Control, so it is of vital importance. However, in addition to this function, this encoder also provides position information to the user. What we mean by user here is PROFIdrive AC4.
In short, the electrical signals obtained by the encoder are decoded by the MENC peripheral module and stored in the position register. This data is then converted into meaningful position data depending on the specifications of the relevant encoder.
Obtaining position data from the encoder
MENC encoder module details
You can find more detailed information about how the encoder and encoder module work on page 208 of the netX 90 - Technical data reference guide.
If we briefly talk about the encoder module, we see that it consists of certain basic components as shown in Figure 1. Some of them are encoder filter, quadrature decoder unit, encoder configuration register, capture unit, etc. The filter part is a typical debounce filter and filters parasitic impulses. The value we configure in our application is 1 μs. In other words, for the signal to be considered valid, the incoming encoder signal period must be at least 1μs. The encoder quadrature decoder unit processes incoming encoder signals. Different error and status situations that may occur during this process can be accessed from the Encoder status register (which contains IRQ support).
In short, the encoder’s electrical signals are interpreted by the Encoder quadrature decoder unit.
In short, the encoder’s electrical signals are interpreted by the Encoder quadrature decoder unit. As shown in Figure 2, the encoder module converts all rising and falling edges of the incoming A and B signals into edge impulses, the phase difference between A and B signals and which signal comes first determines the encoder direction.
The encoder pulse counter performs the counting of incoming edges depending on the current direction (CW - forward counting, CCW - backward counting). In other words, this counting process takes place on every rising and falling edge of the A and B signals (X4 - Counting will be done at every 90o phase angle between A and B). It can invert the incoming encoder direction using configuration registers. Phase error, overflow positive, and negative registers inform the user whether there is an error or not through the status register.
Encoder data interpretation
General information
The position information stored in the Encoder Position Register must be converted in order to be used meaningfully by PROFIdrive AC4. To achieve this, the user requires 3 types of information.
Fine resolution: It increases or decreases depending on the direction, triggered by each rising and falling edge of the A and B signals. Each 1-bit change represents the 90o electrical angle between the A and B signals.
Number of pulses: It is the number of pulses occurring in each revolution (360o) of the encoder.
Number of revolutions: It changes with each complete revolution of the encoder.
In fact, the position register in the MENC module is designed very cleverly. It is very close to the format used by PROFIdrive. In addition, since it uses the 32-bit position register size and stores the additional revolution data here, it will be easier to collect and process revolution data by the PLC.
As mentioned above, each encoder has a number of pulses. This value depends on the production of the encoder and is given to the application in the FOC user parameters.
Data interpretation
Interpreted position data can be seen in Figure 4. Due to the MENC structure, fine resolution is 2-bit (range 0-3). Number of pulses varies depending on the encoder integrated into each motor. The remaining bits on the MSB side are reserved for the number of revolutions.
Figure 5 shows the effect of electrical signals on the relevant counters during the rotation of the encoder in both directions.
PROFIdrive AC4 specific encoder position format
PROFIdrive essentially supports different position information devices. These are Resolvers, Multi-turn absolute encoders using interfaces such as Biss, EnDat, Quadrature, and SinCos incremental encoders, etc. Because so many different position information devices are supported, the PROFIdrive Encoder Position Format Structure is very flexible and can be adjusted with parameter 979.
The format in Figure 4 was used because it is very close to the format in PROFIdrive to simplify things and keep processing to a minimum on the FOC side. We must emphasize again that FOC currently only offers support for the quadrature encoder integrated into the motor. Since both motors we support have different encoder resolutions (number of lines), the position register in the MENC peripheral interface will be interpreted accordingly and will be masked and processed and given the PROFIdrive application. Figure 6 shows the interpretation of the encoder position registers for different motors.
FOC-specific encoder position
For the FOC to provide loose coupling, it must present the relevant position information independently of the application profile used. Therefore, it provides the user with the position information mentioned in the general information section.
The interface provided to the user can be seen in the code snippets below. We basically have two API functions; the first one is Get Encoder Position Information, and the other one is Get Encoder Position Format.
Get Encoder Position Format gives automatically calculated bit lengths depending on the resolution of the encoder integrated into the motor.
/**
* \brief Encoder position data
*/
typedef struct MCL_PSE_ENC_POS_Ttag
{
uint8_t bFineResolution; /** Fine resolution shows actual encoder quadrants. */
uint16_t usNumOfPulses; /** Number of pulses in one revolution. */
uint32_t ulNumOfRevolutions; /** Number of revolutions */
} MCL_PSE_ENC_POS_T;
/*! Get the encoder position information.
*
* It provides position information obtained and processed by the relevant
* peripheral modules.
*
* \param hFoc [in] - FOC handle.
* \param ptEncPos [out] - Pointer to encoder position structure.
*
* \return Hilscher Common error code definitions.
* \retval SUCCESS_HIL_OK Operation succeeded
* \retval ERR_HIL_INVALID_HANDLE Invalid handle.
* \retval ERR_HIL_INVALID_PARAMETER Invalid parameter.
*/
uint32_t
Foc_GetEncoderPos(FOC_H hFoc,
MCL_PSE_ENC_POS_T* const ptEncPos);
/**
* \brief Encoder position data format.
*/
typedef struct MCL_PSE_ENC_POS_FORMAT_Ttag
{
uint8_t bFineResBitLen; /** Fine resolution bit length. */
uint8_t bNumOfPulsesBitLen; /** Number of pulses bit length. */
uint8_t bNumOfRevoBitLen; /** Number of revolution bit length */
} MCL_PSE_ENC_POS_FORMAT_T;
/*! Get the encoder position format information.
*
* It gives automatically calculated bit lengths depending on the resolution of
* the encoder integrated into the motor.
*
* \note It is used to set the parameters of the relevant position interface.
*
* \param hFoc [in] - FOC handle.
* \param ptEncPosFormat [out] - Pointer to encoder position format structure.
*
* \return Hilscher Common error code definitions.
* \retval SUCCESS_HIL_OK Operation succeeded
* \retval ERR_HIL_INVALID_HANDLE Invalid handle.
* \retval ERR_HIL_INVALID_PARAMETER Invalid parameter.
*/
uint32_t
Foc_GetEncoderPosFormat(FOC_H hFoc,
MCL_PSE_ENC_POS_FORMAT_T* const ptEncPosFormat);
The format achieved after calculations for bot motors is shown in Figure 6. Additionally, range information is given separately for each position information in the table below.
Â
 | Fine Resolution | Number of Pulses | Number of Revolutions |
---|---|---|---|
Empapst ECI4220K1B100 | 0 - 3 | 0 - 255 | 0 - 4194303 |
Maxon ECI-30 | 0 - 3 | 0 - 1023 | 0 - 1048575 |
PROFIdrive AC4 P979 parameter details
The predicted p979 parameters are described in the table below.
Subindex | Bits | Value | Meaning |
---|---|---|---|
1 | 0 | 0 | Rotary Sensor |
1 | 1 | A fine resolution in Gx_XIST1 displays the absolute position within a signal period. The transferred value may be interpreted as an absolute value, because the fine resolutions are synchronous in every switch-on instant. | |
2 | 0 | No 64 Bit absolute information available. | |
2 | [31:0] | Maxon: 1024 Empapst: 256 | Number of pulses (=signal period) per revolution. Optional: Get Number of Lines bit length using the Get Encoder Format function, calculate the values and fill the register automatically. |
3 | [31:0] | 2 | Specifies how many bits defining the sum of quadrant information and fine resolution are displayed in Gx_XIST1 (value range: 0 to 32). Optional: Get Fine Resolution bit length using the Get Encoder Format function, calculate the values and fill the register automatically. |
5 | [31:0] | Empapst: 4194304 Maxon: 1048576 | Specifies which absolute position information may be delivered by the sensor. Optional: Get Number of Revolutions bit length using the Get Encoder Format function, calculate the values and fill the register automatically. |
Real position interpretations with the Angular(Pulse-Degree) transformations
We need angular information in order for this data obtained by PROFIdrive to perform position control on any actuator. With this angular information, the necessary transformations will be performed (e.g. Forward and Inverse Kinematics).
Degree per Pulse and Degree per Fine Resolution values can be calculated using the formulas below. Degree per Pulse is the calculated coefficient that indicates how many degrees a bit of Number of Pulse changes. Degree per Fine Resolution is the calculated coefficient that indicates how many degrees a bit of Fine Resolution changes. By using these coefficients, desired angular transformations can be realized.
In the table below, the relevant coefficient values of the motors used in FOC are calculated.
 | Number of pulses | Degree per pulses | Degree per fine resolution |
---|---|---|---|
Empapst ECI4220K1B100 | 256 | 1.40625o | 0.3515625o |
Maxon ECI-30 | 1024 | 0.3515625o | 0.087890625o |