The title is quite self descriptive. I ask this question because I found contradicting information in the atmel web page. I need two external interrupts to control one rotary encoder. One interrupt control pulses from one pin (both rising and falling) and the other iterrupt the same for the other pin. So if I has only 1 it doesn't work for me.

  • \$\begingroup\$ How fast does the encoder change? I had an awful time trying to make a quickly changing encoder function with interrupts, and moved to a controller that handled encoder inputs more directly (pic 18f4331, in this case). Interrupts are fine for things like frob knobs, but if you're looking at fast turning motors you might look at a chip designed to handle them. \$\endgroup\$ – Scott Seidman Jul 17 '13 at 21:19
  • \$\begingroup\$ It's a knob, 4 pulses in each position, 20 positions each turn. My guess is 300 pulses per second tops beign very fast with the fingers. I got it working quite well in the ATmega32U4 of the arduino leonardo. But I'm using 2 interrupts, and that's the problem with the attiny85. Thanks anyway, I didn't tought about it. \$\endgroup\$ – Terrik Jul 17 '13 at 22:07
  • \$\begingroup\$ No problem, then! \$\endgroup\$ – Scott Seidman Jul 17 '13 at 22:07

There's INT0, and then there's PCINT[0:5]. INT0 gets its own interrupt routine, and the PCINT has one routine for all the pins configured to be used by the interrupt. That means that one of the first thing the interrupt routine needs to do is figure out which pin(s) actually changed to trigger the interrupt. Should actually be more convenient to use this way for your encoder, as you really want any encoder change to trigger the same interrupt routine.

I have no idea if all this is accessibile through the arduino platform, or if you need to program the controller yourself (as I'm not an Arduino user).

  • \$\begingroup\$ I'll try this using the arduino interface. If it doesn't work I'll have to get my hands dirty programing making use of the native avr libs. Thanks it really helps. \$\endgroup\$ – Terrik Jul 18 '13 at 8:54

You can do this with a single interrupt if necessary by ORing the two pins into the one interrupt ("something changed"). You'll still need two digital inputs to read the encoder pins, and the ISR (or an exec-level helper routine) will have to take on the responsibility of figuring out which encoder pin(s) changed, but it's doable.

  • \$\begingroup\$ I had a hard time reading the pins after the interrupt is called. It was my firts aproach. The encoder bounces, and you maybe read when is not stable. I let it as a last resource. Thanks \$\endgroup\$ – Terrik Jul 18 '13 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.