measure the speed of several encoder with one arduino board

Hi
I want to measure the speed of 3 encoders which are connected in one Arduino Due board
and I use FreqMeasure library
for one encoder I could use this library but for 3 encoders I have no idea how to use this library, please help

How many edges/ per second/ per encoder do you have to catch ?

ard_newbie:
How many edges/ per second/ per encoder do you have to catch ?

Do you mean how many frequencies measured and take the average for each encoder?

No, what is the maximum number of edges/ per second/ per encoder you will have to record ?

ard_newbie:
No, what is the maximum number of edges/ per second/ per encoder you will have to record ?

30

3 Attachinterrupt() will do the trick nicely then.

ard_newbie:
3 Attachinterrupt() will do the trick nicely then.

for 1 encoder I use this code:

#include <FreqMeasure.h>



void setup() {
Serial.begin(9600);
FreqMeasure.begin();

}
int count = 0;
double sum;

void loop() {
  if (FreqMeasure.available(){
    sum = sum + FreqMeasure.read();
    count = count +1;
    if (count>30){
      float frequency = FreqMeasure.countToFrequency(sum/count);
      Serial.println((double) frequency/200*60);
      sum = 0;
      count = 0;
}
}

but for 3 encoders I don't know how to write the code!!

Does this freqMeasure library even support multiple instances? If not, look for another library that does. Or write your own routine, it's pretty simple. All you have to do is measure the time between two ticks.

wvmarle:
Does this freqMeasure library even support multiple instances? If not, look for another library that does. Or write your own routine, it's pretty simple. All you have to do is measure the time between two ticks.

I don't know how to write my own routine, could you help me, please?

I want to measure the speed of 3 encoders which are connected in one Arduino Due board
and I use FreqMeasure library

How did you get FreqMeasure to work with a Due?

cattledog:
How did you get FreqMeasure to work with a Due?

I have used this library with Uno but now I want to read the speed of three encoders and I want to use Due because of all of the digital pins of the Due board are interrupts, if I couldn't use this library please help how could I write a code to read the speed (even the position ) of three encoders,thanks

You can not use that library with a Due.

how could I write a code to read the speed (even the position ) of three encoders,thanks

You are advised to do some research before coming with a question. See Point 4 in
https://forum.arduino.cc/index.php?topic=148850.0

Depending on the type of encoder there are many different tutorials on how to read them with an Arduino. At 30 counts/second, you could probably use an Uno like you have with pinChange interrupts.

What are you going to do with the speed/or position given by the encoder?

cattledog:
You can not use that library with a Due.
You are advised to do some research before coming with a question. See Point 4 in
How to use this forum - please read - Website and Forum - Arduino Forum

Depending on the type of encoder there are many different tutorials on how to read them with an Arduino. At 30 counts/second, you could probably use an Uno like you have with pinChange interrupts.

What are you going to do with the speed/or position given by the encoder?

thanks for your help I have searched before and I just get some information about how to read the position and speed of one encoder which is installed in one arduino board, but now I want to read position and speed of three encoders which are installed in one arduino board, and I want to use them in a serial communication with matlab to control 3 dc motors

The place to start is with one encoder and without using FreqMeasure. Lets see what you can come up with for one encoder.

cattledog:
The place to start is with one encoder and without using FreqMeasure. Lets see what you can come up with for one encoder.

is it possible to help me please I have not enough time to try and test, my time to doing my project is going to be over

cattledog:
The place to start is with one encoder and without using FreqMeasure. Lets see what you can come up with for one encoder.

and after searching I get to use Encoder and FreqMeasure libraries to read the position and the speed of the encoder

is it possible to help me please I have not enough time to try and test, my time to doing my project is going to be over

I have been involved with two encoder threads you have started since January. I'm sorry if you have run out of time, but I am not going to write code for what looks like an academic project.

https://forum.arduino.cc/index.php?topic=591307.msg4021585#msg4021585

https://forum.arduino.cc/index.php?topic=598391.0

cattledog:
I have been involved with two encoder threads you have started since January. I'm sorry if you have run out of time, but I am not going to write code for what looks like an academic project.

reading the encoder pulses without the Encoder library - Sensors - Arduino Forum

counting rotary encoder pulses in both direction - Project Guidance - Arduino Forum

but for the speed of the encoder, I don't know how to do without freqmeasure library,I mean if I use the counting pulses how I could write the time in the code to makes these counts to counts per second?

koronus:
but for the speed of the encoder, I don't know how to do without freqmeasure library,I mean if I use the counting pulses how I could write the time in the code to makes these counts to counts per second?

there is no way to help me ?
I used rotaryEncoder order in matlab and with this order I could read the position and the speed of the encoder but the problem is when speed rises the encoder would be disconnect and I have to read the speed with Arduino program and read that with serial communication in matlab , so if it is possible help me to write the code in the arduino program to read the speed ,just guide me how I could add the time in the code for counting pulses per second (????second???)

As said, simply record the time. Use micros() for better resolution.

pulseReceived = micros();
timeTaken = pulseReceived - previousPulseReceived;  
speed = distance / timeTaken;
previousPulseReceived = pulseReceived;

That's how you calculate the speed - it's really that simple. For position, add a counter that you increase every time you receive a pulse, that's even simpler:

counter++;

Besides, there must be hundreds of code examples on various blogs with detailed explanation how that code works. Reading encoders for speed/position is a very common thing.

At 30 pulses a second you don't even need interrupts, some proper programming and polling the pins should give you the count without any issues, and probably even a pretty accurate speed. Interrupts does make it a bit simpler in this case, but be aware that pin change interrupts react to both rising and falling edges.

So time for you to do your homework and get to work!