Author Topic: STM32 capable tracking 3 quadrature encoders?  (Read 2074 times)

0 Members and 1 Guest are viewing this topic.

Offline ace1903Topic starter

  • Regular Contributor
  • *
  • Posts: 237
  • Country: mk
STM32 capable tracking 3 quadrature encoders?
« on: October 18, 2019, 01:47:58 pm »
I have old milling machine with 3 Heidenhain encoders.
Would like to make display that will show position in 3 coordinates and will run some algorithm in background.

Ideally some nucleo board will fit perfectly in this project.
But I can not find STM32 with more than 2 timers capable to work in quadrature mode decoding.

Does someone knows STM micro with such capabilities?
I have alternative with small FPGA as interface but prefer everything to be on STM  if possible.
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4664
  • Country: dk
Re: STM32 capable tracking 3 quadrature encoders?
« Reply #1 on: October 18, 2019, 01:59:53 pm »
I have old milling machine with 3 Heidenhain encoders.
Would like to make display that will show position in 3 coordinates and will run some algorithm in background.

Ideally some nucleo board will fit perfectly in this project.
But I can not find STM32 with more than 2 timers capable to work in quadrature mode decoding.

Does someone knows STM micro with such capabilities?
I have alternative with small FPGA as interface but prefer everything to be on STM  if possible.

STM32F411 (and probably others) an do 4  (tim2,tim3,tim4,tim5) two of the timers are only 16 bit but it is simple to safely extend that in SW

 

Offline ace1903Topic starter

  • Regular Contributor
  • *
  • Posts: 237
  • Country: mk
Re: STM32 capable tracking 3 quadrature encoders?
« Reply #2 on: October 18, 2019, 02:15:32 pm »
Forgot to mention , resolution is few um so 16 bit is quickly overflowed.
But anyhow, looking at pin list I can see only two pairs of encode capable pins.
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15219
  • Country: fr
Re: STM32 capable tracking 3 quadrature encoders?
« Reply #3 on: October 18, 2019, 02:28:57 pm »
Do the decoding in software. It's not hard.
 
The following users thanked this post: thm_w

Online langwadt

  • Super Contributor
  • ***
  • Posts: 4664
  • Country: dk
Re: STM32 capable tracking 3 quadrature encoders?
« Reply #4 on: October 18, 2019, 03:34:18 pm »
Forgot to mention , resolution is few um so 16 bit is quickly overflowed.
But anyhow, looking at pin list I can see only two pairs of encode capable pins.

a look at my code says; PA0,PA1 - PA5,PB3 - PB4,PB5 - PB6,PB7

add some code similar to this, and as long as the 16 bit count doesn't wrap more than once between ticks
it should be safe

Code: [Select]
volatile int32_t pos1;
volatile int32_t pos2;
volatile int32_t pos3;
volatile int32_t pos4;

void SysTick_Handler(void)
{
int16_t tm3   = 0;
int16_t tm3dif   = 0;
static int16_t tm3_d = 0;

int16_t tm4   = 0;
int16_t tm4dif   = 0;
static int16_t tm4_d = 0;

pos1 = TIM2->CNT;
pos2 = TIM5->CNT;

tm3 = TIM3->CNT;
tm3dif = tm3-tm3_d;
pos3 += tm3dif;
tm3_d = tm3;

tm4 = TIM4->CNT;
tm4dif = tm4-tm4_d;
pos4 += tm4dif;
tm4_d = tm4;

}



https://github.com/langwadt/nucleo_quad4
« Last Edit: October 18, 2019, 03:52:16 pm by langwadt »
 

Offline lucazader

  • Regular Contributor
  • *
  • Posts: 221
  • Country: au
Re: STM32 capable tracking 3 quadrature encoders?
« Reply #5 on: October 20, 2019, 06:42:07 pm »
You can also setup this up so that on a timer over/underflow an interrupt will trigger, so you can immediately handle this.
 

Offline Retirednerd2020

  • Regular Contributor
  • *
  • Posts: 73
  • Country: us
Re: STM32 capable tracking 3 quadrature encoders?
« Reply #6 on: November 13, 2019, 12:25:59 am »
The STM32F446 can do six.  Four are 16 Bit, two are 32 Bit.  TIM1,3,4,8 and TIM2,5 respectively.   Similar code to extend to 32 or more bits can be used as mentioned above.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf