This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Starterware/STARTERWARE-SITARA: eqep driver

Part Number: STARTERWARE-SITARA

Tool/software: Starterware

Hey everyone,

i 'm facing some trouble trying to use the eqep module of my beaglebone white. My goal is to print how much the encoder has rotated.

Following is a part of my code which builds successfully but when loaded to my board which is connected to a quadrature encoder, it doesn't work as expected.

//
#define EQEP_QPOSCNT 			(0x0)
#define EQEP_QPOSINIT 			(0x4)
#define EQEP_QPOSMAX 			(0x8)
#define EQEP_QDECCTL 			(0x28)
#define EQEP_QEPCTL  			(0x2A)
#define EQEP_QEINT 			(0x30)
#define EQEP_QFLG 			(0x32)
#define EQEP_QDECCTL_XCR 		(0x0800u)
#define EQEP_QDECCTL_XCR_SHIFT 		(0x000Bu)
#define EQEP_QDECCTL_QRSC_SHIFT 	(0x000Fu)
#define EQEP_QDECCTL_QRSC 		(0xC000u)
//
HWREG(SOC_EQEP_1_REGS+EQEP_QPOSCNT) = 0x00000000;
HWREG(SOC_EQEP_1_REGS+EQEP_QPOSINIT)=0x0000;
HWREG(SOC_EQEP_1_REGS+EQEP_QPOSMAX) =2500000;
HWREG(SOC_EQEP_1_REGS+EQEP_QDECCTL) = (HWREG(SOC_EQEP_1_REGS+EQEP_QDECCTL) & (~EQEP_QDECCTL_XCR)) | ((1 << EQEP_QDECCTL_XCR_SHIFT) & EQEP_QDECCTL_XCR);
HWREG(SOC_EQEP_1_REGS+EQEP_QDECCTL) = (HWREG(SOC_EQEP_1_REGS+EQEP_QDECCTL) & (~EQEP_QDECCTL_QRSC)) | ((2 << EQEP_QDECCTL_QRSC_SHIFT) & EQEP_QDECCTL_QRSC);
HWREGH(SOC_EQEP_1_REGS+EQEP_QEPCTL) = 0x1000;
HWREGH(SOC_EQEP_1_REGS+EQEP_QEINT) = 0x0000;
HWREGH(SOC_EQEP_1_REGS+EQEP_QFLG) = 0x0000;

while(1)
  {
      current_pos = HWREG(SOC_EQEP_1_REGS+EQEP_QPOSCNT);
      UARTprintf("counts = %d \n", current_pos);
  }   

The message i get printed though is counts=0 or whatever value i give to EQEP_QPOSINIT register, no matter how much the encoder has rotated...

Assuming that i have enabled all the necessary modules (such as uart, power domain, clocks, gpio module etc) and that  i have done the proper pin-muxing, is something wrong with the above?
I mean, based on this code, shouldn't  i get printed, the incrementation of the position counter (which is my goal)?
Does anyone have any suggestion or can point out any mistake?
Also, do i have any way to check if the eqep module is actually and properly enabled?
Please, i am desperate for some help..

Thanks in advance.

  • Following code is working smoothly for me:

    PWMSSModuleClkConfig(1); // for EHRPWM1 and EQEP1
    
    // initialisation
    HWREGH(SOC_EQEP_1_REGS+QEP_QDECCTL)=0x0800;
    HWREGH(SOC_EQEP_1_REGS+QEP_QEPCTL) =0x1038;
    HWREG(SOC_EQEP_1_REGS+QEP_QPOSMAX) =0xFFFFFFFF; 
    HWREG(SOC_EQEP_1_REGS+QEP_QPOSINIT)=0x7FFFFFFF; 
    HWREGH(SOC_EQEP_1_REGS+QEP_QCAPCTL)=0x0000;
    
    // enable clock
    HWREG(SOC_PWMSS1_REGS + PWMSS_CLOCK_CONFIG) |= PWMSS_QEP_CLK_EN;
    
    // Pin MUX for QEP
    MUX_VAL(CONTROL_PADCONF_LCD_DATA13, (IEN | PD | MODE2 ))
    MUX_VAL(CONTROL_PADCONF_LCD_DATA12, (IEN | PD | MODE2 ))
    
    // reset counter
    HWREGH(SOC_EQEP_1_REGS+QEP_QEPCTL) =0x10B8;
    
    HWREGH(SOC_EQEP_1_REGS+QEP_QEPCTL)=0x10B8; // reset MOTF counter, does not matter when no MOTF is used
    
    currQEPosition=HWREG(SOC_EQEP_1_REGS+QEP_QPOSCNT)-0x7FFFFFFF;
    

    Finally currQEPosition contains the quadrature encoder count - so calling the last line repeatedly should be your solution.

  • Thanks a lot qxc for your reply!

    i am going to test it as soon as possible, but if it is no problem for you, could you please clarify some issues i have with your code, for my better understanding?
    Firstly, i have noticed that you reset the counter twice, is that a mistake or does it serve a purpose?Or do i have to reset it more than once, maybe after some specific conditions?
    Moreover, could you explain to me why you abstract 0x7fffffff from QPOSCNT value?
    Also, you have used the MUX_VAL function...which i am not sure i can find somewhere in starterware..is it a custom function you made?Is it like GpioPinMuxSetup?

    I am truly thankful for your help!!!

  • Resetting of the counter does not have to be done twice, this happened because I simply copied my existing code.

    0x7fffffff is specific to my application but may be useful for you too - when currQEPosition is a signed integer and your encoder starts counting in reverse direction, you will see negative position valius too.

    The MUX_VAL functions indeed are related to pin-muxing, when you do not have enabled them as inputs for eQEP, you will not receive any pulses for counting.
  • Thanks a lot qxc!

    my mistake was in not fully activating eqep module and the qepctl register's value...anyway your help was really useful !!!

    Thanks again