cancel
Showing results for 
Search instead for 
Did you mean: 

How DO I switch from TIM4 CCP1 ISR to TIM4 CCP2 ISR

bluewaters213
Associate III
Posted on May 25, 2013 at 17:31

Hello,

I have a program where by after executing TIM4 CCP1 interrupt routine for a specified number of times, I disable TIM4 CCP1 Interrupt and enable  TIM4 CCP2 interrupt in TIM1 CCP4 Routine .TIM1 CCP4 ISR check for flag and knows when to enable TIM4 CCP2 Interrupt. I notice that TIM4 CCP2 ISR get executed even though TIM4 CCP2 Interrupt is not enable yet. Do anybody have idea what could the problem.

==============================

void TIM4_IRQHandler(void)

{

  if (TIM4->SR & TIM_SR_CC1IF)

          {                                                 /*ALIGNEMENT TIME EXPIRE, PROCEED TO RAMPUP */

                TIM4->SR = ~TIM_SR_CC1IF;                       /*clear CC1IF flag */

                

                TIM4->CCR1 = RAMP_TABLE[Ramp_Index];            /*TIM4 CCP1 Value Set to value in Ramp Table*/

        TIM4->CNT = 0;                                  /*Clear TIM4 Counter*/

        TIM4->EGR = TIM_EGR_UG;                             /*Reload prescaler and other registers*/

                Commutate();                                      /*Change commuation pattern on MOSFET*/

                TIM1->CCR1 = DutyCycle;                         /*Change CH1 PWM Duty Cycle by 6*/

                TIM1->CCR2 = DutyCycle;                         /*Change CH2 PWM Duty Cycle by 6*/

                TIM1->CCR3 = DutyCycle;                         /*Change CH3 PWM Duty Cycle by 6*/

                        

                if (Ramp_Index++ > RAMP_LENGTH)                 /*End of Motor Ramp*/

                    {                                           /*TIM4 Counter use for ZC Timing*/

                        Ramp_Index = 0;

                            TIM4->DIER &= ~TIM_DIER_CC1IE;            /*Disable TIM4 CCP1 Interrupt*/

                            TIM4->CNT = 0;                            /*Clear TIM4 Counter*/

                            TIM2CCP1_Start();                         /*Start TIM2 CCP1 for ADC HOLDOFF of 10us*/    

//                             GPIOB->BSRR = (1 << 9);

                    }    

            }

  if (TIM4->SR & TIM_SR_CC2IF)

       {

           TIM4->SR = ~TIM_SR_CC2IF;

             GPIOB->BSRR = (1 << 9);

             Commutate();                                 /*Change commuation pattern on MOSFET*/

             TIM4->CNT = 0;                            /*Clear TIM4 Counter*/

             TIM4->DIER &= ~TIM_DIER_CC2IE;            /*Disable TIM4 CCP1 Interrupt*/

             GPIOB->BRR = (1 << 9);

       }        

}

===========================

this is how i enable TIM4 CCP2 interrupt in TIM4 CCP1 ISR

                   TIM4->CCR1 =    FilteredCommutation_Time;      

                                     TIM4->CNT = 0;

                   TIM4->EGR = TIM_EGR_UG;                           /*Reload Prescaler and Other Registers*/

                   TIM4->DIER = TIM_DIER_CC2IE;                 /*Enable TIM2 CCP2 Interrupt*/

#stm32f103rb-tim4-ccp1-isr
0 REPLIES 0