Society of Robots - Robot Forum

Software => Software => Topic started by: mstacho on April 13, 2012, 07:26:36 AM

Title: Quadrature encoder library writing
Post by: mstacho on April 13, 2012, 07:26:36 AM
Howdy,

I'm writing my own quadrature encoder functions as part of a software library (you have NO idea how much I'd rather just use webbot, but I'm doing this on an ARM Cortex and no in in the world has ever written lucid code that I can copy for the cortex :-P )

I've got it ticking and reading on interrupts, which is great, but I'm only getting 1/2 the number of ticks per revolution that I expect.  The basic algorithm is:

ON INTERRUPT
     If: DIRECTION_PIN == 1
            EncoderTicks++
     ELSE
            EncoderTicks--
END

Am I supposed to just add twice?  Or...do BOTH pins act as interrupts?

MIKE
Title: Re: Quadrature encoder library writing
Post by: joe61 on April 13, 2012, 08:25:44 AM
I don't know what processor specifically you're using, but you might need to set it up to get an interrupt on both the rising and falling edges. Just a guess.

Joe
Title: Re: Quadrature encoder library writing
Post by: mstacho on April 13, 2012, 11:43:25 AM
Hm, maybe?  Is that how things normally work with quadrature encoders?
Title: Re: Quadrature encoder library writing
Post by: joe61 on April 13, 2012, 12:02:53 PM
I've only used the Pololu wheel encoders, and that was a long time ago. Each encoder has two sensors 90 degrees out of phase to tell direction. There are two external interrupt pins per encoder, which I think are setup to count both rising and falling edges, but it's been a long time since I used them.

I guess it depends on the encoders you're using.

Not much help I guess, sorry.

Joe
Title: Re: Quadrature encoder library writing
Post by: joe61 on April 13, 2012, 03:19:25 PM
Out of curiosity, what processor are you using?

Joe
Title: Re: Quadrature encoder library writing
Post by: mstacho on April 13, 2012, 06:26:49 PM
It's an ARM Cortex M3 based processor, the STMP103...something or other by ST Microelectronics.  It's a neat little thing, but for the most part I have to do everything from scratch (except PWM, although it's horrifying how complex the code to someone who is used to webbotlib :-P)

On the upside, 1/2 of the counts is all I need, really, since position control can be inaccurate.  I've heard tales of the STM* controllers having encoder inputs on them, although I haven't the foggiest clue of how to use them.  They are, shall we say, poorly documented :-)

MIKE