AnsweredAssumed Answered

Problem in using TIM2 Flag Polling

Question asked by slimsly on Mar 2, 2013
Latest reply on Feb 21, 2014 by Clive One
Hello,

I want to use Timer2 to generate approx 1secs Pulse without interrupt. I want the code to sit in an endless loop while testing the TIM2 update interrupt flag or TIM2 CCP1 Flag (I plan to use Compare instead of Update in the future). The problem is I can not generate the pulse when view with Salae Logic Analyzer. it seems like the TIM2 update interrupt flag  is always set or something is wrong with my code. Please I need help.

const uint32_t Comm_Index[6] = {0x00001054,0x00001504,0x00001540,0x00001045,0x00001405,0x00001450};
uint32_t Ramp_Index;
uint32_t NextCommutationStep;
uint32_t  CurrentCommutationStep;
uint32_t BEMF_DETECTION_FLAG = FALSE;

extern uint32_t Step_Count;

void StartUp(void)
{
     TIM1->CCER = Comm_Index[CurrentCommutationStep];/*Align Rotor to Step 1*/
     TIM1->CCR1 = TIM1->CCR2 = TIM1->CCR3 = 1024;
    
     Ramp_Index = Step_Count = 0;
   NextCommutationStep = CurrentCommutationStep = 0;/*Align Rotor to Step 0 */
    
   TIM2->PSC = 2199;                               /*Set Prescaler to (PSC + 1)*/
   TIM2->ARR = 32727;                              /*Auto reload value 1000ms Alignment)*/
   TIM2->DIER = TIM_DIER_UIE  ;                    /*Enable update interrupt (timer level)*/
     TIM2->CR1 = TIM_CR1_CEN;                        /*Start TIM2 (ALIGNMENT COUNTDOWN)*/
     GPIOB->ODR ^= (1 << 8);     
     while (!(TIM2->SR & TIM_SR_UIF))  {             /*1000ms ALIGNEMENT TIME EXPIRE*/       
        }
        TIM2->SR &= ~TIM_SR_UIF;                       /*clear UIF flag */
        GPIOB->ODR ^= (1 << 8);
        TIM1->CCER = Comm_Index[NextCommutationStep];  /*Align Rotor to Step 1*/    
        NextCommutationStep++;                         /*Increment to the Next Commutation Step*/
        GPIOB->ODR ^= (1 << 8);                        /*Toggle PB8*/      
    
}

Regards
Slim

Outcomes