2025-04-24 4:36 AM - last edited on 2025-04-24 4:48 AM by mƎALLEm
Hi Team,
Currently I am working with STM32U575ZiTx SOC and I am using Tim3 for counting external clock pulses,
Can you guide me with the code please.
Below is my requirement :
1. What is the maximum frequency of the incoming signal? (To ensure the timer can handle it without missing counts)
Answer : The frequency is measuring the spin rate of a physical system; a wind-turbine RPM or something similar.
I think we can very safely say the maximum edge rate will be less than 100 kHz (heh) and probably closer to a max of 3600.
2. Should the rolling counter value be transmitted as-is, or should it be reset after each transmission?
Answer : We confirmed with the end customer that the counter will roll over and is expected to reset on reboot.
Code Reference :
static void MX_TIM3_Init(void)
{
/* USER CODE BEGIN TIM3_Init 0 */
/* USER CODE END TIM3_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_IC_InitTypeDef sConfigIC = {0};
/* USER CODE BEGIN TIM3_Init 1 */
/* USER CODE END TIM3_Init 1 */
htim3.Instance = TIM3;
htim3.Init.Prescaler = 0;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 4294967295;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV2;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_ETRMODE2;
sClockSourceConfig.ClockPolarity = TIM_CLOCKPOLARITY_NONINVERTED;
sClockSourceConfig.ClockPrescaler = TIM_CLOCKPRESCALER_DIV1;
sClockSourceConfig.ClockFilter = 0;
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_IC_Init(&htim3) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
if (HAL_TIM_IC_ConfigChannel(&htim3, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM3_Init 2 */
/* USER CODE END TIM3_Init 2 */
}
void Timer_Handling_Thread(void *argument)
{
char iridium_buffer[64] = {0};
HAL_TIM_Base_Start(&htim3);
while(1)
{
uint32_t count = __HAL_TIM_GET_COUNTER(&htim3);
snprintf(iridium_buffer, sizeof(iridium_buffer),"Pulse Count: %lu (dec), 0x%lX (hex)\r\n", count, count);
HAL_UART_Transmit(&huart2, (uint8_t *)iridium_buffer, strlen(iridium_buffer), HAL_MAX_DELAY);
}
}
Can you help me with respect to the configurations of CubeMX ? If possible please provide a suggestions on this post ?
2025-04-24 4:50 AM - edited 2025-04-24 4:50 AM
Hello @ram_jan and welcome to the ST community,
Please review how to post a question in this community in this link, especially how to share a code. I've edited your post.
Thank you for your understanding.
2025-04-24 4:56 AM
Hi mƎALLEm,
Thank you editing my post, Sorry I was not knowing before.
When can I get the response the for the query I mentioned above ?
Thanks and Regards,
ram jan
2025-04-24 5:30 AM
Hi Team,
How can I utilize minimum of 6 channels of two timer pins to convert external pulses ? Can you give any solution on this ?
Thanks and Regards,
2025-04-24 6:09 AM - edited 2025-04-24 6:09 AM
An external clock rate of 100 kHz is no problem. The max rate is going to be about a quarter of the timer frequency, in the MHz region.
Let the timer free-run and take the difference in the counts between successful calls to calculate the speed.
2025-04-24 6:11 AM
You can use a circular DMA transfer to capture the IC value and use the DMA's NDTR register to see how many transfers have taken place. This is somewhat more complicated to set up than using only one channel per timer as the external clock.
2025-04-24 10:55 PM
Hi Team,
Thank you for your response.
I would like to know if there's a way to configure the timers to read from at least six timer channels continuously with / without using DMA configurations.
While exploring this, I noticed that enabling certain options in Slave Mode seems to disable some channel configurations. Could you please clarify this behavior?
Additionally, if possible, could you please share the relevant STM32CubeMX configuration settings or screenshots for this setup?
Looking forward to your guidance.
Thanks and Regards,
2025-04-25 2:52 AM
Hi Team,
Any suggestions for the Query to count minimum of 6 input channels without using DMA please, Please share the CubeMX configuarations / working firmware please.
Thanks and Regards,
2025-04-25 7:56 AM
> I would like to know if there's a way to configure the timers to read from at least six timer channels continuously with / without using DMA configurations.
No. Timers have a single counter.