cancel
Showing results for 
Search instead for 
Did you mean: 

ADC preventing SysTick timer Interrupt (Why?)

bluewaters213
Associate III
Posted on March 10, 2013 at 17:56

Hello,

Once I initailize ADC in my program, it stop the SysTick timer Interrupt from working while ADC work correctly.I want ADC Interrutp to have higher priority than SysTick timer Interrupt.How do I set the priority Level correctly so that the SysTick timer & AD will work correctly?.

======SYSTEM TICK DOES NOT WORK WHILE ADC IS ENABLE=================

int main(void)

{

           

  Init_SysClock();              /*Initialize GPIO & Peripherals Clocks*/

  Init_RCC();                   /*Initialize GPIO*/

  Init_ADC();                   /*Initialized ADC in dual Mode*/

  Init_PWM();                   /*Initialize 17.5KHz PWM on CH 1-3*/

  StartUp();                    /*Align & RampUP BLDC Motor*/

    

   if (SysTick_Config(SystemCoreClock / 1000))

        {

         while(1);/* Capture error */

        }

    

   NVIC_SetPriority(SysTick_IRQn,35);    //Assign SysTick_IRQn = 30 | ADC interrupt Priority = 25(default)           

  while(1)

    {

    }

}

======SYSTEM TICK DOES WORK WHILE ADC IS DISABLE=================

int main(void)

{

           

  Init_SysClock();              /*Initialize GPIO & Peripherals Clocks*/

  Init_RCC();                   /*Initialize GPIO*/

  //Init_ADC();                   /*Initialized ADC in dual Mode*/

  Init_PWM();                   /*Initialize 17.5KHz PWM on CH 1-3*/

  StartUp();                    /*Align & RampUP BLDC Motor*/

    

   if (SysTick_Config(SystemCoreClock / 1000))

        {

         while(1);/* Capture error */

        }   

    

  NVIC_SetPriority(SysTick_IRQn,35);    //Assign SysTick_IRQn = 30 | ADC interrupt Priority = 25(default)

               

  while(1)

    {

    }

}

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

//========================================================================

// ADC Configuration for CH10(PC0) - CH13(PC3) in Dual Simultaneous Injected Mode

//========================================================================

void Init_ADC(void)

{

  RCC-> CFGR |= RCC_CFGR_ADCPRE_DIV6;   //ADC divided by 4 (12MHz)

//Scan Enable| Injected Simultaneous Dual Mode Only |Discontinuous mode on injected channels Enable

//Injected Interrupt Enable

    ADC1->CR1 = ADC_CR1_SCAN | INJECTED_DUAL_MODE_ONLY |ADC_CR1_JEOCIE;

    

//ADC2 Config=>Interrupt enable for injected channels | Scan Mode*/

  ADC2->CR1 = ADC_CR1_SCAN | ADC_CR1_JEOCIE;

    

//Power Up ADC1 |Conversion on External Event Enabled | Enable TIM1 CC4 Trigger

  ADC1->CR2 = ADC_CR2_ADON | ADC_CR2_JEXTTRIG | TIM1_CC4_TRIG;

//Power Up ADC2 |Conversion on External Event Enabled | Enable Software Trigger

  ADC2->CR2 = ADC_CR2_ADON | ADC_CR2_JEXTTRIG | SOFTWARE_TRIG;

  ADC1->SMPR1 = ((uint32_t)0x00000000); //CH10 - CH11 Sample Time = 239.5 cycles

  ADC2->SMPR1 = ((uint32_t)0x00000000); //CH12 - CH13 Sample Time = 239.5 cycles

  ADC1->JSQR = ADC_JSQR_JL_0 | Inject_CH10_CH11;  //2 Injected conversions (CH10 & CH11)

  ADC2->JSQR = ADC_JSQR_JL_0 | Inject_CH12_CH13;  //2 Injected conversions (CH12 & CH13)

  ADC1->CR2 |= ADC_CR2_RSTCAL;   //Initialize ADC1 calibration register

  while ( ADC1->CR2 & ADC_CR2_RSTCAL );

  ADC2->CR2 |= ADC_CR2_RSTCAL;   //Initialize ADC2 calibration register

  while( ADC2->CR2 & ADC_CR2_RSTCAL );

  ADC1->CR2 |= ADC_CR2_CAL;   //Start ADC2 calibration

  while ( ADC1->CR2 & ADC_CR2_CAL );//Calibration Completed

  ADC2->CR2 |= ADC_CR2_CAL;   //Start ADC2 calibration

  while( ADC2->CR2 & ADC_CR2_CAL );//Calibration Completed

    

  NVIC_EnableIRQ(ADC1_2_IRQn);//Enable ADC1_2 Interrupt in NVIC

}

void SysTick_Handler(void)

 {   

    GPIOB->ODR ^= (1 << 8); 

 }

Regards
3 REPLIES 3
Posted on March 10, 2013 at 18:59

On might hazard that there is a problem with your ADC interrupt handler, not shown, or the rate at which it is called. If you saturate the processor it will stay in the handler continuously.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bluewaters213
Associate III
Posted on March 10, 2013 at 20:44

Hello,

Thanks for your response. I configure TIM1 PWM running at 17.5KHz to trigger the ADC in center align mode.The Code for the adc handler is shown below.Do you have any idea of how I can fix the problem?.

void ADC1_2_IRQHandler(void)

{

  if (ADC1->SR & ADC_SR_JEOC)  /*ADC Injected channel end of conversion Completed*/

    {

                   

    if (BEMF_DETECTION_FLAG == TRUE)               /*ZERO CROSSING DETECTION ENABLE*/

        {  

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

                   

          BEMF[2] = BEMF[5] = ADC1->JDR1;          /*Read Phase A BEMF Value*/

          BEMF[1] = BEMF[4] = ADC1->JDR2;          /*Read Phase B BEMF Value*/

          BEMF[0] = BEMF[3] = ADC2->JDR1;          /*Read Phase C BEMF Value*/             

          Neutral_Voltage = (BEMF[0] + BEMF[1] + BEMF[2])/3;/*Compute Motor Neutral Voltage */

          temp = BEMF[CurrentCommutationStep];

                   

         /*ZeroCrossing Evaluation*/

    if (((ZC_Polarity == EDGE_RISING) && (temp > Neutral_Voltage)) ||

             ((ZC_Polarity == EDGE_FALLING) && (temp < Neutral_Voltage)))

          {

                     

          CommutationTime = TIM4->CNT;             /*Store ZeroCrossing Time*/

                     

         /*Filter the Current Zero Crossing Time with earlier measurements through an IIR filter*/         

          FiltererdCommutationTime = (IIR_COEFF_A * CommutationTime + IIR_COEFF_B * FiltererdCommutationTime)/

                                     (IIR_COEFF_A + IIR_COEFF_B);

                     

          Commutation_TIM3_CCP1(FiltererdCommutationTime);/*Set TIM4 CCR1 to the Time of the Next Commutation*/

                     

          BEMF_DETECTION_FLAG = FALSE;             /*Disable BEMF Evaluation*/

                     

          }

       }

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

    Current = ADC2->JDR2;                          /*Read Motor Current*/  

   ADC1->SR = ~ADC_SR_JEOC;                       /*Clear Injected channel Flag*/

             

    }

}

Thanks

Posted on March 11, 2013 at 10:39

Shouldn't the ADC2's interrupt source (JEOC) be checked/cleared, too?

JW