2017-03-26 05:09 AM
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 #quadratureSolved! Go to Solution.
2017-03-27 04:24 AM
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!
2017-03-27 04:24 AM
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!
2017-03-27 04:34 AM
Or, use TIM2 or TIM5, they are 32-bit counters.
Done, easier and faster! ;)
JW
2017-03-27 06:43 AM
But that needs thinking before tjhe layout :)
2017-03-27 06:50 AM
This could be tricky because encoder speed is changing.
But this could work.
Thanks
2017-03-27 06:51 AM
I need to check it. I was thinking that only one 32bit counter supports encoder on F411.
2017-03-27 07:04 AM
But that needs thinking before the layout :)
How true. (No smiley. Or maybe a sad one?)
This could be tricky because encoder speed is changing.
You use the minimum time of overflow, of course. Also, if instantaneous readouts are required, this might get a bit tricky.
I was thinking that only one 32bit counter supports encoder on F411.Maybe. You didn't ask for more and I didn't check.
JW
2017-03-27 07:47 AM
Yes, you are right with 32bit counters. Because of that, I'm thinking about moving to F7 with two 32bit counters handling Encoder.
But my intention was to find a way to easily count pulses above counter capability. I was thinking that interruption approach would be the simplest way and efficient one. There are only a few 32bit counters on a microprocessor. So this could be limiting.
SW
2017-03-27 08:49 AM
I was thinking that interruption approach would be the simplest way and efficient one.
No it is not, Uwe told you above: when the input jitters around the over/underflow, and your ISR is not fast enough to capture all of them, you are in trouble. Listen to what he recommends if you desperately want to extend the 16-bit counters.
There are only a few 32bit counters on a microprocessor. So this could be limiting.First you asked for any, then you asked for two. Here you are:
JW
2017-03-28 12:27 AM
Thanks a lot for your help.