AnsweredAssumed Answered

ADC preventing SysTick timer Interrupt (Why?)

Question asked by slimsly on Mar 10, 2013
Latest reply on Mar 11, 2013 by waclawek.jan
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

Outcomes