High-performance Encoder

hello.
I am trying to use encoders for my (input device) design. It is going to include 6 optical relative encoders (they work similarly to mechanical relative encoders). Which have output of 4 possible states: 00, 01, 11, 10
Where 00 and 11 are typically where normal “notch” encoders will sit. Which is irrelevant since my optical encoders will have no notch.
(ideal/targeted optical encoder output)
image
(generic mechanical encoder output)
image
Since the encoders may be spinning very quickly (200rpm, 12 notch per rev, 2400 Hz/4800Hz diff), what is the best way to maximize the poll/scan performance? There is not really a mcu that have 12 hardware interrupts, nor I think it is absolute relevant since the waveform will be offset to one another by (hopefully) exact 50%

hm. I can also use hall effect sensors. That can simplify designs.

Continued posts about your project might find a better audience that is larger than just Arduboy, as it doesn’t really seem to have anything to do with it.

1 Like

I’m sure there are many that do.

The ATmega328P, used on the Arduino UNO, can generate an interrupt on every one of its GPIO pins. There are 20 GPIO pins available on the UNO.

I was pouring over the (extremely lengthy) 32U4 datasheeet searching for “interrupt” (1034 occurances) and after about an hour still have absolutely no clue on how the pin interrupts work.

I tried to go without interrupts and got satisfying results – because my (planned) encoder doesn’t “click” and have a 50% offset. I am able to get in 60 “clicks” per second on my mechanical encoders (with detent), which is 120 per second when there is a simulated “load” of 5ms.

I also worked on the TI Launchpad Kit (MSP432p or something) and on that chip it says “you can use one interrupt per port”. So I am assuming there would be a similar limit on other mcus as well. But as far as I have learned there is 1 bit reserved for hardware interrupt (aside from reset, usb, timer, i2c) and we have exactly one PCINT (pin change interrupt)

Unlike the ATmega328P, the ATmega32U4 can’t generate a pin change interrupt on every pin. Pin change interrupts are only available on Port B (PB0-PB7), so you have eight of them. You also have four INTx interrupts available on Port D (PD0-PD3). So that gives 12 interrupts that could be used for 6 rotary encoders.

The INTx interrupts have a separate vector for each. The pin change interrupts (PCINT0-7) all share one interrupt vector so the interrupt service routine for them has to read a register to determine which pin(s) actually changed to generate the interrupt.

3 Likes

Ah. I see that on the Datasheet.
Unfortunately that also means that I will lose SPI if I want.
Why do they do that? I2C too. Why?
From the block diagram PB123 is attached to the portB driver whi… oh. So it connects directly to the SPI rather than having to go through the data bus. That make sense.
This also means that I will want to disconnect whatever that is attached to PB0123 if I want to ICSP it. Port F have Jtag and technically PorDBE all have Interrupt … ah found it. Page 77 describe “additional capabilities” and seems like PD have “fastest” interrupt but they are INT (they only interrupt when they go high)
Hmm!
(browsing other Arduino products)
The Due and Zero (ARM based) have very impressive capabilities regarding IO.

The primary reason I stuck with the 32U4 is that it’s “powerful enough” for most tasks but not overtly powerful (like a ARM3X8E or RP2040 would), and it have built-in USB which I assume means faster transports. Which I think for a USB controller is desirable. And look like it’s “not cutting it” in terms of hardware interrupts.
We can get away with a Micro or others since PB have 5 pins other than SCK CIPO and COPI but on the Leonardo one of them go to RXLED.
Where is INT5 and 4?
I guess we will just do without interrupts for now. If it is not satisfactory I will use the Arduino Zero.

What do you think Logitech uses on their mouse?

No. Look at section 11.1.1 of the datasheet on page 89. You can set each INTx to trigger on any edge (as well as low level, falling edge or rising edge).

1 Like

It would probably depend on the mouse. Low end models might use a dedicated mouse IC. Higher end might use a microprocessor but there are so many possibilities that you would have to look and hope it’s something that can be identified.

1 Like

Perfect. This allows for 4 encoder without too much hassle. Thats much better as it allows a full set (XYZ or RxRyRz)