Hot!QEI Setup on the dsPIC33EP512GM710

Author
joshua.cochran
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2018/09/25 07:40:46
  • Location: USA
  • Status: offline
2018/10/02 10:53:45 (permalink)
0

QEI Setup on the dsPIC33EP512GM710

Hello all,

I am working on a project where I have setup an ADC that samples and then sends the sample buffer back over UART. I have setup this with the MCC, however, I am also working on setting up a feedback control system with a encoder and the QEI interface.

Since the QEI is not supported by the MCC, I have coded the setup myself. Currently, the issue that I am having is that the POS1CNTL and POS1CNTH registers do not increase when spinning the encoder. I have the UART printing the POS1CNTL register and the register value is 1 when spinning the encoder and 0 when it is stopped. My encoder does not have an index input.
#include <p33EP512GM710.h>

void InitializeQEI() {
    QEI1CONbits.QEIEN = 1; //Enable Module
    QEI1CONbits.QEISIDL = 0;
    QEI1CONbits.PIMOD = 0;
    QEI1CONbits.CNTPOL = 0;
    QEI1CONbits.CCM = 1;
    QEI1STATbits.POSOVIEN = 1; //Enable overflow interrupt
}

Modified MCC code:
#include <xc.h>
#include "pin_manager.h"

/**
    void PIN_MANAGER_Initialize(void)
*/
void PIN_MANAGER_Initialize(void)
{
    /****************************************************************************
     * Setting the Output Latch SFR(s)
     ***************************************************************************/
    LATA = 0x0000;
    LATB = 0x0000;
    LATC = 0x0000;
    LATD = 0x0000;
    LATE = 0x0000;
    LATF = 0x0000;
    LATG = 0x0000;

    /****************************************************************************
     * Setting the GPIO Direction SFR(s)
     ***************************************************************************/
    TRISA = 0xDF93;
    TRISB = 0x3FEF;
    TRISC = 0xBFFB;
    TRISD = 0xF17E;
    TRISE = 0xF303;
    TRISF = 0x36F3;
    TRISG = 0xF3CF;

    /****************************************************************************
     * Setting the Weak Pull Up and Weak Pull Down SFR(s)
     ***************************************************************************/
    CNPDA = 0x0000;
    CNPDB = 0x0000;
    CNPDC = 0x0000;
    CNPDD = 0x0000;
    CNPDE = 0x0000;
    CNPDF = 0x0000;
    CNPDG = 0x0000;
    CNPUA = 0x0800;
    CNPUB = 0x0000;
    CNPUC = 0x0001;
    CNPUD = 0x0000;
    CNPUE = 0x0000;
    CNPUF = 0x0000;
    CNPUG = 0x0200;

    /****************************************************************************
     * Setting the Open Drain SFR(s)
     ***************************************************************************/
    ODCA = 0x0000;
    ODCB = 0x0000;
    ODCC = 0x0000;
    ODCD = 0x0000;
    ODCE = 0x0000;
    ODCF = 0x0000;
    ODCG = 0x0000;

    /****************************************************************************
     * Setting the Analog/Digital Configuration SFR(s)
     ***************************************************************************/
    ANSELA = 0xD213;
    ANSELB = 0x0383;
    ANSELC = 0x143F;
    ANSELD = 0xC000;
    ANSELE = 0xF303;
    ANSELF = 0x3630;
    ANSELG = 0x81CC;


    /****************************************************************************
     * Set the PPS
     ***************************************************************************/
    __builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS

    RPINR18bits.U1RXR = 0x0018; //RA8->UART1:U1RX;
    RPOR1bits.RP36R = 0x0001; //RB4->UART1:U1TX;
    //Configure QEI
    RPINR14bits.QEA1R = 121; //0x0079; //Pin #14
    RPINR14bits.QEB1R = 127; //0x007F; //Pin #21
    //RPINR15bits.INDX1R = 0x0030; //Pin #32
   
    __builtin_write_OSCCONL(OSCCON | 0x40); // lock PPS

}

What I am I doing wrong here? The end goal is to use the VEL1CNT register to determine the speed of rotating machinery.
#1

