Interrupt pins

Hi, i'm Fabio and i'd like to know how to connect

  • two motors DC with quadrature encoder
  • one R/C receiver (with four PWM signals)

to Arduino Mega2560 Rev3 .

Each motor/encoder has six wires, two of which are

  • Yellow: encoder A output
  • White: encoder B output

for a total of four wires that must be connected to Arduino for a future closed-loop control.
I read that both Encoder signals and R/C signals have to be linked to the interrupt pins of Arduino.
But in the total there are eight wires (4+4) and my Arduino Mega has only six interrupt pins (2,3,18,19,20,21).
How can i do that?
Thank you in advance for your help

You could use pin change interrupts but in your case you could connect one encoder output to an interrupt pin (p.e. A) and the other (p.e. B) to a normal digital input. You loose a bit of resolution on the encoder but that's probably no problem (you didn't told us what you're doing with that setup).

pylon:
You could use pin change interrupts but in your case you could connect one encoder output to an interrupt pin (p.e. A) and the other (p.e. B) to a normal digital input. You loose a bit of resolution on the encoder but that's probably no problem (you didn't told us what you're doing with that setup).

I've to control an RC wheeled robot, where there are:

  • an electric motor in each of its four wheels
  • two drivers (one for two motors)
  • an R/C receiver
  • Arduino MEGA
  • battery and accesories

I have to make a closed loop speed control of the front DC motors.

If you read Nick Gammons website there are lots of pins that can be used as interrupts.

...R

FabioM:
I read that both Encoder signals and R/C signals have to be linked to the interrupt pins of Arduino.

Firstly, I think that using interrupts for this purpose is a bad idea, even given that the motor generates a ridiculously high rate of output pulses.

Nevertheless, since it uses a Hall effect sensor, you will not have to worry about debouncing and you only need to use one encoder output from each motor since you will already know in which direction the motor is turning. Just ignore the other encoder output completely.

As to the R/C receiver, you would do better to combine all four outputs with a NOR gate and feed the result into a single pin on the Arduino. Much easier to code that way!

Paul__B:
Firstly, I think that using interrupts for this purpose is a bad idea, even given that the motor generates a ridiculously high rate of output pulses.

Nevertheless, since it uses a Hall effect sensor, you will not have to worry about debouncing and you only need to use one encoder output from each motor since you will already know in which direction the motor is turning. Just ignore the other encoder output completely.

As to the R/C receiver, you would do better to combine all four outputs with a NOR gate and feed the result into a single pin on the Arduino. Much easier to code that way!

Firstly thank you very much for your answers.
To sum up, i might connect one encoder output to a normal digital pin of Arduino and let the other one disconnected.
Secondly, as for the R/C receiver, i haven't found on the web an example regarding a four input NOR gate, RC receiver and Arduino.
Would you please help me explaining me how to do that?
Thank you in advance for your help

FabioM:
To sum up, I might connect one encoder output to a normal digital pin of Arduino and let the other one disconnected.

The problem with the gearbox you indicate, is that the encoder is directly on the motor shaft, instead of the output shaft where it should be. 3200 counts (not clearly defined) per revolution of a wheel is plainly ridiculous, quite useless. When I say "not clearly defined", it is not explained whether they mean 64 transitions of both encoders per revolution (as I am pretty sure they do) or 64 complete cycles through the quadrature sequence, which would be four times as many transitions. If it is only 3200 transitions per output revolution, then that is only half as many transitions per encoder, so by ignoring one encoder, you have already halved that number and made it one step more manageable. And therein is the inherent perversity of this arrangement - the motor will not run in other than the direction for which you are powering it, so there is no need whatsoever for the second encoder for the quadrature function, which is intended to sense the direction.

The implication that you need interrupts to count fast pulses is that you may not have time to count them by polling, however executing interrupts takes time in itself and you still have to have code (not in the interrupt routine) to figure out what to do with them all, so even for counting fast pulses, there is relatively little point in using interrupts; a tight polling loop will generally do just as well and be more tractable. The fact is that if you are counting very fast pulses, you will be able to do little else at the same time.

You might do just as well to "condition" each encoder output through a divide-by-32 divider before input to an Arduino.

FabioM:
Secondly, as for the R/C receiver, I haven't found on the web an example regarding a four input NOR gate, RC receiver and Arduino.
Would you please help me explaining me how to do that?

I don't think you will, as decoding four R/C receiver servo outputs into one Arduino is not so common. I could be wrong (Raschammel will know), but if you want to do this the usual way would be to feed the "raw" R/C pulse stream directly into the MCU. As I recall, the standard decoder in a R/C receiver is a single 4017 counter which advances to the next output on each pulse and is reset by a particularly long break. Each output stream is then a single pulse whose length corresponds to the interval between a specific pair of pulses in the input stream. That is a very simple thing for an Arduino to figure out for itself, requiring only one input rather than as many as you have channels. As I come to think of it, you probably do not want to OR the successive outputs, but every alternate one including that after the last one you need to decode so that each pulse is represented as the time between transitions rather than the time between rising edges.

The situation would be similar if the R/C was using PCM.