• AVR Freaks

Hot!dspic33CK256MP506- QEI1 resets POS1CNTL counter every 32768 pulses

Author
JJAYAR
Starting Member
  • Total Posts : 34
  • Reward points : 0
  • Joined: 2011/11/30 20:40:39
  • Location: 0
  • Status: offline
2020/05/24 21:30:34 (permalink)
0

dspic33CK256MP506- QEI1 resets POS1CNTL counter every 32768 pulses

-Reposting - did not include code correctly last time!! - my mistake!!
Have configured QEI1 for quadrature encoder read
For some reason the 16 bit position register (POS1CNTL) resets itself every 32768 pulses
The POS1HLD never changes value(stays=0)
 

long int count;
 
long int posn[2000];//array to store values from counter register
..
while(1)
{
      count = POS1CNTL;//read lower register only for now
      if(count >= 0)
     {
        Blue(1);//light up led once motor shaft starts turning
        if(i < (dataArraySize-2))
        {
           posn[i] = count;//store count in an array to observe later
        }
      i++;
     Delay(4200);//add delay so motor gets a chance to turn
   }
   else
   Blue(0);//shut led
 
}//end while 1

 


 

This is how I am setting up the QEI1 module
RP64 = A, RP65 = B & RP66=I
void SetupEncoder1()
{
//ENCODER CONTROL REGISTER
QEI1CONbits. QEIEN = 0;//disable the encoder
QEI1CONbits.PIMOD = 0;//INDEX BIT does not effect counter
QEI1CONbits.QEISIDL = 0;//CONTINUE WHEN IDLE #13
QEI1CONbits.IMV = 0;//INDEX BIT does not effect counter
QEI1CONbits.INTDIV = 0x0; //freq divisor
QEI1CONbits.CNTPOL = 1;//counter is positive by default
QEI1CONbits.GATEN = 0;//gate not enabled
QEI1CONbits.CCM = 0;//quadrature
QEI1IOCbits.QCAPEN = 0;//home event does not capture position
QEI1IOCbits.FLTREN = 1;//filter enabled
QEI1IOCbits.QFDIV = 0x2;//filter freq divide
QEI1IOCbits.OUTFNC = 0;//out function disabled
QEI1IOCbits.SWPAB=0;//do not swap AB
//signal polarities
QEI1IOCbits.HOMPOL=0;//home polarity not inverted
QEI1IOCbits.IDXPOL=0;//index polarity not inverted
QEI1IOCbits.QEAPOL=0;//A polarity not inverted
QEI1IOCbits.QEBPOL=0;//B polarity not inverted
//
QEI1IOCbits.INDEX=1;
QEI1IOCbits.HOME=1;
QEI1IOCbits.QEA=1;
QEI1IOCbits.QEB=1;
//
QEI1STATbits.POSOVIEN=1;//position counter overflow interrupt enable
QEI1STATbits.VELOVIEN=1;//vel counter overflow

//Interrupt
IFS3bits.QEI1IF = 0;//clear long int flag
IEC3bits.QEI1IE = 0;//keep disabled interrupt


//ASSIGN ENCODER PINS
RPINR14bits.QEIA1R = 64;//RP64 = encoder input pin A
RPINR14bits.QEIB1R = 65;//RP65 = encoder input pin B
RPINR15bits.QEINDX1R = 66;//RP66 = encoder input pin I

//INitialize all registers
POS1HLD = 0X00;//pos hold reg
POS1CNTL = 0X00;//posn count low
POS1CNTH = 0x00;//posn count hi

INDX1HLD = 0x00;//index count hold reg
INDX1CNTH = 0x00;//index count high reg
INDX1CNTL = 0x00;//index count low reg

VEL1CNT = 0X0;
INT1TMRH = 0x00;//interval timer Hi bit
INT1TMRL = 0x00;//interval timer Lo bit
INT1HLDH = 0x00;//interval timer hold High
INT1HLDL = 0x00;//interval timer hold Lo
QEI1ICH = 0x00;//Initialization/capture HI
QEI1ICL = 0x00;//Initialization/capture Lo

QEI1CONbits.QEIEN = 1;//enable the encoder
}
 

 
Was wondering if anyone else has encountered such a situation
Could not understand why POS1CNTL was behaving like a signed 16bit register
Any comments appreciated
Thank you in advance
 
Jay
post edited by JJAYAR - 2020/05/24 23:24:06
#1

3 Replies Related Threads

    XorLor
    Junior Member
    • Total Posts : 72
    • Reward points : 0
    • Joined: 2009/10/23 00:17:05
    • Location: 0
    • Status: offline
    Re: dspic33CK256MP506- QEI1 resets POS1CNTL counter every 32768 pulses 2020/05/24 23:09:24 (permalink)
    0
    JJAYAR
     
    For some reason the 16 bit position register (POS1CNTL) resets itself every 32768 pulses
    The POS1HLD never changes value(stays=0)

     
    I'm not sure what you mean by "pulses". QEA/QEB pulses? The POS1CNT should increment/decrement on each change of state for QEA and QEB. Are you saying the POS1CNTL never goes above 32768?
     
    Does the POS1CNTH register change?
     
     
     
    #2
    JJAYAR
    Starting Member
    • Total Posts : 34
    • Reward points : 0
    • Joined: 2011/11/30 20:40:39
    • Location: 0
    • Status: offline
    Re: dspic33CK256MP506- QEI1 resets POS1CNTL counter every 32768 pulses 2020/05/24 23:29:39 (permalink)
    0
    Hi XorLor - thank you for replying
    To answer your first question
    1) As QEA & QEB from encoder keep coming in, the POS1CNT keeps increasing till it reaches 32768 & then instead of going to 32769 it goes to 0 & starts counting up again
     
    2) POS1CNTh (POS1HLD) never changes from 0
     
    Jay
    #3
    Batgoy
    Starting Member
    • Total Posts : 33
    • Reward points : 0
    • Joined: 2004/06/15 04:33:51
    • Status: offline
    Re: dspic33CK256MP506- QEI1 resets POS1CNTL counter every 32768 pulses 2020/06/16 03:51:11 (permalink)
    0
    Try to increase QFDIV
    #4
    Jump to:
    © 2020 APG vNext Commercial Version 4.5