Hello, i want to make a 1 us interrupt timer in for my stm32f103 in timer 2, i could make 10 us n 5 us, but in lower than that its not working truely! what should i do?!
/* TIM2 init function */ static void MX_TIM2_Init(void) { TIM_ClockConfigTypeDef sClockSourceConfig; TIM_MasterConfigTypeDef sMasterConfig; htim2.Instance = TIM2; htim2.Init.Prescaler = 0; htim2.Init.CounterMode = TIM_COUNTERMODE_UP; htim2.Init.Period = 359; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim2) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } }
it's workin with this for 5 us.
I expect to get 1us,
i'm using stm32f103rbt6, and frequency is 72 mhz, Does this "ST" chip meet my expectations?
MohsenJanlou said:I expect to get 1us,
And how do arrive at that expectation? How did you check you haven't reached it?
Please note that looking at the input state every microsecond in an interrupt handler is hardly the optimal way of measuring a frequency at that input. That's what timers have input capture modes (and corresponding input pins) for.
No because your expectations are unrealistic and unattainable. It is akin to driving 1000 KM and every metre you travel a kid in the back seat asks if you're there yet, and wants to use the bathroom. Is it realistic to stop 1,000,000 times?
The TIM have methods to a) count pulses over a given observation window, or b) measure the time between the edges of the signals