Go Down

Topic: detecting rotary switch position change through interrupt (Read 901 times) previous topic - next topic


You could try to do something externally with a comparator and a latch, but it would probably be more complicated than it's worth.  Use a pull-down resistor so that the output goes to gnd when the wiper is not connected to a pole, and set the comparator to signal when its input goes lower than the lowest value of the switch.  Feed that into a latch, and the output of that can go to an interrupt pin.  You'd need to reset the latch after each read, though.

You could do the same thing using the internal analog comparator, if you connect the switch wiper to A0 and feed A1 from a voltage divider. However, this will only work if your switch is break-before-make.

Alternatively, if you can afford to use 3 digital or analog pins instead of a single analog pin, you can use 3 diodes to turn the 5-positions into a binary code on the 3 inputs. Then you can use pin change interrupts to detect transitions.

However, unless you have a requirement to put the mcu to sleep and wake it up when the switch is turned, then it is better to stick with polling. If your project includes an LCD display that can be used to display the current selection, then it may be better to use a rotary encoder instead.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Go Up