2023-04-13 02:29 AM
Hello,
i am using the STM32F410CBUx and want to detect rising and falling edges with the Timer 5.
I get these values with the help of the DMA because the signal edges are close together and i need accurate meassurments. The edges occure all in a short time frame and after that i have some time to compute them.
Sadly, all other channels are already in use doing the same with other signals so i cant use two for the same signal.
Is it possible to get the polarity of the edge together with the timervalue through DMA?
Thanks for your help.
2023-04-13 04:14 AM
> Is it possible to get the polarity of the edge
Unfortunately, no.
JW
PS. Added it as an idea for future STM32, please upvote
2023-04-14 04:06 AM
Thank you for the answer.
Then i have to do it with only one edge.
2023-04-14 11:45 AM
Hi PDieh.1
Your question has been routed to the online support team. A case has been created and you'll be contacted shortly
Kind Regards
Joe WILLIAMS
STMicro Support
2023-04-14 02:44 PM
Hi @Joe WILLIAMS ,
Isn't the point of a public forum to discuss technical issues for the benefit of all users participating?
So, would you be so kind and share any advice you have to OP, with us all?
Thanks,
JW
@Lina DABASINSKAITE
2023-04-25 05:34 AM
Hello,
to follow @Community member request, here the answer I got from an ST Employee:
I confirm that the timer doesn't have the edge polarity information in its registers. It is then not possible to transfer this information together with the counter value through the DMA transfer.
However, as the edge polarity is the opposite for each consecutive counter value transfererd by the DMA, the information needed is only the polarity of the signal when the counter is started.
If the edge polarity is unknown when the timer is started, the first edge of the signal could trigger an interrupt to allow the CPU to read this information.
This can be done by connecting the timer entry pin to another GPIO pin with external interrupt input feature (GPIO EXTI). The priority must be very high (let's say 0) to have a chance to get the timer input level before the next edge.
The code of the interrupt handler is then something like:
TIM5_InputState = GPIOA->IDR & GPIO_PIN_0; // Read the TIM5_CH1 GPIO input data register.
// The GPIO EXTI input data register can be used instead.
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_x);
Best Regards
2023-04-25 05:35 AM
But I have a followup question, maybe @Community member can help.
I start the DMA with the HAL_TIM_IC_Start_DMA function and i write the data in an Array with the size of 20. In my testcase, i get only one edge (later i don't know how much there are, this can and will vary), but the DMA filles the size of the array completly with the same value from the edge. If i have two edges, it filles the array with both values in alternating order.
Is there a way to only geht the values only once and leave the other values in the array at 0?
Thanks for your help and best regards,
Philipp Diehl
2023-04-25 06:08 AM
Thanks for sharing the reply.
> However, as the edge polarity is the opposite for each consecutive counter value transfererd by the DMA,
> the information needed is only the polarity of the signal when the counter is started.
This does works only if there is no overflow, i.e. if all edges are enough far apart that DMA can transfer all the capture values without missing any. It's highly nontrivial to determine what is the limit in a given system. I'm not sure if overcapture detects this case, it might.
> If the edge polarity is unknown when the timer is started, the first edge of the signal
> could trigger an interrupt to allow the CPU to read this information.
Surely, the input level of given pin can be read at the moment when timer is started (assuming there are no edges around this time), and that then determines the subsequent edge.
Perhaps a better solution might be to capture rising and falling edges separately on two channels of the same timer, using the possibility to "redirect" signal to "neighbouring" channel. DMAing them may be not that simple, I'd try to use the DMAR/DCR mechanism triggered from one of the channels but I'm not entirely sure it would work as expected.
> DMA filles the size of the array completly
This is strange. I don't use Cube. Read out and check/post content of DMA and TIM registers.
JW
2023-04-26 05:08 AM
Hello,
i found my problem.
The HAL_TIM_IC_Start_DMA Function needs the number of values it should transfer and since i didn`t know that, i used a higher number. But this means, that it was not automatically finished after i recieved my Edges.
Combined with the time it takes to stop the program with the debugger, it filled the array with the values of the next frame.
My solution was to trigger an interupt bevor my measuring window to start the DMA and one interupt after the frame to stop it with HAL_TIM_IC_Stop_DMA.
Then i only get the values and 0 in all other positions in the array.
Thanks for your help!
Best regards,
Philipp Diehl