cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt duplication for AWD1 and EOS flags from ADC1

KErmo
Associate

Hello.

I have a Nucleo board with stm32f302r8. I want to set a state variable for voltage window:

state = STATE_OK if higher threshold > current voltage >  lower threshold

state = STATE_AWD if higher threshold < current voltage or lower threshold > current voltage.

I set up a ADC1 with AWD1 and enable interrupt for AWD1 and EOS flags.

My handler:

void ADC1_IRQHandler(void)

{

   // debug_send(NVIC_GetPendingIRQ(ADC1_IRQn)); //simple uart sender

   if (ADC1->ISR & ADC_ISR_AWD1) {

      // Exclude the cause of the interrupt

      ADC1->ISR |= ADC_ISR_AWD1;

      state = STATE_AWD;

   } else {

      state = STATE_OK;

   }

   ADC1->ISR |= ADC_ISR_EOS; // Exclude the cause of the interrupt

   debug_send(state); // simple uart sender

}

If current voltage has a permissible value then generated only one interrupt.

If current voltage has not a permissible value then generated TWO interrupt:

  1. for AWD1 flag
  2. for EOS flag

I try to read ISPR register (using CMSIS function NVIC_GetPendingIRQ()) and problem disappeared: always generated only one interrupt.

Why?

1 ACCEPTED SOLUTION

Accepted Solutions
KErmo
Associate

I understood.

I have a three ADC conversion:

  1. Potentiometer
  2. Temperature sensor
  3. Internal voltage reference

I have a two flag which generates interrupt:

  1. AWD flag
  2. EOS flag

AWD flag is generated at the same time as the EOC flag. Timing diagram:

0690X000008j9AuQAI.png

Because is generated two interrupts.

Conversion:

  1. DISABLE interrupt from AWD flag.
  2. Clear AWD flag in handler from EOS flag.

ADC Handler:

void ADC1_IRQHandler(void)

{

   if (ADC1->ISR & ADC_ISR_AWD1) {

      ADC1->ISR |= ADC_ISR_AWD1; // Clear flag

      state = STATE_AWD;

   } else {

      state = STATE_OK;

   }

   ADC1->ISR |= ADC_ISR_EOS; // Exclude the cause of the interrupt

   debug_send(state); // uart sender

}

View solution in original post

1 REPLY 1
KErmo
Associate

I understood.

I have a three ADC conversion:

  1. Potentiometer
  2. Temperature sensor
  3. Internal voltage reference

I have a two flag which generates interrupt:

  1. AWD flag
  2. EOS flag

AWD flag is generated at the same time as the EOC flag. Timing diagram:

0690X000008j9AuQAI.png

Because is generated two interrupts.

Conversion:

  1. DISABLE interrupt from AWD flag.
  2. Clear AWD flag in handler from EOS flag.

ADC Handler:

void ADC1_IRQHandler(void)

{

   if (ADC1->ISR & ADC_ISR_AWD1) {

      ADC1->ISR |= ADC_ISR_AWD1; // Clear flag

      state = STATE_AWD;

   } else {

      state = STATE_OK;

   }

   ADC1->ISR |= ADC_ISR_EOS; // Exclude the cause of the interrupt

   debug_send(state); // uart sender

}