Question
How to differentiate Motor 1 from Motor 2 in __weak void *HALL_TIMx_CC_IRQHandler(void *pHandleVoid)?
Hi everyone,
I'm working on a dual motor setup using an STM32F303 with the STM32 Motor Control SDK (MCSDK). I'm using FOC with Hall sensors and 3-shunt current sensing. The project is configured with MC Workbench and controlled via ST Motor Pilot.
I’m trying to track the position of Motor 1 using the following code inside the Hall sensor interrupt handler:
rotation_count_M1 -= pHandle->Direction * SenseMoteurM1;
This works fine when only one motor is connected. However, when both motors are active, the function __weak void *HALL_TIMx_CC_IRQHandler(void *pHandleVoid) is called for both motors, and the position count becomes incorrect — which makes sense, since I can't tell which motor triggered the interrupt.
I tried something like:
if (pHandle == "HALL_M1") { ... }
But of course, that doesn’t work because pHandle is a pointer, not a string.
My question is:
What is the proper way to identify whether pHandle corresponds to Motor 1 or Motor 2 inside this interrupt handler? Is there a recommended way to compare it with the actual motor handles (e.g., HALL_M1, HALL_M2) or retrieve the motor index?
What is the proper way to identify whether pHandle corresponds to Motor 1 or Motor 2 inside this interrupt handler? Is there a recommended way to compare it with the actual motor handles (e.g., HALL_M1, HALL_M2) or retrieve the motor index?
Thanks in advance for your help!
