2023-10-10 04:13 AM - edited 2023-10-10 04:19 AM
Hi,
I am working with STM32G491RE.I am giving pulse to GPIO pin from function generator. That pulse will be 2 msec on time and 8msec off time.I need to make flag high if the signal from function generator lost.
Can anyone suggest me how to do this?
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin==detect_Pin){
if(HAL_GPIO_ReadPin(detect_GPIO_Port,detect_Pin)==GPIO_PIN_SET){
HAL_UART_Transmit(&huart2, (uint8_t *)"rising:",7, HAL_MAX_DELAY);
}
else if(HAL_GPIO_ReadPin(detect_GPIO_Port,detect_Pin)==GPIO_PIN_RESET){
HAL_UART_Transmit(&huart2, (uint8_t *)"falling:",8, HAL_MAX_DELAY);
}
else
{
HAL_GPIO_WritePin(led_GPIO_Port,led_Pin,GPIO_PIN_SET);
}
I tried with EXTI interrupt but If input is there from generator its detecting both rising and falling edge and if there is no signal from generator I am not getting in to else condition.
img: pulse input from function generator.
1.If I want to make flag high for no signal from function generator,above image offtime also it considering as no signal.
can anyone suggest how to do?
Thanks
Solved! Go to Solution.
2023-10-10 07:10 AM
Read HAL_GetTick within your interrupt and store as a global variable. To check if signal is lost see if difference from current HAL_GetTick and the one you stored is >10ms. If so, signal has been lost.
2023-10-10 04:43 AM - edited 2023-10-10 04:45 AM
you could do it with a retriggerable monoflop , set to 10ms ; this would change output, if 10ms no trigger coming.
on a cpu this could be a timer ( ie. Tim 2..4) , set to Retriggerable one pulse mode , update interrupt (enable : UIE ) will trigger, when full time of timer is reached (if set to 10ms , get int then).
2023-10-10 05:07 AM
Hi @AScha.3 ,
Thanks for the reply. are you telling to use timer instead of GPIO?. I need to use GPIO only for my application. Can't I check without timer? Can you clarify.
retriggerable monoflop - concept new to me but I will check.
Thanks
2023-10-10 06:37 AM - edited 2023-10-10 06:39 AM
the trigger in is a gpio pin...just look in Cube , when you select ETR (external trigger)
you just cannot use any pin you like , every timer has some fixed pin numbers for this function.
2023-10-10 07:10 AM
Read HAL_GetTick within your interrupt and store as a global variable. To check if signal is lost see if difference from current HAL_GetTick and the one you stored is >10ms. If so, signal has been lost.
2023-10-10 09:52 PM - edited 2023-10-10 09:53 PM
Hi @TDK,
is it correct?
volatile uint32_t last_input_change=0;
const uint32_t pulse_timeout = 10;
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin==Zerocross_detect_Pin){
last_input_change =HAL_GetTick();
}
}
void fault()
{
uint32_t last_input_change_copy = last_input_change;
if(HAL_GetTick()-last_input_change_copy>=pulse_timeout)
HAL_GPIO_WritePin(led_GPIO_Port,led_Pin,GPIO_PIN_SET);
}
2023-10-11 07:06 AM
Looks good to me.