Hall sensor does not recognize FALLING_EDGE
Posted: Tue Sep 03, 2019 4:25 pm
Hello,
i am using an STM32F103C8T6 to read data from two hall sensors to detect the direction of rotation of a pulley mounted on a motor.
I am not able to count the pulses from the sensor with accuracy, i read multiple interrupts and is a problem. What i am doing wrong?
Attached the code to read the data from one sensor (i have the same problems with both sensors):
#define HAL_SENSOR_LINE_A0_PORT GPIOA
#define HAL_SENSOR_LINE_A0_PIN 0
void hal_sensor_init(void)
{
/* Enabling events on rising edge of the encoder lines.*/
// line A0
palSetLineMode(HAL_SENSOR_LINE_A0, PAL_MODE_INPUT_PULLUP);
palEnableLineEvent(HAL_SENSOR_LINE_A0, PAL_EVENT_MODE_FALLING_EDGE);
palSetLineCallback(HAL_SENSOR_LINE_A0, (palcallback_t)hal_sensor_line_a0_rising_edge, NULL);
}
static void hal_sensor_line_a0_rising_edge(void)
{
chSysLock();
if (palReadPad(GPIOA, 0) == PAL_LOW)
{
hal_sensor_A0_counter++;
hal_sensor_evaluate_data(PULLEY_PROBE_A0);
}
chSysUnlock();
}
Thank you,
Antonio
i am using an STM32F103C8T6 to read data from two hall sensors to detect the direction of rotation of a pulley mounted on a motor.
I am not able to count the pulses from the sensor with accuracy, i read multiple interrupts and is a problem. What i am doing wrong?
Attached the code to read the data from one sensor (i have the same problems with both sensors):
#define HAL_SENSOR_LINE_A0_PORT GPIOA
#define HAL_SENSOR_LINE_A0_PIN 0
void hal_sensor_init(void)
{
/* Enabling events on rising edge of the encoder lines.*/
// line A0
palSetLineMode(HAL_SENSOR_LINE_A0, PAL_MODE_INPUT_PULLUP);
palEnableLineEvent(HAL_SENSOR_LINE_A0, PAL_EVENT_MODE_FALLING_EDGE);
palSetLineCallback(HAL_SENSOR_LINE_A0, (palcallback_t)hal_sensor_line_a0_rising_edge, NULL);
}
static void hal_sensor_line_a0_rising_edge(void)
{
chSysLock();
if (palReadPad(GPIOA, 0) == PAL_LOW)
{
hal_sensor_A0_counter++;
hal_sensor_evaluate_data(PULLEY_PROBE_A0);
}
chSysUnlock();
}
Thank you,
Antonio