Processing Motor Encoder data?

231 views
Skip to first unread message

Chris Albertson

unread,
Apr 26, 2017, 1:11:20 PM4/26/17
to hbrob...@googlegroups.com
How are people here handling quadrature encoder reading?    I don't need a 
"How To" explanation just wonder the methods used by most others.

My problem is I have four 37D gear motors for Pololu the each have 64 pulse per revolution quadrature encoders on them.   In the worst case each encoder spins at 11,000 RPM.  This means about 12,000 pulses per second or with all four motors, 48,000 pulses per second.    I'm using an ARM Cortex M as the controller and if it were to get 50K interrupts per second about all it would do is respond to interrupts.

There two basic solutions to this problem.  

(1) Find a way to reduce the interrupt rate.   (Either ignoring some pulses, such as the falling edges, or using more ARM processors up to one per wheel) or

(2) Find a way to handle 50K/second interrupt rate.  (maybe not using the ARM chip and instead using an FPGA.

I found an FPGA development breakout board that is only 6x8 cm in size and costs $13. There are many eBay seller offering this.  See one I selected at random: ....ebay.com/itm/ALTERA-FPGA-Cyslonell-EP2C5T144...

I really DO want encoders on all four wheels.  Not for odometer but for speed control.  If a wheel looses traction under load it will spin if it is not controlled.
--

Chris Albertson
Redondo Beach, California

William Henning

unread,
Apr 26, 2017, 1:24:20 PM4/26/17
to hbrob...@googlegroups.com

I would think the encoders would be on the shaft that is geared down?

if so, that would make them easier to handle.


--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+unsubscribe@googlegroups.com.
To post to this group, send email to hbrob...@googlegroups.com.
Visit this group at https://groups.google.com/group/hbrobotics.
For more options, visit https://groups.google.com/d/optout.

Austin Hendrix

unread,
Apr 26, 2017, 1:26:44 PM4/26/17
to hbrob...@googlegroups.com
I haven't worked with it in quite a while, but I seem to remember that
the timers in my STM32F070 had a quadrature encoder mode that would
handle the encoder input and increment or decrement the timer's counter
without triggering an interrupt, and then I could read the counter from
software as frequently or infrequently as I wanted, and wasn't worried
about losing ticks.

I think you can also get similar encoder receiver peripherals that
handle the counting for you, and I've heard that some of the PICs and
other microcontrollers have similar built-in peripherals.

Happy hunting!
-Austin

On 04/26/2017 10:10 AM, Chris Albertson wrote:
> How are people here handling quadrature encoder reading? I don't
> need a
> "How To" explanation just wonder the methods used by most others.
>
> My problem is I have four 37D gear motors for Pololu the each have 64
> pulse per revolution quadrature encoders on them. In the worst case
> each encoder spins at 11,000 RPM. This means about 12,000 pulses per
> second or with all four motors, 48,000 pulses per second. I'm using
> an ARM Cortex M as the controller and if it were to get 50K interrupts
> per second about all it would do is respond to interrupts.
>
> There two basic solutions to this problem.
>
> (1) Find a way to reduce the interrupt rate. (Either ignoring some
> pulses, such as the falling edges, or using more ARM processors up to
> one per wheel) or
>
> (2) Find a way to handle 50K/second interrupt rate. (maybe not using
> the ARM chip and instead using an FPGA.
>
> I found an FPGA development breakout board that is only 6x8 cm in size
> and costs $13. There are many eBay seller offering this. See one I
> selected at random:
> ....ebay.com/itm/ALTERA-FPGA-Cyslonell-EP2C5T144...
> <http://www.ebay.com/itm/ALTERA-FPGA-Cyslonell-EP2C5T144-Minimum-System-Learning-Development-Board-CA-/142101985664?hash=item2115f03980:g:7%7EYAAOSw5IJWgywx>
>
> I really DO want encoders on all four wheels. Not for odometer but
> for speed control. If a wheel looses traction under load it will spin
> if it is not controlled.
> --
>
> Chris Albertson
> Redondo Beach, California
> --
> You received this message because you are subscribed to the Google
> Groups "HomeBrew Robotics Club" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to hbrobotics+...@googlegroups.com
> <mailto:hbrobotics+...@googlegroups.com>.
> To post to this group, send email to hbrob...@googlegroups.com
> <mailto:hbrob...@googlegroups.com>.

Chris Albertson

unread,
Apr 26, 2017, 1:51:24 PM4/26/17
to hbrob...@googlegroups.com
On Wed, Apr 26, 2017 at 10:24 AM, William Henning <webdev...@gmail.com> wrote:

I would think the encoders would be on the shaft that is geared down?

if so, that would make them easier to handle.

Yes and no.   I'm using Pololu's 100:1 gear reduction motors.  So placing the same kind of encoder on the wheel shaft would reduce the rate by 100.  That is good but. I have one platform like this and the problem is speed control when you are going slow.    You don't get enough pulses per second to control the velocity.   Lets say the wheel is moving at 10 RPM.  That is about 10 pulses per second.   The PID control loop runs at say 5Hz.   I only get on average 2 pulses per control loop cycle and is not a fine enough measure of speed and the motor will "hunt".  One PID loop cycle we see 1 pules and then maybe 3 pulses the next cycle and 2 on the next and so on but with an average of 2.  The PID controller algorithm goes nuts when it sees what looks like a 3:1 velocity change in one 5Hz cycle.   But is is just quantization noise.  

If I were using the encoders only for odometry then having about 60 pulses per wheel just borderline enough.   With 6" diameter wheels the that comes to 0.3 inches per "tick"

Chris Albertson

unread,
Apr 26, 2017, 1:56:15 PM4/26/17
to hbrob...@googlegroups.com
The STM32 has just one quadrature input.  I was planning to use it until I found there is only one. At least that is what I found in the documentation.   I need four.    

Yes I can look for those chips that read quadrature but I wonder if one FPGA might be better?

On Wed, Apr 26, 2017 at 10:26 AM, 'Austin Hendrix' via HomeBrew Robotics Club <hbrob...@googlegroups.com> wrote:
I haven't worked with it in quite a while, but I seem to remember that the timers in my STM32F070 had a quadrature encoder mode that would handle the encoder input and increment or decrement the timer's counter without triggering an interrupt, and then I could read the counter from software as frequently or infrequently as I wanted, and wasn't worried about losing ticks.

I think you can also get similar encoder receiver peripherals that handle the counting for you, and I've heard that some of the PICs and other microcontrollers have similar built-in peripherals.

P Tiago Pereira

unread,
Apr 26, 2017, 2:01:23 PM4/26/17
to HomeBrew Robotics Club
Chris,

I use this 32 bit quadrature chip (SPI): 

2 in a "custom" pcb (attached image)

They are affordable, and easy to use. I think is a waste of micro-controller time to count cycles although you can find a STM32F1 for less than $3.
2015x04x02x12x59x36.JPG

Alex Sy

unread,
Apr 26, 2017, 2:09:40 PM4/26/17
to hbrob...@googlegroups.com
Hi Chris,
Depending on the ARM vendor you are using (like Atmel, ST), some support quadrature encoders directy, although I have only seen up to two.  You could also use the input as timer counter clk to reduce the interrupt rate unless you really need to know the instantaneous speed at each tick.  You could then process it at 10msec interrupt rate to go to your PID which is fast enough for ground vehicles.  This also allows you to accumulate distance travelled (although 16bits may not be much at this rate).  Also note that you do not always need to use a quadrature encoder as a quadrature encoder, ie you may not actually need the direction information since you are controlling it. 
Alex
--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+...@googlegroups.com.
To post to this group, send email to hbrob...@googlegroups.com.

William Henning

unread,
Apr 26, 2017, 2:43:52 PM4/26/17
to hbrob...@googlegroups.com

Neat chip!

On findchips I could only find one source for $25 each.


--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+unsubscribe@googlegroups.com.

William Henning

unread,
Apr 26, 2017, 2:47:33 PM4/26/17
to hbrob...@googlegroups.com

Makes sense.

I would use a P8X32A if I needed quadrature encoding that fast.

Or reduce the PID update rate to 1Hz or less.


--

sdey...@hotmail.com

unread,
Apr 26, 2017, 5:33:55 PM4/26/17
to HomeBrew Robotics Club
I like an CPLDpaired with a microcontroller. Actually, I use a Cool Runner CPLD; don't have to re-image the device every time like an  FPGA


On Wednesday, April 26, 2017 at 1:11:20 PM UTC-4, Chris Albertson wrote:

P Tiago Pereira

unread,
Apr 26, 2017, 5:34:09 PM4/26/17
to hbrob...@googlegroups.com
I remember it was a pain in neck to find a supplier, first i called the manufacturer (http://www.lsicsi.com)  and i asked for a distributor, they gave me the nearest one.

6 from sa...@geminielec.com, $3.95 per unit. 

--
You received this message because you are subscribed to a topic in the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hbrobotics/miAIp0Dm8Yo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hbrobotics+unsubscribe@googlegroups.com.

Wayne C. Gramlich

unread,
Apr 26, 2017, 5:50:42 PM4/26/17
to hbrob...@googlegroups.com, Wayne C. Gramlich
All:

On 04/26/2017 01:11 PM, P Tiago Pereira wrote:
> I remember it was a pain in neck to find a supplier, first i called the
> manufacturer (http://www.lsicsi.com) and i asked for a distributor, they
> gave me the nearest one.
>
> 6 from sa...@geminielec.com <mailto:sa...@geminielec.com>, $3.95 per unit.

The LS7366 chips do work. The only distributer I ever found was Gemini Electronics.
I kind of remember that they had a minimum order of $50+. These days I'd
suggest looking around for microcontroller that has one or two encoders
built in.

Regards,

-Wayne
>
> On Wed, Apr 26, 2017 at 2:43 PM, William Henning <webdev...@gmail.com <mailto:webdev...@gmail.com>> wrote:
>
> Neat chip!
>
> On findchips I could only find one source for $25 each.
>
>
> On Apr 26, 2017 11:01 AM, "P Tiago Pereira" <tiago....@gmail.com <mailto:tiago....@gmail.com>> wrote:
>
> Chris,
>
> I use this 32 bit quadrature chip (SPI):
> http://www.lsicsi.com/pdfs/Data_Sheets/LS7366R.pdf <http://www.lsicsi.com/pdfs/Data_Sheets/LS7366R.pdf>
>
> 2 in a "custom" pcb (attached image)
>
> They are affordable, and easy to use. I think is a waste of micro-controller time to count cycles although you can find a STM32F1 for less than $3.
>
>
>
>
>
> On Wednesday, April 26, 2017 at 1:11:20 PM UTC-4, Chris Albertson wrote:
>
> How are people here handling quadrature encoder reading? I don't need a
> "How To" explanation just wonder the methods used by most others.
>
> My problem is I have four 37D gear motors for Pololu the each have 64 pulse per revolution quadrature encoders on them. In the worst case each encoder spins at 11,000 RPM. This means about 12,000 pulses per second or with all four motors, 48,000 pulses per second. I'm using an ARM Cortex M as the controller and if it were to get 50K interrupts per second about all it would do is respond to interrupts.
>
> There two basic solutions to this problem.
>
> (1) Find a way to reduce the interrupt rate. (Either ignoring some pulses, such as the falling edges, or using more ARM processors up to one per wheel) or
>
> (2) Find a way to handle 50K/second interrupt rate. (maybe not using the ARM chip and instead using an FPGA.
>
> I found an FPGA development breakout board that is only 6x8 cm in size and costs $13. There are many eBay seller offering this. See one I selected at random: ....ebay.com/itm/ALTERA-FPGA-Cyslonell-EP2C5T144... <http://www.ebay.com/itm/ALTERA-FPGA-Cyslonell-EP2C5T144-Minimum-System-Learning-Development-Board-CA-/142101985664?hash=item2115f03980:g:7~YAAOSw5IJWgywx>
>
> I really DO want encoders on all four wheels. Not for odometer but for speed control. If a wheel looses traction under load it will spin if it is not controlled.
> --
>
> Chris Albertson
> Redondo Beach, California
>
> --
> You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+...@googlegroups.com <mailto:hbrobotics+...@googlegroups.com>.
> To post to this group, send email to hbrob...@googlegroups.com <mailto:hbrob...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/hbrobotics <https://groups.google.com/group/hbrobotics>.
> For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "HomeBrew Robotics Club" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/hbrobotics/miAIp0Dm8Yo/unsubscribe <https://groups.google.com/d/topic/hbrobotics/miAIp0Dm8Yo/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email to hbrobotics+...@googlegroups.com <mailto:hbrobotics+...@googlegroups.com>.
> To post to this group, send email to hbrob...@googlegroups.com <mailto:hbrob...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/hbrobotics <https://groups.google.com/group/hbrobotics>.
> For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+...@googlegroups.com <mailto:hbrobotics+...@googlegroups.com>.
> To post to this group, send email to hbrob...@googlegroups.com <mailto:hbrob...@googlegroups.com>.

Osman Eralp

unread,
Apr 26, 2017, 7:55:19 PM4/26/17
to HomeBrew Robotics Club
Chris,

The STM32F4xx series has more timers that should fit your needs. For example, in the STM32F407, TIM2, TIM3, TIM4, TIM5 all have independent DMA request generation. Each is capable of handling quadrature encoder signals. Just make sure you have the timers configured as quadrature inputs not as interrupts. I've used a STM32F4xx to build a robot with four motors with four quadrature encoders. It worked great.

My Robomagellan robot had four motors with four quadrature encoders. It used an off the shelf FPGA board from Demand Peripherals which is designed for robotics. With the Demand Peripherals board, all of the FPGA programming is taken care of for you. You talk to the board using simple Linux commands. It's a great solution if you don't want to design your own PCB. You need a system connected to the Demand Peripherals board that is running Linux, however. I had a Raspberry Pi running Ubuntu on my robot.

Lastly, the STM32F0 might still be a good solution for you. Just use 4 of them. At $1.50 each in single quantity, I bet they are cheaper than any discrete quadrature chip.

Osman

Mark Johnston

unread,
Apr 26, 2017, 8:38:10 PM4/26/17
to HomeBrew Robotics Club

My approach was to form a dual-channel little board with each side using a dsPic30F2010 chip which only has one hardware wheel encoder and also offers PWM with IO for the control lines to a motor controller like the TB6612 driver boards.  TB6612 external allows selection of the 'beef' you need offboard of this controller.   


I talk to each side of this board over I2C and can read wheel encoders or can set PWM for speed control (and a couple other things not related to this discussion)
As of yet I hope to someday put in some PID ability but that never seems to rise high enough to get it done (right).  Each side of the board could control one wheel basically in a PID loop which may happen 'someday'. 

As far as geared motors I agree with Wayne that you put the encoder on the Pololu extended shaft tiny geared motors OR get a DF Robot larger motor with built in encoder also pre-gear down.   That gets you slow speed control.

PS:  Wayne does NOT like PIC chips and I would prefer STM family but now built in hardware encoders.   I know it can be done with timers but have not gone that route yet.

John Tilghman

unread,
Apr 26, 2017, 8:40:25 PM4/26/17
to hbrob...@googlegroups.com
Didn't mean to barge in to the thread, but I thought it might be better than starting a new one.

By the way the chips from U.S. Digital are great and not that expensive.

I know what encoders do, and understand how they work.

What I am not sure of is how to use the information from them ?

EX: Encoder counts ticks as the wheel turns, so that gives me speed. It also can give direction as well.

And can be used to navigate, but what do you do when the ticks overflow ?

Do you reset this counter or counters at some point, and why ?

Or when the wheels change direction, you subtract ticks ?

What if it's a spin in place type deal, so one wheel is counting up and the is counting down ?

I hope this doesn't sound like I don't have a clue about some of this, strangely enough I have an Arlo type robot from Parallax and it runs ROS so it hides much of what is going on.

I am working with OpemCV for computer vision and tracking, and yet this thing with the encoders has me stumped.

Thanks for a great list here.

JT


--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+unsubscribe@googlegroups.com.
To post to this group, send email to hbrob...@googlegroups.com.

Chris Albertson

unread,
Apr 26, 2017, 9:58:22 PM4/26/17
to hbrob...@googlegroups.com
On Wed, Apr 26, 2017 at 5:29 PM, John Tilghman <john.t...@gmail.com> wrote:

And can be used to navigate, but what do you do when the ticks overflow ?

Use a 64 bit counter you can drive for days before it overflows.  

Do you reset this counter or counters at some point, and why ?

Typically a few times per second so you can adjust the speed and update robot's velocity and location 

Or when the wheels change direction, you subtract ticks ?

Yes.  If you go in both directions you counter never overflows. 

What if it's a spin in place type deal, so one wheel is counting up and the is counting down ?

Yes one goes up the other down and when you do the calculations you find you are facing some other direction.   The algorithm knows the width between the wheels.
This also applies to driving around a corner with along radius.   You have to control the velocity of the left and right wheel to keep the turn radius accurate.
 


Ralph Hipps

unread,
Apr 27, 2017, 10:55:49 AM4/27/17
to HomeBrew Robotics Club
speaking of FPGAs, they could be useful for this sort of thing as they are fast and highly parallelizable. You could build 4 or more high speed independent quadrature inputs with large counters, etc., no problem.

You would need to learn Verilog, but the syntax is similar to standard C. 

Here's another board option, 3" x 3" and non-volatile so you don't have to reload it on power up, SW tools are free:

Chris Albertson

unread,
Apr 27, 2017, 12:44:13 PM4/27/17
to hbrob...@googlegroups.com

Thank you all.  Many good ideas.  Keep them coming if there are more.   Now like any engineer I will have to work out a rough design for several of them and estimate size, power, cost and design time.

The FPGA route is a good one.  An advantage is I could likely also do PWM control and the PID loops in the FPGA and it could take the place of the ARM M4 in my design.  VHDL is something I could learn.  The syntax looks familiar but I'm guessing there is some learning curve about how FPGAs work internally.   Syntax is usually the easy part.

Then I find there is an "encoder mode" for the five counters that are built into the STM32F4.  Each timer can be used to directly count motor encoders without interrupts.  Also these encoders implement a digital filter to remove glitches common to encoders.   

So the stand alone encoder chips don't seem to be needed as the same logic is already built into the ARM.   

One more problem to solve is that I need to use the timers for PWM generation to control the motor voltage and I can't use them for encoder reading if using them for PWM.   So it appears that one can control only two motors with an STM32F4.

An FPGA, I'm sure could control all four.   There are a number of FPGA breakout boards in the $20 range that are about 3" square.

I need to find out id those little "minim system M0" boards that sell for $3 have enough timers to handle two motors.  THAT could be the solution, two of those.

If will keep your all informed and if anything generally useful comes out of this I will publish the solution.    First I'll try using the $3 ARM to control two motors using PID using serial commands (I2C or SPI ?)

--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+unsubscribe@googlegroups.com.
To post to this group, send email to hbrob...@googlegroups.com.
Visit this group at https://groups.google.com/group/hbrobotics.
For more options, visit https://groups.google.com/d/optout.

Osman Eralp

unread,
Apr 27, 2017, 2:58:01 PM4/27/17
to HomeBrew Robotics Club
Chris,

One STM32F407 has enough timers for four quadrature inputs and four PWM outputs.Without knowing your other design criteria, I'd say the STM32 would be a simpler solution.

Osman

sdey...@hotmail.com

unread,
Apr 27, 2017, 6:15:44 PM4/27/17
to HomeBrew Robotics Club
Here's a nice FPGA that goes along with a RaspberryPi: http://www.bugblat.com/products/pif/

And another nice stand-alone one: https://embeddedmicro.com/mojo-v3.html

I've used both.


On Wednesday, April 26, 2017 at 1:11:20 PM UTC-4, Chris Albertson wrote:

Chris Albertson

unread,
Apr 27, 2017, 8:01:13 PM4/27/17
to hbrob...@googlegroups.com
These seems to be all over eBay for about $13 shipped

Looks like just the FPGA chip a voltage regulator and headers for the pins

I like the one that fits in the Pi3 header, cuts down on a lot of wiring and likely noise that wire would pick up.

--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+unsubscribe@googlegroups.com.
To post to this group, send email to hbrob...@googlegroups.com.
Visit this group at https://groups.google.com/group/hbrobotics.
For more options, visit https://groups.google.com/d/optout.

Ralph Hipps

unread,
Apr 28, 2017, 1:09:38 AM4/28/17
to hbrob...@googlegroups.com
my free advice that's worth the price, learn Verilog, not VHDL. There are religious issues at play here, many die hard fans on either side, but I've used both, and I MUCH prefer Verilog, a lot easier to learn and less verbose.

but either if fine, both are supported by the compiler, etc.


Ralph

>+<
 |    /\
 |___/  \
 [_@_]   `<
 O O O   
      IRS!
------------------------------------------------------------------------------------
In the twenty-first century, the robot will take the place
which slave labor occupied in ancient civilization.
 -- Nikola Tesla
------------------------------------------------------------------------------------


--
You received this message because you are subscribed to a topic in the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hbrobotics/miAIp0Dm8Yo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hbrobotics+unsubscribe@googlegroups.com.

Andy Jang

unread,
Apr 29, 2017, 1:27:55 AM4/29/17
to hbrob...@googlegroups.com

Pololu also has 37D motors with encoders depending on rpm needs.

37d-mm-metal-gearmotors

On Thu, Apr 27, 2017 at 5:00 PM, Chris Albertson <alberts...@gmail.com> wrote:

Chris Albertson

unread,
Apr 29, 2017, 12:01:52 PM4/29/17
to hbrob...@googlegroups.com
Yes, these 37D motors are exactly the ones I am using.  I'm using the ones with a 100:1 gear reduction and some rubber tires that are made for scale model "Monster Trucks"
Pololu's specs turn out to be conservative.   They are more powerful than I need

On Fri, Apr 28, 2017 at 9:00 PM, Andy Jang <aj48...@gmail.com> wrote:

Pololu also has 37D motors with encoders depending on rpm needs.

37d-mm-metal-gearmotors

Steve Liren cheng

unread,
Apr 29, 2017, 6:32:47 PM4/29/17
to hbrob...@googlegroups.com
I did a little bit digging on my robot which has two ActoBotics motors with encoders. I used a simple Arduino UNO to read encoders output. One interrupt per motor. So at speed of 268mm/second, my robot gets 3618 interrupts per motor which results in 3618x2 = 7238 interrupts per seconds. My basic Arduino UNO whose CPU is running at 16MHz is doing a good job in handling 7K interrupts per second.

cheers,

Steve

--

Chuck McManis

unread,
May 2, 2017, 1:19:10 AM5/2/17
to hbrob...@googlegroups.com
Not sure whose ARM chip you are using but the ST Micro ones have a 'quadrature' mode on the timer/counter. You hook your encoder up to that and the timer will count up when its running one way and down when it is running the other. You can then interrupt based on getting to a particular count or every 'n' counts etc. 

--Chuck


--

Chris Albertson

unread,
May 2, 2017, 2:23:15 AM5/2/17
to hbrob...@googlegroups.com
Thank you.  I just read about the encoder mode.   As I type this I'm experimenting with an Nucleo F401RE and I have 8 interrupts wired up to four quadrature encoders and I'm about to spin them all up to 11,000 RPM.  It might work.

The problem with the F401RE is a lack of counter/timers.     I think there are enough timers for two motors on my F401RE.   I think I need an M7 to handle four motors where each motor has both PWM and an encoder.    Do I have this right?  I should need 8 counter/timers to handle four motors

I'll know by tomorrow if the F401RE can handle the 48,000 interrupts per second rate and still do anything else.

I want to try the quadrature mode.  If I can get it to work in the F401RE then I will order some F7xx type Nucleo, unless there is some physically smaller M7 board.

Ralph Gnauck

unread,
May 2, 2017, 3:47:24 AM5/2/17
to hbrob...@googlegroups.com
There is no lack of timers on the 401 chips!

Timer 1 alone will drive 4 independent PWM outputs at one time.

Timers 2,3,4,5 can be quadrature encoders 
That still leaves 3 more for the PID loop timing etc.

I have used 401 chips to drive 4 motors with encoders no problem.


Ralph


From: Chris Albertson <alberts...@gmail.com>
To: hbrob...@googlegroups.com
Sent: Monday, May 1, 2017 11:23 PM
Subject: Re: [HBRobotics] Processing Motor Encoder data?

To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+...@googlegroups.com.

Chuck McManis

unread,
May 2, 2017, 1:00:20 PM5/2/17
to hbrob...@googlegroups.com
Hi Chris,

I've been using the various M-4 variants (F407, F446, F412, F469, F412) in different projects, and as Ralph says there are a lot of timers on these things. If you're coming from an AVR background it can be confusing because one timer can do several things at once. (not quite as flexible as the old Coldfire timer processing unit but pretty good). There are a bunch of appnotes from ST on using these chips to control DC motors. It is one of the things they have been pushing of late.

The F7 is nice but it is dangerously close to slipping over the complexity curve into the painful side. Already I have seen a couple of issues with its caches and people expecting things to work and forgetting to invalidate caches and stuff. That is where it gets a bit weird. I don't believe I saw what your overall goal was here.

--Chuck
 

Chris Albertson

unread,
May 2, 2017, 2:50:29 PM5/2/17
to hbrob...@googlegroups.com
OK, to start over. This is the top level goal. It is a multi-level
control robot. I'm working now on the first level and very slowly on
the third level



(1) level one: I want to have an ARM "M" running an RTOS control a
four wheel drive mobile platform and a few basic sensors (IMU, and a
couple collusion detectors). This platform will have a few built-in
test programs, a simple human interface using a 2x16 LCD and will be
able to "mindlessly" wonder and not bump into walls or people. I've
decided to use the "mbed" platform as the RTOS. Mbed is a layer over
the CMSIS-RTOS Keil RTX. Mbed makes programming about as easy as
Arduino IDE but under the hood it is RTX. The motors and IMU,
battery monitoring, power management and ultrasonic sensors all work
under the mbed RTOS.


(2) Second level: The above platform becomes a ROS node using ROS
Serial. ROS runs on a Raspberry Pi3 and handles navigation. So now
the platform "knows" where it is on the map. and the Pi3 provides WiFi
3D sensors and GPS connect directly to the Pi3 not the F401RE

(3) level three: I'm working on a expert system planner, writing in
Prolog. Prolog is very good at searching a database of rules and
facts. This is the top level control. It runs (for now) on a
multi-core Intel i7 processor that I hope to integrate with the Pi3 on
the platform using WiFi. This system will have access to other
platforms, for example a fixed IP security camera.

The over all goal is to have Prolog string together a sequence of
actions that are primitive enough that ROS can execute them. What's
good about Prolog is it is NON-Procedural. I just have to state the
desired outcome.

For now I want to get #1 "done right" so I'm experimenting. It looks
like the F401 can handle 50,000 interrupts per second but (A) I don't
know how this effects foreground tasks and (B) It would be nicer to
use the quadrature hardware. I just have to learn how to do it under
mbed/RTX. I want to re-use this same controller platform and the #2
Pi based controller for another mobile platform with different
physical design. (using two 700 mm bicycle wheels, statically
balanced)

Current state of devilment is a 1x6 pine board with motors zip tied in
place, h-bridges nailed to board along with F401RE and a billion
Dupont wires. I was happy to find that my H-bridges (VNH2SP30) and
the hall effect encoders on the 37D Pololu motors all work at 3.3
volts so I removed the level shifters.

One sort-of problem: Four gear motors running at full sped are NOISY.
not electrically but the sound is not acceptable outside of a
development lab. The problem is the spur gears. I will need to find
something that uses helical gears and or belts

I do have a CS degree and 20+ years of professional software
development experience but it is all with large computers, mainframes
and server rooms. So I'm learning. many little things, like I just
found out about logic analyses. The $12 Saleae clone is worth 10X
the price.
>>>> an email to hbrobotics+...@googlegroups.com.
>>>> To post to this group, send email to hbrob...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/hbrobotics.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "HomeBrew Robotics Club" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to hbrobotics+...@googlegroups.com.
>>> To post to this group, send email to hbrob...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/hbrobotics.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>>
>> --
>>
>> Chris Albertson
>> Redondo Beach, California
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "HomeBrew Robotics Club" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to hbrobotics+...@googlegroups.com.
>> To post to this group, send email to hbrob...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/hbrobotics.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "HomeBrew Robotics Club" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to hbrobotics+...@googlegroups.com.

Chris Albertson

unread,
May 3, 2017, 1:24:35 PM5/3/17
to hbrob...@googlegroups.com


Update.  

(1) Just FYI, an STM32F401 has no trouble handling a total of 50,800 interrupts per second spread over 8 digital inputs while at the same time running a second task to blink a LED and another to write debug data over a virtual serial terminal using USB.

(2) About using timer quadrature mode.  This would be preferred but searching forum posting tells the processor platform I'm using can only read TWO encoders and I need to read FOUR.   The limit is because (a) not all pins are lead out to headers and (b) the OS needs to use TIMER5. 

I do need to use a really available low cost board that is plug and play programmable from any PC or Mac with no programmer device.  

Alex Sy

unread,
May 3, 2017, 4:15:23 PM5/3/17
to hbrob...@googlegroups.com
Hi Chris,
If you do not actually need direction (which is actually quite common since you control the motor direction), you can feed one of the quadrature outputs as a clock to a timer.  This means that you need to have 4 timers (for 4 motors) which is often available.  Then use a system timer that interrupts at some regular PID time like 1000 or 100 times per second, to read all four timer counts, compare against previous counts to get the change, and then perform the PID loop.  The interrupt rate becomes a very manageable rate.  The second quadrature output is not used.  Then another timer which has 4 compare registers can then drive 4 PWM outputs as motor drivers.  I use this method to run on 8 bit as well as 32 bit processors and it has very light CPU loading.
Alex
 
 
----- Original Message -----
--

Andy Jang

unread,
May 3, 2017, 6:08:14 PM5/3/17
to hbrob...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+unsubscribe@googlegroups.com.

Chris Albertson

unread,
May 3, 2017, 7:12:07 PM5/3/17
to hbrob...@googlegroups.com
TheBeagle board is a Cortex A and runs Linux.  I need an M type that can run an RTOS.

As I wrote below, I verified that the STM32F401 can easily handle 50,000 interrupts per second and at the same time run multiple tasks and send data to vertical console over USB.   I might have CPU power to spare.

I will have a Raspberry Pi 3 on board in addition to this STM32F401.

Andy Jang

unread,
May 3, 2017, 7:46:29 PM5/3/17
to hbrob...@googlegroups.com
Hi Chris,

Found some interesting reading about motors controllers.

Tips-Motor-Control-using-PWM-and-PID

STM32F401 microcontrollers

Have you done some labs on the key components?


-andy



>>>> To post to this group, send email to hbrob...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/hbrobotics.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "HomeBrew Robotics Club" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an

>>> To post to this group, send email to hbrob...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/hbrobotics.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>>
>> --
>>
>> Chris Albertson
>> Redondo Beach, California
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "HomeBrew Robotics Club" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

>> To post to this group, send email to hbrob...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/hbrobotics.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "HomeBrew Robotics Club" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> To post to this group, send email to hbrob...@googlegroups.com.
> Visit this group at https://groups.google.com/group/hbrobotics.
> For more options, visit https://groups.google.com/d/optout.



--

Chris Albertson
Redondo Beach, California

--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+unsubscribe@googlegroups.com.

Chris Albertson

unread,
May 3, 2017, 9:36:14 PM5/3/17
to hbrob...@googlegroups.com
On Wed, May 3, 2017 at 4:27 PM, Andy Jang <aj48...@gmail.com> wrote:
Hi Chris,

Found some interesting reading about motors controllers.

Tips-Motor-Control-using-PWM-and-PID

This is one of the best tutorials on the subject.  Easy to read.   But he does leave out stuff one would need in a real-world controller.   In particular how to make the system stable and at the same time responsive to changes of the set point.    And his description of tuning is weak.  He says basically "change the parameters until they work starting with P"  

I've done this a few times before.  It is really common in the world of motion control.  The only question was the BEST way to get the quadrature signal into the processor.   Most people use Interrupts.   I've gotten that to work.   BUT, it was pointed out by several that the processor (STM32F401) has on-board quadrature decoders that would do the work most people do in software.   Basically it off loads the process to dedicated on-chip hardware.    This sounded very attractive but as it turns out there is not enough hardware on my board to use this method.  So I use Interrupts for now.   I could change out the board if something small, inexpensive and well supported is found.    (I don't think the BBB has quadrature decode hardware.)

It would be good to hear about your experience with RTOS on Beagle Boards and about the tool chain used.   I've got two BBB here and both are set up to boot Ubuntu Linux but I'm not using them because Raspberry Pi 3 is vastly more powerful as a Linux machine.    I could find a use for a BBB tuning an RTOS on a free toolchain.
Reply all
Reply to author
Forward
0 new messages