Go Down

Topic: What is the maximum frequency I can read from a Quadrature Encoder ?  (Read 3046 times) previous topic - next topic

ggoudreau

Hi everybody,

This is my first post on this forum.

My situation :  I am beginning a new project and it seems like an Arduino could help me to accomplish my goal (I don't own any Arduino yet)

The project is to measure the speed from an encoder attached to a wheel.
The encoder is 10k CPR, which means I will have 40 000 PPR.
Link to the Encoder from US Digital

I am using a high resolution encoder because I want to measure speed as close to 0 mph as possible.

I would like to measure speed from 0 to 2000 RPM. Therefore, the corresponding frequency would be a bit lower than 1.5 MHz.

Is it possible to use a Arduino to measure the signal from an encoder up to 1.5 MHz ?

If yes is it possible to send it back on a CAN bus or send the results as an analog output ?

cattledog

Quote
I would like to measure speed from 0 to 2000 RPM. Therefore, the corresponding frequency would be a bit lower than 1.5 MHz.

Is it possible to use a Arduino to measure the signal from an encoder up to 1.5 MHz ?
You certainly can't get anywhere near those speeds with software on a 16MHz Arduino where it's pushing it to get just under 100K quadrature counts/second. And that's without the processor doing anything else. Take a look at this thread http://forum.arduino.cc/index.php?topic=342499.0

You can get higher interrupt driven performance, with lower resolution, by counting fewer edges. If you use one of the mcu's witjh a faster processor like 84 Mhz, you can pick up more speed, but I doubt you can get to 1.5 MHZ when software driven.

You will need to explore the performance of an external hardware decoder.

ggoudreau

First thank you for taking time to respond to me.

The processor from the Arduino would be used only to read the signal from the encoder and send it back to a CAN bus or an Analog output. (It won't do anything else)

I will read carefully the thread you are referring me too.

From your knowledge, what is the maximum frequency I can achieve with an Arduino ?

CrossRoads

If you were to use a part like this, so you only had 1 stream of pulses to deal with a direction line that didn't change much, you might be able to reach hundreds of KHz depending on how frequently and how much data you were sending over the CAN bus. If you kept it simple, just storing the time from micros() with every positive edge and letting the CANbus side do the RPM math, you might be able to reach pretty high speeds.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

ggoudreau

Thanks again for your help, I was digging a bit further in this forum and found this thread : http://forum.arduino.cc/index.php?topic=140205.15

At the top of the second page, Schwingkpof said that it might be possible to go to rates above 1MHz.

in terms of speed you will then be limited by your interrupt handlers. If you programm cleverly you can get the time to handle the interrupts well below 1us (I can provide code if necessary), meaning that you can detect slopes at rates above 1MHz. If you use more than one encoder you just divide the 1MHz by the number of encoders you'd like to use.

It seems like it would be enough for my project. What do you think about that ?

dlloyd

Quote
I am using a high resolution encoder because I want to measure speed as close to 0 mph as possible.
Just to mention that 40,000 PPR isn't required to measure speed with high precision. For example, a 60 PPR encoder turning at 1 RPM would emit 1 pulse/sec. Each pulse could be accurately timed using micros() to get high resolution speed, updated once per second.

The answers to these requirements would help determine the minimum PPR needed:
What is the required precision for speed?
What is the minimum update interval for speed?
What is the diameter of the wheel?

ggoudreau

I forgot to explain how it will be used.

Mainly it will be use to measure the speed while an object is doing the transition from going backwards to going forward. For example it could be from -10 mph and going to 0 an than going to 10 mph.

In this situation, I will approach a speed of 0. Therefore, I will achieve a situation were the time between 2 pulses will theoretically be infinite. Why it is not possible to measure a speed of 0. 

I choose to use an high resolution encoder to minimize the distance between the pulses. This is what will allow me to measure the smallest speed possible.

The wheel attached to it has a diameter of 12 inches. (I know l would increase the precision of my measurement with a smaller wheel, but I need this size to go over obstacle for other tests)

The required precision for speed measurement is : 0.01 mph

What is the minimum update interval for speed : I don't know how to obtain that (I am not sure to understand what information you want)

cattledog

Quote
At the top of the second page, Schwingkpof said that it might be possible to go to rates above 1MHz.
It seems like it would be enough for my project. What do you think about that ?
I think the Due has proved difficult to master, and there is not the level of knowledge and support as there is for the 8 bit products. In fact, I think the Due has been dropped from the product line. I understand what was posted in your link, but I have not actually seen the clock cycle benchmarks on the processor operations required to enter and exit from an interrupt, independent of what is done within the interrupt handler. I think that even with the difference between 84MHz and 16MHz it will be difficult to get to 1MHz encoder counts with software.

I would recommend pursuing a hardware quadrature decoder as pointed at by Crossroads if you are going to be in a very fast quadrature encoder counting situation.

dlloyd has suggested a very interesting solution where at low speeds you work with interval times between pulses, and transition to pulse counts at higher speeds. You might also consider counting on 1 of the four available transitions at higher speeds, and change to the 4X algorithm at slower speeds if you are using the high resolution encoder.

What is the data and its format that you need to pass on the CAN bus? How frequently do you need to update it? Do you actually need the positive and negative counts from the encoder, and if so, how frequent/fast are the reversals. EDIT: I see from your post that you do.

Another alternative for fast counting might be to feed the encoder pulses into the external clock source of a Timer1. You can read TCNT1 every 20 ms and can read over 3 MHz without coding for overflow counts.




dlloyd

Quote
In this situation, I will approach a speed of 0. Therefore, I will achieve a situation were the time between 2 pulses will theoretically be infinite. Why it is not possible to measure a speed of 0.
You dont need to measure 0 mph. All that's needed is a timeout that occurs at (for example) 0.005 mph, so anything within ±0.005 mph reads 0.00. Now your readings could sequence -0.02, -0.01, 0.00, 0.01, 0.02, etc mph.

Quote
The required precision for speed measurement is : 0.01 mph
For this example, lets use an encoder that's only 1 PPR
The wheel attached to it has a diameter of 12 inches.
The diameter here is 3.14 feet.
0.01 mph = 0.01467 feet/sec
Seconds/revolution(1 pulse) = 3.14/0.01467 = 214.15 seconds
Your timeout for measurement with ±0.005 mph could be 428.3 seconds, 428300000 µs
The function micros() overflows approximately every 70 minutes (no problem here).

Quote
What is the minimum update interval for speed : I don't know how to obtain that (I am not sure to understand what information you want)
If you need to see the speed (mph) update its reading every second at the slowest speed ±0.01 mph, then you'll need an encoder that has at least 214 PPR rating. Higher is OK, but I don't think you need 40,000 PPR

ggoudreau

Thank you everybody, the information you provide are very helpful for me.

I think it is important to specify that I have absolutely no experience with arduino, micro-controller or anything similar. I am a mechanical engineer, but I am interested by a lot of things and I want to learn how to work with those tools. Therefore, sorry if my questions are very basic or if I don't seem to understand what you are trying to explain to me.

I think that this solution might be the best for me :
You might also consider counting on 1 of the four available transitions at higher speeds, and change to the 4X algorithm at slower speeds if you are using the high resolution encoder.
and then switch to the solution propose by dlloyd if this is not enough
dlloyd has suggested a very interesting solution where at low speeds you work with interval times between pulses, and transition to pulse counts at higher speeds.
I am not sure to understand the solution proposed by CrossRoads. The hardware quadrature decoder proposed can be added to the arduino and process the signal ?

ggoudreau

Can someone confirm that to me :

The hardware quadrature decoder proposed can be added to the arduino and process the signal ?
For now I ordered an Arduino UNO and a 12bit DAC module. I think I will be able to do what I want with this combination.

I am still interested to use the hardware solution proposed by CrossRoads previously, it would be nice if someone can give me more information about it.

cattledog

Quote
I am still interested to use the hardware solution proposed by CrossRoads
You may want to take a look at the data sheet for the LS7366 which is an SPI interfaced decoder.

Here are some links to the ls7633R chip on a breakout board, it you don't want to work with the bare chip. It does come in a dip version, but it may be hard to find.  There is some example code linked on the superdroidrobots site .


https://www.superdroidrobots.com/shop/item.aspx/dual-ls7366r-quadrature-encoder-buffer-breakout-board/1523/

http://www.robogaia.com/3-axis-encoder-conter-arduino-shield.html

MarkT

For this sort of quadrature speed I'd go to the propeller chip and rattle up some PASM.  The LS7366 looks
hard to find these days (since every motor driver chip worth its salt comes with built-in
quadrature decoder hardware, there's no need for a separate part).

Regards the actual application, if your system has a lot of inertia, you can get a good estimate of
speed by modelling the system and correcting that model with each incoming edge using
techniques like Kalman filtering - however if you need the actual positional accuracy (40000 cpr
is not cheap), then there is no substiture for a decent encoder.

As encoders get more precise the mechanical precision of the bearings becomes important and
encoders get larger and very much more expensive.   This is really necessary for speed measurement,
just position.

You could have a jockey wheel running on the rim of your 12 inch disk to spin a cheap eBay encoder?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

chrisalbertson



This is an old thread but I had the same problem.   

The solution:  ARM (STM32) chips have HARDWARE quadrature decoders built-in.   So you set up the control registers to assign a quadrature decoder to pins then you can do MHz level encoders with zero software overhead.  The software only needs to monitor the count register.   

Go Up