MCPcopy Create free account
hub / github.com/ZhuYanzhen1/miniFOC / encoder_get_electronic_angle

Function encoder_get_electronic_angle

program/algorithm/encoder.c:93–101  ·  view source on GitHub ↗

! \brief according to the electrical angle calculated from the mechanical angle, this function will call encoder_get_mechanical_angle() function. \retval register raw data reading back */

Source from the content-addressed store, hash-verified

91 \retval register raw data reading back
92*/
93float encoder_get_electronic_angle(void) {
94 /* read back the mechanical angle directly from the magnetic encoder */
95 unsigned short tmp_mechanical_angle = encoder_get_mechanical_angle();
96
97 /* calculate and update the mechanical angle and electric angle */
98 FOC_Struct.mechanical_angle = (float) tmp_mechanical_angle * MECHANGLE_COEFFICIENT;
99 float electric_angle = (float) (tmp_mechanical_angle % (ENCODER_RESO / POLAR_PAIRS)) * ELECANGLE_COEFFICIENT;
100 return electric_angle;
101}
102
103/*!
104 \brief called every 2 milliseconds to calculate the speed.

Callers 1

TIMER2_IRQHandlerFunction · 0.85

Calls 1

Tested by

no test coverage detected