[Top][All Lists]

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

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

From: Trampas
Subject: RE: [avr-gcc-list] Two interrupts one function?
Date: Sat, 13 May 2006 13:55:44 -0400

The rotary encoder I am using is actually a detented knob. The detents are
at each edge change, therefore I have to detect both edges. 

I was wondering if WINAVR had a way to tell the linker to use the same ISR
function for both interrupts. That is set the vector table such that both
interrupts call the same function. 

Like possibly:
   //my code here

I realize that I could manually set the vector tables, but was looking for a
"clean" solution. 

Thanks again for all the help!


-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of Larry
Sent: Saturday, May 13, 2006 12:31 PM
To: AVR GCC List
Subject: RE: [avr-gcc-list] Two interrupts one function?

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
!! ;-)
| }
| ---------------------------------

AVR-GCC-list mailing list

reply via email to

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