How to setup input capture mode for Maxbotix LV-MaxSonar using Pulse Width (Pin 2)
Hi I'm new to stm32Cube and have been trying for days to read these ultra sonic sensors. Here is the data sheet to the one i am using:
https://www.maxbotix.com/documents/LV-MaxSonar-EZ_Datasheet.pdf
if someone could please attach a picture of the stm32cube setup in order to read the Pulse Width (Pin 2) from the sensor i want the internal timer to start on the rising edge and stop/capture on the falling edge of the signal here is the setup i'm currently trying :

Any help would be much appreciated I'm very new to using timers and tried reading the timers cookbook but after 12 setup attempts i get an output that changes but i cant seem to figure out if i'm doing it right
this is my flag:
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) {
if (htim->Instance == TIM2) {
if (i == 0) {
cap1 = __HAL_TIM_GET_COMPARE(&htim2, TIM_CHANNEL_1);
i = 1;
} else if (i == 1) {
cap2 = __HAL_TIM_GET_COMPARE(&htim2, TIM_CHANNEL_1);
i = 0;
}
__HAL_TIM_SET_COUNTER(&htim2, 0);
}
}and this is my while:
HAL_TIM_IC_Start_IT(&htim2,TIM_CHANNEL_1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
count = __HAL_TIM_GET_COUNTER(&htim2);
}
/* USER CODE END 3 */
}hers a snapshot of of output the values change i'm just no sure if it's right:

