Thanks for the replies.
I@t1d
I am already multiplexing the pushbutton from the rotary along with some other pins to trigger a wakeup on the other Atmel hardware interrupt pin. That part is easy, since the state of each pin is known when the Atmel is put to sleep. Bit I also need to trigger the wake-up by an encoder rotation and the state of the two pins at "sleep time" is indeterminate. I can't just monitor one pin and wake up when that changes state, since if the other pin is "leading" then I would lose that rotation.
@Peabody
I've already written a rotary encoder library in the past that uses interrupts (
https://github.com/SV-Zanshin/RotaryEncoder) but now I'm putting a specific device together and really want to minimize energy consumption so am trying to leverage the 2 hardware I/O pins which can wake the Atmega chip up; if I kept the processor at a lesser level of sleep I could use pin change interrupts on my pins, but the power savings would be much less.
@Kasper
If I use just one pin I would lose one "tick" if the pin I am watching is not the leading one on the quadrature, and that isn't acceptable for this design. I always avoid excess code in interrupt, but in this case the interrupt is a wake-up one which just re-enables internal registers and is so quick that the standard interrupt handler
I have for the encoder can still register the pin change.
@MasterT
Thanks for code post, but I'm already using similar code in my own library (see link above). Unfortunately many Atmega processors such as the ATMega168 or ATMega 328 only have 2 external interrupt pins that can wake the processor from deep sleep.
But that does give me an idea that might work - if I attach the CW and CWW pins of the encoder to the 2 HW interrupt pins, and also add the output of the pushbutton pin (through a diode) to both pins then a turn or a click would cause one or both to trigger a wake-up.... Oh, but then a pushbutton event during normal processing would simulate an encoder turn... but perhaps I could disconnect that connection after the system wakes up... That does give me food for thought, thanks.
I have a prototype working now for a small breakout board for the 3-color and 2-color LED encoders that is software configurable to output TTL-Serial, SPI, I2C and/or 1-Wire to a controlling processor - eliminating the need for writing code to control the LED and also eliminating having to reserve 6 pins for rotary encoder. The last part left is figuring out how to ensure a timely wake-up from sleep mode and then the prototype will be finished and ready to get miniaturized onto a PCB. If all works out well this might even be productized