cancel
Showing results for 
Search instead for 
Did you mean: 

Integrating an analog magnetic sensor in MCSDK 6.1.2 generated project

mirhamza708
Associate

Hi everyone,
I am currently working on implementing an FOC algorithm based on a single analog linear hall effect sensor (DRV5055). This sensor will be used to measure the angle of the rotor. The control\inverter board that I am using is the B-G431-ESC1 which don't have an extra analog pin but there is a potentiometer which I have removed and used that pin as my ADC input from the DRV5055. The sensorless algorithm runs good on this board but since my application requires very low speed operation so I want to implement this analog sensor. Also this sensor have a high bandwidth so this can operate both at low speeds and high speeds. I have tested the hardware the sensor provides reading from 1600 to 2400 in 12 bit ADC value maybe because the magnet on the shaft is not strong enough or the sensor has low sensitivity. Now about integrating the analog sensor:

I plan to do it this way:
>>>Create a project with hall effect sensors (3 sensors spaced at 60) from the MCSDK.
>>>Bring that project in cubeide and then modify the hall_speed_pos_fdbk.c and hall_speed_pos_fdbk.h files so they provide the angles calculated from the analog sensor instead of the combination of 3 hall effect sensors.
>>>Also I want to call the ADC conversion every systick interrupt just after the MC_Scheduler() is called, as my speed loop rate is around 2KHz, the ADC value is also calculated at 2KHz. 

While the idea seems to be possible (to me), I want to get some expert opinions on this way of doing this also some advice would be great on what would be the most efficient way of doing the programming like how to play with the handles and the functions so the rest of the code don't break. I would be really thankful if someone can let me know if there is some other better way of doing this. Also, why STMicroelectronics not include the Hall effect analog sensor in the SDK? I heard that they have a confidential version of the SDK where they have implemented this analog sensor, does anyone have any idea about that?

1 REPLY 1
ramprakash08
Associate III

Based on your description, it seems like you're on the right track with your approach to integrating the analog magnetic sensor into your MCSDK 6.1.2 generated project. Modifying the hall_speed_pos_fdbk.c and hall_speed_pos_fdbk.h files to provide angles calculated from the analog sensor instead of the combination of 3 hall effect sensors is a good starting point.

However, there are a few things to consider:

  1. Ensure that the ADC conversion is synchronized with the PWM period. This is to make sure that the ADC conversion is not happening during the PWM transitions, which can cause noise in the ADC readings.
  2. Make sure to handle the ADC conversion in an interrupt routine to ensure that the ADC values are updated in real-time.
  3. Consider using a moving average filter or a low pass filter to filter out any noise in the ADC readings.

As for the question about why STMicroelectronics does not include the Hall effect analog sensor in the SDK, it's likely because the Hall effect sensors are typically digital and are used for commutation of the motor, while the analog sensors are typically used for more precise position control applications.

Regarding the confidential version of the SDK, it's not possible to provide information on that. However, you can refer to the MCSDK User Manual for more information on how to implement the Hall sensor feedback processing.

Here is a code snippet that might be helpful:

 void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {     // Start the next ADC conversion     HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_value, 7);
// Calculate the angle from the ADC value angle = calculate_angle_from_adc_value(adc_value);
// Update the angle in the motor control algorithm update_motor_control_angle(angle); }

This code starts the ADC conversion in the ADC interrupt routine and calculates the angle from the ADC value. The angle is then updated in the motor control algorithm.