Hi,
All I know is that the mcpwm_foc_hall_detect() function is used to calculate the initial Angle of the sector corresponding to the HALL sensor. The results are stored in hall_table[].
For the details, there's something in the code of mcpwm_foc_hall_detect() that I don't understand:
//--------------------------------------------code section-----------------------------------------------------
// Forwards
for (int i = 0;i < 3;i++) {
for (int j = 0;j < 360;j++) {
motor->m_phase_now_override = (float)j * M_PI / 180.0;
chThdSleepMilliseconds(5);
int hall = utils_read_hall(motor != &m_motor_1);
float s, c;
sincosf(motor->m_phase_now_override, &s, &c);
sin_hall[hall] += s;
cos_hall[hall] += c;
hall_iterations[hall]++;
}
}
// Reverse
for (int i = 0;i < 3;i++) {
for (int j = 360;j >= 0;j--) {
motor->m_phase_now_override = (float)j * M_PI / 180.0;
chThdSleepMilliseconds(5);
int hall = utils_read_hall(motor != &m_motor_1);
float s, c;
sincosf(motor->m_phase_now_override, &s, &c);
sin_hall[hall] += s;
cos_hall[hall] += c;
hall_iterations[hall]++;
}
}
//-----------------------------------------------code section--------------------------------------------------
Q1: Why use a for loop?
Q2: Will The HALL state be change on each loop , because of the delay about 5ms?
Q3: Why do we need to distinguish between Forwards and Reverse?
Q4: Can you explain this iteration principle? or offer some ideas about math?
Thank you very much.
Thank you for your reply.
For the 4th , I want to ask you some questions about the loop that rotate the motor through 1 electrical revolution (for (int j = 360;j >= 0;j--))
1. The cycle pace is 1 degree, so the motor actually turns 1 degree ,YES or NO ?
code: motor->m_phase_now_override = (float)j * M_PI / 180.0;
2. What is the purpose of iteration with sin and cos ?
Best Regards
Conner