I use one motor to drive one object move back and forth in a straight line, with two hall ic(XC3202) at the boundary points at both ends. The motor turn when the object reaches one detecting point.
I use interrupt to detect the object reach the boundary point(the hall ic), but finally i found the interrupt sometimes lost, especially when the motor speed is high.
//----------------------------------
void hall_ic_detect_init(void)
{
nrf_drv_gpiote_in_config_t in_config1 = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);
in_config1.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(HAL_PIN1, &in_config1, hall_pin1_handler);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_gpiote_in_init(HAL_PIN2, &in_config1, hall_pin2_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(HAL_PIN1, true);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(HAL_PIN2, true);
APP_ERROR_CHECK(err_code);
}
void hall_pin1_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
if(pin == HAL_PIN1 && action == GPIOTE_CONFIG_POLARITY_HiToLo)
{
left_detect_flag = 1;
}
}
void hall_pin2_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
if(pin == HAL_PIN2 && action == GPIOTE_CONFIG_POLARITY_HiToLo)
{
right_detect_flag = 1;
}
}
When the motor runs with a high speed ,the hall_pin1_handler() and hall_pin2_handler() can't trigger sometimes. I am puzzled, maybe the softdevice block it? or else reason?