EmbeddedRelated.com
Forums

Quadrature Encoder

Started by nilesh shirbhate December 25, 2009
Rtstofer said: Saturday, December 26, 2009 1:02 PM
> But I'm going to keep those chips in mind. In fact,
> I may order a few after the first of the year.
> They're pretty inexpensive.

I've used the LSI chips in the past, done software quadrature,
and used the built-in quadrature detectors of the LM629 and the
DSP56F8xxx family. By far, I think quadrature is something best
left to hardware. Not that you can't do it in software if you
are careful to implement the whole state machine. It's just so
often I've seen examples of people trying to get by on the
cheap, and I don't mean cost, I mean effort.

But since having used the DSP56F8xxx family with the quadrature
built-in, where all you have to do is read a memory register to
know where the count is, in 32-bit, with difference register
provided... It is very sweet.

I am now particularly interested in the LPC1768 Cortex M3's
which have quadrature built-in. Haven't used them yet, but think
if they're as sweet as the DSP56F8xxx then I will have to go
that way in the future. Anybody used them yet? And can comment
from experience?

Randy

An Engineer's Guide to the LPC2100 Series

rtstofer wrote:
>
> --- In l..., "Charles R. Grenz" wrote:
>
>> Hi Richard,
>>
>> We currently use the 7366 with a PID loop Td of 4KHz and we control
>> motor speeds from 25rpm to 18,000rpm. The 4MHz SPI maximum is not a
>> problem with this control and using the LPC2148 or even the LPC2103
>> running at 60MHz we can service the timer isr with encoder read in
>> 26us. More then enough time left over for other duties. This is for an
>> BLDC controller we currently sell.
>
> For the 18k RPM, how many PPR are you using?
>
> I think my interest lies with measuring distance from the wheels of a small robot. The RPM won't be very high and neither will the PPR (maybe 32 PPR) so handling this directly with the '2148 seems quite feasible.
>
> But I'm going to keep those chips in mind. In fact, I may order a few after the first of the year. They're pretty inexpensive.
>
> Richard
>
Hi Richard,

The PPR of the encoder is 1K in x4 mode which gives us 4K PPR.

regards,
Charles
rtstofer wrote:
>
> --- In l..., "Charles R. Grenz" wrote:
>
>> Hi Richard,
>>
>> We currently use the 7366 with a PID loop Td of 4KHz and we control
>> motor speeds from 25rpm to 18,000rpm. The 4MHz SPI maximum is not a
>> problem with this control and using the LPC2148 or even the LPC2103
>> running at 60MHz we can service the timer isr with encoder read in
>> 26us. More then enough time left over for other duties. This is for an
>> BLDC controller we currently sell.
>
> For the 18k RPM, how many PPR are you using?
>
> I think my interest lies with measuring distance from the wheels of a small robot. The RPM won't be very high and neither will the PPR (maybe 32 PPR) so handling this directly with the '2148 seems quite feasible.
>
> But I'm going to keep those chips in mind. In fact, I may order a few after the first of the year. They're pretty inexpensive.
>
> Richard
>

Hi Richard,

The original customer wanted to make sure that there was no cogging of
the BLDC motor at 25rpm. We tested as low as 10 rpm with no problems
and was keeping a rpm tolerance below 0.2 rpm from the target speed.

Luminary makes a few ARM processors that have quadrature encoder
interface built in as well. I have not looked into using these much
but they seem promising. They are 32 bit counters.

regards,
Charles
hi,
try the following source code
#include
 void isr(void) __irq
{
 del();                    //CALL DELAY
EXTINT  =0x2;            //CLEAR EINT1 INTERRUPT FLAG
count0++;                //UPDATE COUNT VALUE
VICVectAddr=0XFF;        //MODIFY VECT ADDR REGISTER VALUE
}
void isr(void) __irq
{
 del();                    //CALL DELAY
EXTINT  =0x4;            //CLEAR EINT1 INTERRUPT FLAG
count1++;                //UPDATE COUNT VALUE
VICVectAddr=0XFF;        //MODIFY VECT ADDR REGISTER VALUE
}

