Hi, I''m currently making a mobile robot, i use 4 motors with encoder to control the speed through arduino Mega 2560. Are there any ways rather than using AttachInterrupt to read encoder, because there are only 3 ports available for it on Mega, but I have 4 encoders to read.
Thank you.
You can free up pins by using external SPI/I2C encoder ‘chips’.
The run independent counters within the chip, then you read the current value when you need it.
[Google](rotary encoder chip - Google Search]
Another idea…
https://www.elmelectronics.com/wp-content/uploads/2016/07/ELM402DS.pdf
There are 6 pins with external interrupts available on the Mega (2, 3, 18, 19, 20, 21). What is using 3 of those pins?
Encoder needs 2 (Chanel A and B) on each motor.
You can use PCINT on every pin. A common PCINT ISR applies to each port.
The PJRC Encoder Library automatically detects the the capability of each pin specified in it's constructor and selects the best available option from the choices: 2 interrupt-capable pins, 1 interrupt-capable and one polled pin, and 2 polled pins (with performance decreasing in that order).
does it? can't one be tied to an interrupt and the 2nd used to determine direct. yes, half the resolution, but what resolution is required?
Hi, can you tell me more about this, I don't really get what you mean.
Hi, can you tell me more about the tied to an interrupt thing, it''s kinda new to me since this is my first project on Arduino.
I gave you the essential keywords PCINT and ISR which you can search in the forum. AFAIR ISR is described in the Arduino Reference, for PCINT study the AVR controller data sheets. You also will have to learn how to properly use interrupts and shared variables, what not to do when and why. Take some time for a study before proceeding. Come back if you have specific questions.
not sure i was clear. just trying to say that only one encoder output needs to be connected to an interrupt for changes (rise or fall). knowing it went high or low by measuring it and the state of the other pin determine a clockwise or CCW movement and whether position inc/decrements
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.