6 years, 5 months ago.

Interrupt conflict ?

Hi,

I have connected to an STM32F103 Nucleo-64 board a rotary encoder switch which have two functionalities: - the rotary encoding when you turn the stick - a push button contact when you push the stick

Obviously, I am interested in both: the pulse count and the "clicks".

So I wrote this code: (see full listing at the end of message).

Strangely enough, when I declare These are the pins used by the encoder rotary switch InterruptIn ENCODER_Click(D6); QEI ENCODER_Wheel(D2,D3,NC,624);

the encoder wheel (the pulse count) works but the clicks aren't recorded.

When I swap the two lines These are the pins used by the encoder rotary switch QEI ENCODER_Wheel(D2,D3,NC,624); InterruptIn ENCODER_Click(D6);

the clicks recording works, but the encoder wheel doesn't work anymore.

It makes me believe that the two are using the same interrupt, and that this is the last one declared that wins it all... but I am unsure of this and I found no documentation on this.

Can somebody help me ?

Thanks !

Rotary encoder switch

#include "mbed.h"
#include "QEI.h"

/*******************************************************************************
 * PIN configuration
 *    what component goes where... and what kind of signal is used
 *******************************************************************************/

// These are the pins used by the encoder rotary switch
InterruptIn ENCODER_Click(D6);
QEI         ENCODER_Wheel(D2,D3,NC,624);




/*******************************************************************************
 * CODE SPECIFIC TO THE ENCODER ROTARY SWITCH (SW11 ON SCHEMA)
 *******************************************************************************/
 
 // How many times the click button has been activated since last reset
 int ENCODER_ClickCounter=0;
 
 ///////////////////////////////////////////////////////////////////////////////
 // Reset the rotary switch
 // Parameters:
 //    Options: the sum of those options (or -1 for full option)
 //             1  reset the pulse counter to 0
 //             2  reset the clicked button status to 0
 //             
 // Return:
 //    none
void ENCODER_Reset(int Options)
   {
   if ((Options&1)!=0) { ENCODER_Wheel.reset(); }
   if ((Options&2)!=0) { ENCODER_ClickCounter=0; }
   }

 ///////////////////////////////////////////////////////////////////////////////
 // Has the rotary encoder been clicked since last reset ?
 // Parameters:
 //    Options: the sum of those options (or -1 for full option)
 //             1  reset click counter after reading
 // Return:
 //    0 for never clicked
 //    1 for clicked once
 //    2 for clicked twice
 //    ...
int ENCODER_Clicks(int Options)
   {
   int Answer=ENCODER_ClickCounter;
   if ((Options&1)!=0) { ENCODER_Reset(2); }
   return(Answer);
   }
   
 ///////////////////////////////////////////////////////////////////////////////
 // Rotary click interrupt handler
 // Parameters:
 //    none          
 // Return:
 //    none
void ENCODER_ClickHandle(void)
   {
   ENCODER_ClickCounter+=1;
   }

 ///////////////////////////////////////////////////////////////////////////////
 // Initialise the rotary switch
 // Parameters:
 //    none          
 // Return:
 //    none
void ENCODER_Initialise(void)
   {
   ENCODER_Click.rise(&ENCODER_ClickHandle);
   }




/*******************************************************************************
 * MAIN LOOP
 *******************************************************************************/
 
int main()
   {
   ENCODER_Initialise();
 
   while(1==1)
      {
      printf("------------------------------------\n\r");
      printf("ENC pulses %i\n\r", ENCODER_Wheel.getPulses());
      printf("ENC clicks %i\n\r", ENCODER_Clicks(0));
      wait(1);
      }
   }

2 Answers

6 years, 5 months ago.

D6 is Port B pin 10, D2 is Port A pin 10. These are on the same EXTI line (number 10), so you have to change one of them.

QEI is a software library to handle encoders, but STM32F103 is capable to handle encoders from hardware. You can save CPU cycles here. Check the MCU's documentation.

Accepted Answer

Hi,

sorry for the late answer. I didn't saw there was answer until now (I presume mails got catched by google spam filter or something).

Thanks for this very clear and straightforward answer. I could sort it out by polling the click event instead of using an interrupt, but I am definitely very happy and reassured to know why it didn't worked.

Thank you very much.

posted by Frederic Cloth 13 Jul 2018
6 years, 5 months ago.

Hi Frederic, Could you please check how the External interrupt configuration register is configured on your system? Please refer to RM0008 section 10.2.5 External interrupt/event line mapping . 112 GPIOs can configure 16 interrupts. Since QEI is a library, you may require to configure this.

(https://www.st.com/content/ccc/resource/technical/document/reference_manual/59/b9/ba/7f/11/af/43/d5/CD00171190.pdf/files/CD00171190.pdf/jcr:content/translations/en.CD00171190.pdf)

Please let us know if you have further questions.

Thanks, Naveen Team mbed

Hi,

sorry for the late answer. I didn't saw there was answer until now (I presume mails got catched by google spam filter or something).

I will read the documentation.

I the meantime I resorted to just polling for the clicks and not using the interrupt, which luckily is possible for this project, but I'm happy and reassured to now know why it didn't worked.

Thank you very much.

posted by Frederic Cloth 13 Jul 2018