[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Two interrupts one function?

From: Larry Barello
Subject: RE: [avr-gcc-list] Two interrupts one function?
Date: Sat, 13 May 2006 09:31:06 -0700

Depending what you are doing, the function, below, will have problems.  To
avoid false counts with mechanical jitter near the transition point you need
to interrupt on both the leading and trailing edges with appropriate inc/dec
logic depending upon the edge.  All external interrupts and ICP and ACI
interrupts have selectable leading/falling edge select, so even with a small
chip you can get quite a few encoders going. 

Larry Barello

| -----Original Message-----

| Beside, do you really need two external interrupts ?
| I use a quadrature encoder in my current project, and one interrupt pin
| is enough and the code is ridiculously simple !
| -------------------------------
| #include "encoder.h"
| static volatile int8_t encoder_count;
| //ISR to handle the rotary encoder
| {
|       if ( PIND & _BV(PD6) )          //if Channel B is high
|               encoder_count++;        //then the knob has been turned
|       else
|               encoder_count--;        //if not... then must have been CCW
!! ;-)
| }
| ---------------------------------

reply via email to

[Prev in Thread] Current Thread [Next in Thread]