AnsweredAssumed Answered

how to make 500nS delay function using timer3

Question asked by fynn.luis on Aug 11, 2015
Latest reply on Feb 23, 2016 by Clive One
I wanna to make 500ns delay function using timer3. I can't use systick timer because FreeRTOS use systick timer. 

I wrote my code below.. please help me !!!

13 void TimerInit(void)
 14 {
 15     NVIC_InitTypeDef NVIC_InitStructure;
 16     TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
 17
 18     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);            //TIM2 clock enable
 19     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);            //TIM3 clock enable
 20
 21     NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;                 /* Enable the TIM2 Interrupt */
 22     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 14;
 23     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 24     NVIC_Init(&NVIC_InitStructure);
 25
 26     NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;                 /* Enable the TIM3 Interrupt */
 27     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 14;
 28     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 29     NVIC_Init(&NVIC_InitStructure);
 30
 31     //Time base configuration
 32     //time of 1 clock count = (Period * Prescaler) / (System Core Clock)
 33     //(10000*72)/72000000 = 0.01(10mS)
 34     TIM_TimeBaseStructure.TIM_Period = 10000-1;     // Interrupt occured, every 10000 Clock count.
 35     TIM_TimeBaseStructure.TIM_Prescaler = 72-1;     // Timer clock setting. Up to 1s, Clock Count need to 1,000,000(72/System Clock(=72Mhz))
 36     TIM_TimeBaseStructure.TIM_ClockDivision = 0;
 37     TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 38     TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
 39     TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);      /* Enable TIM2 Update interrupt */
 40     //  TIM_Cmd(TIM2, ENABLE);                      // TIM2 enable counter
 41
 42     //Time base configuration
 43     //time of 1 clock count = (Period * Prescaler) / (System Core Clock)
 44     //(24*3)/72000000 = 0.00001(10uS)
 45     TIM_TimeBaseStructure.TIM_Period = 1-1;     // Interrupt occured, every 1000 Clock count.
 46     TIM_TimeBaseStructure.TIM_Prescaler = 72-1;     // Timer clock setting. Up to 1s, Clock Count need to 1,000,000(72/System Clock(=72Mhz))
 47     TIM_TimeBaseStructure.TIM_ClockDivision = 0;
 48     TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 49     TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
 50     TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);      /* Enable TIM2 Update interrupt */
 51     TIM_Cmd(TIM3, ENABLE);                          // TIM3 enable counter
 52 }
 53

Outcomes