AnsweredAssumed Answered

2 different rotary encoder on STM32F103

Question asked by paul sauv on May 18, 2018
Latest reply on May 18, 2018 by Jan Waclawek

Hello everyone,

 

I want to run 2 rotarty encoders on my STM32F103. I'm using cubemx.

The first one is a 2000 step rotarty encoder like these: 

1pcs E6B2 CWZ1X 2000P/R encoder for Omron / 2000 line rotary encoder / 2M incremental encoder-in Electronics Production … 

 

I use TIM4:

 

And everything works perfectly

 

and here is my code:

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance==TIM4) //check if the interrupt comes from TIM4
{
if (!(TIM4->CR1 & TIM_CR1_DIR)) MULT1K++;
else MULT1K--;
}

if (htim->Instance==TIM3) //check if the interrupt comes from TIM4
{
if (!(TIM3->CR1 & TIM_CR1_DIR)) pas = pas +5;
else pas = pas -5;
}

}

 

But on TIM3 I use a different encoder type:

Rotary Encoder with Pushbutton Switch | MPJA.COM 

It has only 3 pins

I wired up like this:

Résultat de recherche d'images pour "3 pin rotary encoder stm32"

 

except i didn't used PB6 and PB5

 

and here is my setup:

 

 

Any idea why it's not working?

 

Thank you very much for your help

Outcomes