0

I am designing an ESC with stm32f103c8t6. In my design I am using BEMF circuitry to detect phase of the motor. From BEMF circuitry (with comparator LM339) I am reading 3 interrupt pins but when code running I need to change the pinmode (like rising edge detection to falling edge detection) and also I need to disable other 2(it depends on phase of the motor at that time) interrupt pins in order to not to read noise that comes from circuitry. How can I do that?

Thanks for your help,

1 Answers1

0

Something like this to switch between falling/rising edge:

void isr_hallsensor(void) {
    if (hallsensor_edge_select) {
        //rising edge, magnet has left the detection zone.
        gpio_hall_sensor.Mode = GPIO_MODE_IT_FALLING;
        HW_GPIO_Init(HALLSENSOR_PORT, HALLSENSOR_PIN, &gpio_hall_sensor);
        hallsensor_edge_select = 0;
        __HAL_GPIO_EXTI_CLEAR_IT(HALLSENSOR_PIN);
    } else {
        //falling edge, magnet detected.
        gpio_hall_sensor.Mode = GPIO_MODE_IT_RISING;
        HW_GPIO_Init(HALLSENSOR_PORT, HALLSENSOR_PIN, &gpio_hall_sensor);
        hallsensor_edge_select = 1;
        __HAL_GPIO_EXTI_CLEAR_IT(HALLSENSOR_PIN);
    }
}

Something like this to enable an interrupt:

    __HAL_TIM_CLEAR_IT(&htim16, TIM_IT_UPDATE);
    HAL_NVIC_SetPriority(TIM1_UP_TIM16_IRQn, 15, 15);
    HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn);

Something like this to disable an interrupt:

    HAL_NVIC_DisableIRQ(TIM6_DAC_IRQn);

This will at least get you started, this is for STM32L4.

pgibbons
  • 309
  • 2
  • 5