[Top][All Lists]

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

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

From: Vincent Trouilliez
Subject: Re: [avr-gcc-list] Two interrupts one function?
Date: Sat, 13 May 2006 18:04:24 +0200

On Sat, 2006-05-13 at 09:28 -0400, Trampas wrote:
> I have two external interrupts connected to a quadature encoder, I do
> the same operations when either interrupt pin is changed. I was
> wondering if it was possible to have one ISR that is called from both
> interrupts. If so how do I do it?

Write a "normal" function and call it from the two ISR's ?
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 
                encoder_count--;        //if not... then must have been CCW !! 

Works like a charm. 
I guess you don't even need an interrupt and could just poll, but since
I had one available and it makes the code so simple, I couldn't justify
not to use it.



reply via email to

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