You are here

HALL-FOC---don't understand the mcpwm_foc_hall_detect() function

3 posts / 0 new
Last post
ConnerL
ConnerL's picture
Offline
Last seen: 3 years 10 months ago
Joined: 2021-01-06 10:22
Posts: 2
HALL-FOC---don't understand the mcpwm_foc_hall_detect() function

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.

 

 

district9prawn
Offline
Last seen: 2 years 2 weeks ago
Joined: 2018-04-26 12:18
Posts: 123
  1. The nested for loops rotate the motor through 3 electrical revolutions. The current used to rotate the motor is probably set a few lines before the code you pasted.
  2. The expected behaviour is 6 hall states per electrical revolution.
  3. I believe that will help determine the offset in the physical placement of the halls.
  4. Not exactly sure what you are asking here?
ConnerL
ConnerL's picture
Offline
Last seen: 3 years 10 months ago
Joined: 2021-01-06 10:22
Posts: 2

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