generate delay in stm32 use timer -
I'm trying to generate 1us delay using stm32, I know that I need a timer. I've got some code on the timer, but I do not know how to configure the setting to make it 1us because the setting depends on the epi 1 clock frequency or below is my code:
Zero TIM5_Init_Query (zero) {TIM_TimeBaseInitTypeDef Tim5; TIM_DeInit (TIM5); RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM5, enabled); Tim5.TIM_Period = 1; Tim5.TIM_Prescaler = 80-1; Tim5.TIM_ClockDivision = 1; Tim5.TIM_CounterMode = TIM_CounterMode_Down; TIM_TimeBaseInit (TIM5, & amp; Tim5); } Zero us Dele (U32 NTEM) {u16 counter = ntem & amp; 0xffff; TIM_Cmd (TIM5, enabled); TIM_SetCounter (TIM5, counter); While (counter> 1) {counter = TIM_GetCounter (TIM5); } TIMCMD (TM5, Disable); } My question is, how to set TIM_precaler, TIM_Period, and Tim5. What is the relationship between the IMMLL link division, those values and my delay? How to check the frequency of APB 1 clock in my code?
You can get the APB clock frequency at run time of RCC_GetClocksFreq Using which is provided in STM32 peripheral library. If you are using an external crystal, then the correct value for this function can return, in which the default value (8 MHz or 25 MHz STM32F1xx, check your microcontroller) is frequency, you can use the macro < Code> HSE_VALUE and set it to the crystal frequency used in your project. You did not tell which microcontroller you are using (many different St 32 micros), but different parameters for your microcontroller family reference reference book, for example STM32F1XX Section 15.3 of the reference book will be, this document:
Comments
Post a Comment