AnsweredAssumed Answered

Issue while Enabling and Disabling Timer

Question asked by arbitrer on Jan 19, 2015
Basically what my problem is Once I de-init the Timer after a successful operation I'm not able to re-init it again...

I am writing a program to generate a delay using timer whose delay canbe varied according to the user defined value. But for the First timeI'm able to generate the desired delay but Once I de-initialize I'm notable to reinitialize the timer again

 void TIM2_irq(void)
    if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
        TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
        if(count == Max_Cnt )
            flag=1;             //Once the defined count is reached set the flag
            TIM_DeInit(TIM2);   //Deinitialise the Timer

void delay_using_TIM(float delay_val)
    Max_Cnt = delay_val *10;
    NVIC_InitTypeDef NVIC_InitStructure;
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
    /* Enable the TIM2 gloabal Interrupt */
    NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    /* TIM2 clock enable */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
    /* Time base configuration */
    TIM_TimeBaseStructure.TIM_Period = 5;
    TIM_TimeBaseStructure.TIM_Prescaler = 0x410;        // Verfied 100 microsec for timer expiry
    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
    /* TIM IT enable */
    TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
    /* TIM2 enable counter */
    TIM_Cmd(TIM2, ENABLE);

int main()
        GPIO_SetBits(GPIOB, GPIO_Pin_6);    //Gpio is already initialised
        GPIO_ResetBits(GPIOB, GPIO_Pin_6);

Is this the proper way of de-initializing the Timer ?

Please help