Skip to main content
Stefan Wozniak
Associate III
March 26, 2017
Solved

How to get interrupt on counter overflow with Quadrature Encoder with Cube and HAL?

  • March 26, 2017
  • 2 replies
  • 4393 views
Posted on March 26, 2017 at 14:09

Hi,

I want to use Timer with Quadrature Encoder. I'm new on STM32 so I'm trying to start with Cube and HAL.

I'm able to setup STM32F411 to count pulses but there is an only 16bit counter. I need to measure pulses up to 400k.

Can I rise interrupt on counter overflow to store revolutions? I want to do this using Cube and HAL. I was trying a lot of settings and interrupts but I'm unable to get interrupt from an encoder.

Can you help me?

Thanks in advance.

Steve

#cube #cube-mx #quadrature-encoder #stm32-cube #stm32f411 #quadrature
This topic has been closed for replies.
Best answer by Uwe Bonnes
Posted on March 27, 2017 at 13:24

There is no such interrupt. However there also is no need for that interrupt and a Jitter at the position of that interrupt would be harmful. Depending on the maximum count rate, determine the time needed to count 2^16 pulses. Mostly this will be several ten or hundreds of Milliseconds. Be sure to call a  function every less than half of that time that calculates the difference between that last and the presen counter value and add these differences up to a 32 bit value. Done!

2 replies

Uwe Bonnes
Chief
March 27, 2017
Posted on March 27, 2017 at 13:24

There is no such interrupt. However there also is no need for that interrupt and a Jitter at the position of that interrupt would be harmful. Depending on the maximum count rate, determine the time needed to count 2^16 pulses. Mostly this will be several ten or hundreds of Milliseconds. Be sure to call a  function every less than half of that time that calculates the difference between that last and the presen counter value and add these differences up to a 32 bit value. Done!

Stefan Wozniak
Associate III
March 27, 2017
Posted on March 27, 2017 at 13:50

This could be tricky because encoder speed is changing.

But this could work.

Thanks

waclawek.jan
Super User
March 27, 2017
Posted on March 27, 2017 at 13:34

Or,  use TIM2 or TIM5, they are 32-bit counters.

Done, easier and faster! ;)

JW

Uwe Bonnes
Chief
March 27, 2017
Posted on March 27, 2017 at 13:43

But that needs thinking before tjhe layout :)