12 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 2249
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: QEI Setup on the dsPIC33EP512GM710 2018/10/02 13:15:19 (permalink)
    0
    What encoder are you using?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    joshua.cochran
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/09/25 07:40:46
    • Location: USA
    • Status: offline
    Re: QEI Setup on the dsPIC33EP512GM710 2018/10/02 13:22:41 (permalink)
    0
    This is a AVAGO HEDS-5605-G06 encoder with two channels, no index pulse and 360 PPR
    #3
    du00000001
    Just Some Member
    • Total Posts : 2249
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: QEI Setup on the dsPIC33EP512GM710 2018/10/02 13:30:32 (permalink)
    5 (1)
    Could it be that only one of the channels is connected correctly? Which would explain a "count forth, count back" scheme that you seem to have currently. An indication would be that the CNT_DIR would change with every edge on the working channel.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #4
    joshua.cochran
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/09/25 07:40:46
    • Location: USA
    • Status: offline
    Re: QEI Setup on the dsPIC33EP512GM710 2018/10/03 07:13:26 (permalink)
    0
    Thanks for the advice, this makes sense why the system only responds when it's in the External UP Down Mode (CCM = 1).
     
    What happens is that POS1CNTL goes to 0xFFFF immediately after turning the encoder, and then counts down no matter which direction I turn the encoder. After removing the QEIA channel the counts still go down. Basically it looks like my QEIA channel has a problem.
     
    Is there a way to directly access the CNT_DIR?
    #5
    du00000001
    Just Some Member
    • Total Posts : 2249
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: QEI Setup on the dsPIC33EP512GM710 2018/10/03 07:42:21 (permalink)
    5 (1)
    Unfortunately there seems to be no way to make CNT_DIR accessible  :(
     
    Revisiting your setup, I'd suggest to set CCM to 0 (not 1) !
    Might immediately solve your problem.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #6
    joshua.cochran
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/09/25 07:40:46
    • Location: USA
    • Status: offline
    Re: QEI Setup on the dsPIC33EP512GM710 2018/10/03 07:44:29 (permalink)
    0
    If CCM = 0, the POSCNT register switches between 0 and 1.
    #7
    du00000001
    Just Some Member
    • Total Posts : 2249
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: QEI Setup on the dsPIC33EP512GM710 2018/10/03 07:48:52 (permalink)
    4.5 (2)
    OK. But CCM=0 is the only setting applicable for QEI operation.
    Now you may have to get QEA/QEB correct and working.
    Your approach of disconnecting one of the lines is good. Continue with that and find out what's not ok with the non-functional one. (Remapping, ANSELx set and alike.)

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #8
    qhb
    Superb Member
    • Total Posts : 7987
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: QEI Setup on the dsPIC33EP512GM710 2018/10/08 22:01:08 (permalink)
    4.2 (5)

        RPINR14bits.QEB1R = 127; //0x007F; //Pin #21

    I think this will select pin RG7 = RP127 = pin#1
    not RA9 = RPI27 = pin#21.
    You have misread capital "I" as "1".
     
     
    post edited by qhb - 2018/10/08 22:02:18
    #9
    Batgoy
    New Member
    • Total Posts : 29
    • Reward points : 0
    • Joined: 2004/06/15 04:33:51
    • Status: offline
    Re: QEI Setup on the dsPIC33EP512GM710 2018/10/09 23:42:49 (permalink)
    0
    joshua.cochran
    If CCM = 0, the POSCNT register switches between 0 and 1.


    This occurs when one of the "A" or "B" signals is missing.
    #10
    qhb
    Superb Member
    • Total Posts : 7987
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: QEI Setup on the dsPIC33EP512GM710 2018/10/10 05:23:43 (permalink)
    5 (1)
    I pointed out the problem in post#9, which means one signal IS missing, because it is connected to the wrong pin, and someone gave it a -1 rating. ???
     
    #11
    Jim Nickerson
    User 452
    • Total Posts : 5589
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: QEI Setup on the dsPIC33EP512GM710 2018/10/10 06:30:57 (permalink)
    5 (1)
    I bumped up the rating, some do not understand how to use the ratings ( at least it was not flagged !! )
    #12
    qhb
    Superb Member
    • Total Posts : 7987
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: online
    Re: QEI Setup on the dsPIC33EP512GM710 2018/11/09 03:06:02 (permalink)
    0
    So Joshua, did this fix your problem?
    #13
    Jump to:
    © 2018 APG vNext Commercial Version 4.5