avr-chat
[Top][All Lists]
Advanced

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

Re: [avr-chat] Using Rotary Encoders...


From: Brian Dean
Subject: Re: [avr-chat] Using Rotary Encoders...
Date: Wed, 21 Sep 2005 01:38:25 -0400
User-agent: Mutt/1.5.9i

On Wed, Sep 21, 2005 at 07:00:30AM +0200, Vincent Trouilliez wrote:

> I pasted the relevant bits of my program below.

What MCU are you using?

> I wired channel B on INT0 and set it to trigger on a rising
> edge. Then in the ISR I increment or decrement the counter,
> depending on the logic level of channel A (going CW or CCW).  That
> worked fine (bar the random glitches). Then I added the 50ms delay
> to see if that would improve things, but no :o( I turn an LED on
> when the pulse/rising edge has been detected, and I turn it off once
> the 50ms delay has elapsed. This produces a short flash which I can
> about see. I just noticed, however, that whenever a glitch happens,
> I get a BIG flash from the LED ! Now what does that mean, I don't
> know exactly, but at least it gives me something to work on...

Not knowing anything else about your encoders, other than they are
mechanical, I would suspect that you need to ensure that your input
lines have pull-ups enabled, and that you keep them enabled.  When you
flash the LED, you are turning on all bits of PORTD, though only one
is needed.  This does enable the pull-ups for all input lines.
However, when you turn off the LED, you are turning off all bits of
PORTD, and thus, disabling the pull-ups for all the pins of PORTD
defined as inputs.

So, first thing to try, IMO, is turn on/off only just the bit you need
for the LED.  Leave all the others alone, i.e,:

     PORTD |= _BV(LED_BIT); /* turn on led */
and
     PORTD &= ~_BV(LED_BIT); /* turn off led */

Where LED_BIT is the bit number (not the mask) of the PORTD pin the
led is connected to.

These would replace the lines where you have PORTD = 0xff, and PORTD =
0x00.

Be sure and enable the pull-up on both input pins when you initialize
the port, i.e., in ioinit():

     DDRD  = 0x20;
     PORTD = ~0x20;  /* all inputs have pull-ups enabled */

What PORT/pin is INT0 of your part?  Be sure and do the same for it.

With the pull-up not enabled all the time, the input pin could be
floating and you might be getting your INT0 interrupt sporadically,
thus causing your mis-counts.

-Brian
-- 
Brian Dean
ATmega128 based MAVRIC controllers
http://www.bdmicro.com/




reply via email to

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