int main(void)
{
PINSEL0 |=0xc0|0x80000000;                    //CONFIGURE P0.3,p0.7 AS EINT1 &eint2
EXTMODE=0x6;                         //EINT1 &eint2 EDGE SENSITIVE
EXTPOLAR =0x0;                         //FOLLING ENGE
VICIntSelect &=~(3<<15);                 //SELECT EINT1&eint2 AS IRQ TYPE
VICIntEnable =3<<15;                 //ENABLE EINT1&eint2
VICVectAddr0 =(unsigned long) isr;     //LOAD ISR ADDRESS TO SLOT0 REG(eint1)
VICVectAddr1 =(unsigned long) isr1;     //LOAD ISR1 ADDRESS TO SLOT0 REG(eint2)

VICVectCntl0 =0x20 | 15|16;
count0=0;             ;signnal a
count1=0;              ;signal b
while(1);

}
              Thanks & Regards,

P. ALAGAPPAN
VASEE ELECTRONICS, SALIGRAMAM, CHENNAI -93. www.vaseee.com

--- On Fri, 25/12/09, nilesh shirbhate wrote:

From: nilesh shirbhate
Subject: [lpc2000] Quadrature Encoder
To: l...
Date: Friday, 25 December, 2009, 4:23 PM

 

hi,
I am trying to interface Quadrature Encoder with LPC 2148.
I am using EINT1 and EINT2 (External Interrupt) for Signal A and Signal B.
I have used two ISRs.
Please guide.
Thanks and Regards
Nilesh
 
 

The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.

The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
--- In l..., nilesh shirbhate wrote:
>
> hi,
> I am trying to interface Quadrature Encoder with LPC 2148.
> I am using EINT1 and EINT2 (External Interrupt) for Signal A and Signal B.
> I have used two ISRs.
> Please guide.
> Thanks and Regards
> Nilesh
>
>
>
>
> The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/
>

Look in the Files folder for Quadrature.zip. I'll delete it in a few days.

This LPC2148 example uses EINT0 and EINT2 (because they seemed easiest to use on my board) and the main function loops calling forward and reverse steps. So, the board tests itself.

The transition edges are about 7 uS apart and the code seems to work fine. That is, the expected 40,000 count forward followed by -40,000 followed by 0 comes out right.

This implementation deals with all 4 edges and it is implemented with a small state machine. I leave it to the reader to unencode the state transitions.

This is a "Eureka" version, it has not been tested.

Richard

--- In l..., "rtstofer" wrote:

> Look in the Files folder for Quadrature.zip. I'll delete it in a few days.
There is no doubt that the Makefile will need tweaking. The path to my toolchain is set in the LOCATION macro.

There is reference to an included file for setting up the serial port for lpc21isp.

The file LPC21ISP_PORT contains a single like:
SERIAL_PORT=/dev/ttyUSB0

My laptop doesn't have serial ports and my workstation does (until my dog ate the serial cable this afternoon) so I need a way to change the port depending on which machine I am using.

Oh, and lpc21isp is the programmer of choice. You can get the latest version from the lpc21isp group here on Yahoo. FlashMagic can be used but is not called from the Makefile. You are on your own if you aren't using lpc21isp.

Richard

> The original customer wanted to make sure that there was no cogging of
> the BLDC motor at 25rpm. We tested as low as 10 rpm with no problems
> and was keeping a rpm tolerance below 0.2 rpm from the target speed.
>
> Luminary makes a few ARM processors that have quadrature encoder
> interface built in as well. I have not looked into using these much
> but they seem promising. They are 32 bit counters.
>

Use Sinusoidal pwm signal to drive power stage. It will give a very smooth
motor operation at lower RPM without a high resolution encoder.

Warm Regards,
Mukund Deshmukh,
Beta Computronics Pvt Ltd,
10/1 IT Park, Parsodi,
Nagpur -440022.

>
> --- In l..., "Charles R. Grenz"
> wrote:
>
>> Hi,
>>
>> If you are looking for an external decoder we have been using for
>> years an LSI-CSI part called the LSLF7084. It decodes the A and B
>> channels and produces a Clock and Direction output. It also has a RC
>> input so you can eliminate noise on the inputs.
>>
>> http://usdigital.com/products/interfaces/ics/lfls7084-s/
>>

A small 8 pin micro like 12F615 would do a wonderful job, like eliminate
glitch, produce clock, direction, and increase resolution to 4X, if
required, by combining 2 channel, and generating a pulse on rising and
falling edge.

Some time these micro are very handy..

Warm Regards,
Mukund Deshmukh,
Beta Computronics Pvt Ltd,
10/1 IT Park, Parsodi,
Nagpur -440022.