encoder interface using mbed.....

21 Mar 2010

Hi,

The Led's which are connected to the board are pin no 34 & 37 (i am considering only two port pins ) which are also encoder i/p to the microcontroller.......i was planning to remove the led's and give my encoder input's ......please suggest me if i am going wrong........

 

The other issue is about the programming part . The online compiler doesnt support quadrature encoder interface(i mean no built in library for encoder) .......So suggest me any offline line compiler for the same......

21 Mar 2010

Hi Dhaval,

I would also like a quadrature interface but alais there isn't one yet. I did play about with using hardware interupts to achieve this with limited sucess using a 2500 line encoder. The code was...

void PinChange() {
    if(LastA!=PhaseA){    //A change on Phase A has occured
        if(PhaseA==0){
            if(PhaseB==1)
                Count--;
            else
                Count++;}
        else
            if(PhaseB==0)
                Count--;
            else
                Count++;}           
    else if(LastB!=PhaseB){    //A change on Phase B has occured
        if(PhaseB==0){
            if(PhaseA==0)
                Count--;
            else
                Count++;}
        else
            if(PhaseA==1)
                Count--;
            else
                Count++;}   
    LastA=PhaseA;
    LastB=PhaseB;           
    }

I'm sure a good software guy could do a lot better but this did work, as long as you didn't spin the encoder too fast!

21 Mar 2010

Hi Dhaval,

Dhaval Shah wrote:
i was planning to remove the led's and give my encoder input's ......please suggest me if i am going wrong........
Assuming you know what you are doing, and don't expect any warranties etc, go for it! I'd love to see the results.

Dhaval Shah wrote:
The online compiler doesnt support quadrature encoder interface(i mean no built in library for encoder) .......So suggest me any offline line compiler for the same......
You are correct that there is no built in library for the quadrature encoder, but you can still have a go at writing one like you would other code; no real relation to being online/offline. In fact, all the mbed libraries were written in the mbed online compiler! Eat your own dogfood! So it obviously possible, unless I didn't understand a special requirement you have.

The quadrature encoder register structure is already available in the mbed library as part of the CMSIS library. See:

From this and the pointer definition LPC_QEI, you can see you can just access the registers (e.g. the QEICON) like:
#include "mbed.h"

int main() {
    LPC_QEI->QEICON = 0;
} 
Does this makes sense and answer your question? It'd be great to see the quadrature encoder working, as we never had a chance to look at it.
Simon
21 Mar 2010

Hi Simon

Using a function like QEI that is not in the mbed library requires a little research, of which getting the CMSIS  register names is just the first step. Getting QEI is on my to do list and so I have made a start by building this crib.

/*------------- Quadrature Encoder Interface (QEI) ---------------------------*/
		CMSIS Name			Handbook Name	Function

572	typedef struct
573	{
574	  __O  uint32_t QEICON;		// QEICON		( Control)
575	  __I  uint32_t QEISTAT;	// QEISTAT		( Status)
576	  __IO uint32_t QEICONF;	// QEICONF		( Configure)
577	  __I  uint32_t QEIPOS;		// QEIPOS		( Position)
578	  __IO uint32_t QEIMAXPOS;	// QEIMAXPOS		( Max Position)
579	  __IO uint32_t CMPOS0;		// CMPOS0		( Position Compare 0)
580	  __IO uint32_t CMPOS1;		// CMPOS1		( Position Compare 1)
581	  __IO uint32_t CMPOS2;		// CMPOS2		( Position compare 2)
582	  __I  uint32_t INXCNT;		// INXCNT		( Index Count)
583	  __IO uint32_t INXCMP;		// INXCMP		( Index Compare)
584	  __IO uint32_t QEILOAD;	// QEILOAD		( Velocity Timer Reload)
585	  __I  uint32_t QEITIME;	// QEITIME		( Velocity Timer)
586	  __I  uint32_t QEIVEL;		// QEIVEL		( Velocity Counter)
587	  __I  uint32_t QEICAP;		// QEICAP		( Velocity Capture)
588	  __IO uint32_t VELCOMP;	// VELCOMP		( Velocity Compare)
589	  __IO uint32_t FILTER;		// FILTER		( Digital Filter)
590	       uint32_t RESERVED0[998];
591	  __O  uint32_t QEIIEC;		// QEIIEC		( Interrupt Enable Clear)
592	  __O  uint32_t QEIIES;		// QEIIES		( Interrupt Enable Set)
593	  __I  uint32_t QEIINTSTAT;	// QEINTSTAT		( Interrupt Status)
594	  __I  uint32_t QEIIE;		// PCQIE		( QIE Interrupt Enable = 1 Disabled = 0)
595	  __O  uint32_t QEICLR;		// QEICLR		( Interrupt Status Clear)
596	  __O  uint32_t QEISET;		// QEISET		( Interrupt Status Set)
597	} LPC_QEI_TypeDef;

	/*--------------------- Other Regs ----------------------------*/
	LPC_SC->PCONP			// PCONP		( Power Enable)
	(not found)			// PCLK_QEI		
	(PINSEL and PINMODE regs not found)	//			
	(NVIC registers CMSIS name not found) 		

The idea is to match the CMSIS register names with the names used in the User Manual and the register function. You will see that I still have some work to do in the Other Register part at the bottom of the table. With the table complete, writing code is a do-able task.

It is not exactly like decoding Linear B, but there are similarities.

22 Mar 2010

Hi ,

Thank you all for your guidance . I have started the work on Red Suite 3 evaluation version provided by red code .

Please let me know if there are problems faced if any using the evalution version.

 

Regards,

 

Dhaval

11 Oct 2010

does the QEI library that is available online use the native QEI interface or just hardware interrupts?  Would the native QEI system be faster than the generic hardware interrupts?

Thanks

12 Oct 2010

I believe the QEI library on http://mbed.org/cookbook/QEI doesnot use the on chip QEI hardware

12 Oct 2010

I think Rahul is correct, the cookbook example just uses interrupts. If you were able to use the built in QEI harware on the LPC1768 it would be much quicker and more reliable.

12 Oct 2010

has anyone tried this?  I thought I read that one of the encoder inputs was used as a blue LED?    I am looking at creating a PID servo brushed motor controller and want the fastest encoder input whether thats interrupt based or built in QEI.   I basically am using the library QEI encoder in and a small H-bridge output boardlet with a small brushed motor for testing.  Anyone else doing a project like this??

 

31 Oct 2017

i think the qei library mbed library doesn t have the best priority for the interuption ,why i have some loses pulses count

i talk about this http://mbed.org/cookbook/QEI