Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
084135b
initial commit
anirudhupadhyaya Jan 20, 2024
d2652bf
Add content
anirudhupadhyaya Jun 6, 2024
1f1b8a0
Update docs
anirudhupadhyaya Jun 19, 2024
d81c691
Update doc
anirudhupadhyaya Jun 24, 2024
e0fbf68
Update docs
anirudhupadhyaya Jun 26, 2024
cbc72d1
Update docs
anirudhupadhyaya Jun 26, 2024
655f2b1
Update doc
anirudhupadhyaya Jun 28, 2024
cbd2100
Update block diagram
anirudhupadhyaya Jun 30, 2024
d971d20
Apply suggestions from code review
anirudhupadhyaya Jun 30, 2024
63600c6
Update doc to address review comments
anirudhupadhyaya Jun 30, 2024
3a1ca7b
Add line on low pass filter
anirudhupadhyaya Jun 30, 2024
04c3490
Update source/getting-started/control-with-amdc/encoder-fb/index.md
anirudhupadhyaya Jul 1, 2024
7bdd0aa
Edit background
elsevers Nov 2, 2024
c249ab3
Fix file name type-o
elsevers Nov 2, 2024
52556e6
Fix type-os
elsevers Nov 2, 2024
5ac7ce6
Add config instructions
elsevers Nov 2, 2024
1532f0a
Edit first 1/3 of document
elsevers Nov 3, 2024
5b5a78b
add simulink model of pll
elsevers Dec 10, 2024
1086a13
Add pll test files
noguchi-takahiro Dec 12, 2024
93cf84e
Change indexme file
Daehoon-Sung Jun 6, 2025
eab8281
Update index.md
Daehoon-Sung Jun 6, 2025
196297a
Edit finding offset and step 1
elsevers Jun 7, 2025
b27375c
Edit finding the offset section
elsevers Jun 7, 2025
36971f0
Add encoder angle diagram, first edits of text to use it.
elsevers Jun 7, 2025
8dc006b
Add latex source for motor cross section
elsevers Jun 7, 2025
cb1c257
add test code
elsevers Jun 7, 2025
d515467
Merge branch 'add-control-content' into add-enc-anirudh
elsevers Jun 8, 2025
41096e6
- Edit everything before finding the offset
elsevers Jun 8, 2025
f2ed019
Merge branch 'add-enc-anirudh' into user/Daehoon-Sung/update-offset-r…
elsevers Jun 8, 2025
9e7a82b
change image naming to dash-case
elsevers Jun 8, 2025
600fc24
Improve typesetting around the image
elsevers Jun 8, 2025
cc7f038
Add torque characteristic and update step 1 instructions.
elsevers Jun 8, 2025
5e845e7
Make motor cross-section plot 2 poles, add phave v and w axes
elsevers Jun 8, 2025
a86055f
Merge branch 'add-enc-anirudh' into user/Daehoon-Sung/update-offset-r…
elsevers Jun 8, 2025
d0d86d6
Add clarifying comment to torque characteristic
elsevers Jun 8, 2025
9341c81
Update index.md
Daehoon-Sung Jun 8, 2025
fc88ad4
Update the encoder offset plot
Daehoon-Sung Jun 8, 2025
2747e11
Update index.md
Daehoon-Sung Jun 8, 2025
24ff6a8
Update index.md
Daehoon-Sung Jun 8, 2025
4a8698a
Update source/getting-started/control-with-amdc/encoder-fb/index.md
Daehoon-Sung Jun 9, 2025
ae4a93f
Update index.md
Daehoon-Sung Jun 9, 2025
99a620f
Update index.md
Daehoon-Sung Jun 9, 2025
783a3a2
Update index.md
Daehoon-Sung Jun 9, 2025
281f09d
Fix rendering of equation
noguchi-takahiro Jun 10, 2025
dc92a10
Fix rendering issue of image
noguchi-takahiro Jun 10, 2025
655ec82
Update the encoder image
Daehoon-Sung Jun 13, 2025
0775c96
Merge branch 'user/Daehoon-Sung/update-offset-report' of https://gith…
Daehoon-Sung Jun 13, 2025
b5fe0f8
Update index.md
Daehoon-Sung Jun 13, 2025
bc7db65
Update the figure
Daehoon-Sung Dec 2, 2025
59b8863
Clarify terminology for mechanical angle in documentation
Daehoon-Sung Dec 2, 2025
e0e3223
Enhance encoder offset determination section
Daehoon-Sung Dec 2, 2025
64578a3
Clarify voltage equation with angular velocity note
Daehoon-Sung Dec 2, 2025
5ac71e2
Clarify voltage vector description in index.md
Daehoon-Sung Dec 2, 2025
39163c8
Fix voltage vector equation formatting
Daehoon-Sung Dec 2, 2025
b56bbdf
Refine description of encoder offset estimation process
Daehoon-Sung Dec 2, 2025
02d299b
Fix minor grammatical error in encoder offset section
Daehoon-Sung Dec 2, 2025
ed8f8ad
Fix formatting in encoder offset determination section
Daehoon-Sung Dec 2, 2025
2d0d0b1
Revise current command notation in encoder equations
Daehoon-Sung Dec 2, 2025
78f9611
Fix rendering issues for images
noguchi-takahiro Dec 3, 2025
a826e60
Clarify angle calculation and encoder offset procedure
Daehoon-Sung Dec 5, 2025
f28d03d
Revise encoder offset section contents (#146)
elsevers Dec 16, 2025
92cb825
Merge pull request #139 from Severson-Group/user/Daehoon-Sung/update-…
elsevers Dec 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 54 additions & 43 deletions source/getting-started/control-with-amdc/encoder-fb/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,96 @@

## Background

Encoders provide the rotor position feedback to the control system in a motor drive. This document describes a method to convert the raw readings of an encoder into meaningful position information which can be used by the contrl algorithm. Consequently, few techniques to derive the rotor speed from the measured position is also proposed. For more information on how an encoder works and how they may be interfaced with the AMDC please refer to this [document](https://docs.amdc.dev/hardware/subsystems/encoder.html#).
Encoders provide rotor position feedback to the control system in a motor drive. This document describes a method to convert the raw readings of an encoder into meaningful position information which can be used by the contrl algorithm. Consequently, few techniques to derive the rotor speed from the measured position are also proposed. For more information on how an encoder works and how they may be interfaced with the AMDC please refer to this [document](https://docs.amdc.dev/hardware/subsystems/encoder.html#).

## Calibration

Incremental encoders which are typically used with AMDC have a fixed number of counts per revolution (for example, 1024) and is denoted by `CPR`. The user needs needs to convert the count into usable angular information which maybe used in the code.
Incremental encoders which are typically used with AMDC have a fixed number of counts per revolution (for example, 1024) and is denoted by `CPR`. The user needs needs to write some code to obtaine the encoder count at a given instance and tconvert the count into usable angular information which can be used within the control code.

### Converting from raw counts to angle information
### Obtaining encoder count and translating it into rotor position

As a first step, the user may use the AMDC `enc` driver function `encoder_get_position()` to get the count of the encoder reading. Next, the user needs to verify if the encoder count is increasing or decreasing with counter-clock wise rotation of shaft. This may be done by manually rotating the shaft, if it is feasible. This document assumes a positive rotor angular position in the counter clockwise (CCW) direction of shaft rotation. Using this information, along with the offset and total encoder counts per revolution, the obtained count can be translated into angular position using a simple linear equation. Care must be taken by the user to ensure that angle is within the bounds of `0` and `2 $\pi$` by appropriately wrapping the variable.
<img src="./resources/EncoderCodeBlockDiargam.svg" width="100%" align="center"/>

Example code for when encoder count is increasing with CCW rotation of shaft:
As a first step, the user may use the AMDC `enc` driver function `encoder_get_position()` to get the count of the encoder reading. Next, the user needs to verify if the encoder count is increasing or decreasing with counter-clock wise rotation of shaft. This may be done by manually rotating the shaft and observing the trend of the reported position with respect to the direction of rotation. This document follows the convention of a positive rotor angle in the counter clockwise (CCW) direction of shaft rotation. Using this information, along with the offset and total encoder counts per revolution, the obtained count can be translated into angular position using a simple linear equation. The user must ensure that angle is within the bounds of 0 and 2 $\pi$ by appropriately wrapping the variable using the `mod` function.

Example code to convert encoder to angular position in radians:
```C
double task_get_theta_m(void)
{
// Get raw encoder position
uint32_t position;
encoder_get_position(&position);

// Encoder count per revolution
int ENCODER_COUNT_PER_REV, CCW;
double enc_theta_m_offset;

// User to set encoder count per revolution
ENCODER_COUNT_PER_REV = 1024;

// Set 1 if encoder count increases with CCW rotation of shaft, Set 0 if encoder count increases with CW rotation of shaft
CCW = 1;

// Angular position to be computed
double theta_m_enc;

// User to set encoder offset
enc_theta_m_offset = 100;

// Convert to radians
theta_m_enc = (double) PI2 * ( ( (double)position - enc_theta_m_offset )/ (double) ENCODER_COUNT_PER_REV);

// Wrapping to ensure within bounds
while (theta_m_enc < 0) {
theta_m_enc += PI2;
// Convert to radians
if (CCW){
theta_m_enc = (double) PI2 * ( ( (double)position - enc_theta_m_offset )/ (double) ENCODER_COUNT_PER_REV);
}
else{
theta_m_enc = (double) PI2 * ( ( (double)ENCODER_COUNT_PER_REV - (double)1 -(double)position + enc_theta_m_offset )/ (double) ENCODER_COUNT_PER_REV);
}

// Mod by 2 pi
theta_m_enc = fmod(theta_m_enc,PI2 );
return theta_m_enc;
}
```

Example code for when encoder count is decreasing with CCW rotation of shaft:
```C
double task_get_theta_m(void)
{
// Get raw encoder position
uint32_t position;
encoder_get_position(&position);

// Encoder count per revolution
ENCODER_COUNT_PER_REV = 1024;

// Angular position to be computed
double theta_m_enc;
### Finding the offset
Copy link
Contributor

@noguchi-takahiro noguchi-takahiro Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Daehoon-Sung I am sure you know about this section well and contribute to update some.


enc_theta_m_offset = 100;
The example code shown above makes uses of an encoder offset value. It is necessary for the user to find this offset experimentally for their machine. For synchronous machines, this offset is the count value measured by the encoder when the d-axis of the rotor is aligned with the phase U winding of the stator.

// Convert to radians
theta_m_enc = (double) PI2 * ( ( (double)ENCODER_COUNT_PER_REV - (double)1 -(double)position + enc_theta_m_offset )/ (double) ENCODER_COUNT_PER_REV);
To get the rotor to align with the phase U winding, the user may have some current flow through phase U and out of phase V and phase W. This can done by using a DC supply, with phase U connected to the positive terminal and phases V and W connected to the negative terminal. Alternately, the user may also inject some current along the d-axis using the AMDC injection function, but with the rotor position overridden by the user to 0. After obtaining the offset, the user needs to set the variable `enc_theta_m_offset` to the appropirate value in the `task_get_theta_m()` function.

To ensure that the obtained encoder offset is correct, the user may perform additional validation. For a permanent magnet synchronous motor, this can be done as follows:

// Wrapping to ensure within bounds
while (theta_m_enc > PI2) {
theta_m_enc -= PI2;
}
return theta_m_enc;
}
```
1. Spin the motor up-to a steady speed under no load conditions
1. Measure the d-axis voltage commanded by the current regulator
1. Repeat the experiment for a few different motor speeds
1. Plot the d-axis voltage against the motor speed
1. The d-axis voltage if the offset is tuned correctly, should be close to zero for all speeds.
1. In-case there is an error in the offset value, a significant speed dependent voltage will appear on the d-axis voltage

### Finding the offset

The example code shown above makes uses of an encoder offset value. It is necessary for the user to find this offset experimentally for their machine. For synchronous machines, this offset is the count value measured by the encoder when the rotor d-axis is aligned with the phase U of the stator.

To get the rotor to align with the phase U of stator the user may have some current flow through phase U and out of phase V and phase W. Alternately, the user may also inject some Id current with the AMDC injection function but with the rotot position set to 0.
## Computing Speed from Position

- Converting from raw counts to "theta"
- Direction: +/- depending on phase connections
- Sync machines: dq offset
The user needs to compute a rotor speed signal from the obtained position signal to be used in the control algorithm. There are several ways to do this. A simple and straightforward way to do this would be to compute the discrete time derivative of the position signal in the controller as shown below. This can be referred to as $\Omega_{raw}$.

## Computing Speed from Position
$$
\Omega_\text{raw}[k] = \frac{\theta_m[k] - \theta_m[k-1]}{T_s}
$$


$\Omega_\text{raw}$ will be a choppy and noisy signal due to the derivative operation. A low pass filter may be applied to this signal as shown below to get a filtered speed, $\Omega_\text{lpf}$. The user may select an appropriate bandwidth, $\omega_b$ for the low pass filter to eliminate the noise introduced by the derivative operation. However, this signal will always be a lagging estimate of the actual rotor speed due to the characterstics of a low pass filter.

$$
\Omega_\text{lpf}[k] = \Omega_\text{raw}[k](1 - e^{\omega_b T_s}) + \Omega_\text{lpf}[k-1]e^{\omega_b T_s}
$$

An observer which implements a mechanical model of the rotor as shown below will produce a no-lag estimate of the rotor speed, denoted by $\Omega_\text{sf}$. To implement an observer, the user needs to know the system parameters - `J` - the inertia of the rotor shaft and `b` - the damping coefficient of the rotor shaft. Further, to obtain a no-lag estimate it is necessary to provide the electromechanical torque, $T_{em}$ as input to the mechanical model. The `P-I` part of the observer closes the loop on the speed with $\Omega_\text{raw}$ being the reference input. The recommended tuning approach is as follows:

$$
K_p = \omega_{sf}b, K_i = \omega_{sf}J
$$

- LPF
- State Filter
- Observer
This tuning ensures a pole zero cancellation in the closed transfer function, resulting in a unity transfer function for speed tracking under ideal parameter estimates of `J` and `b`

Anirudh will added content here...
<img src="./resources/ObserverFigure.svg" width="100%" align="center"/>
Loading