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.

CCS/EK-TM4C123GXL: QEI configuration

Part Number: EK-TM4C123GXL

Tool/software: Code Composer Studio

I am trying to read position of motor using QEI and i m giving initial value to QEI position register "0" and "6400" as maximum value.

    QEIConfigure        (QEI0_BASE,
        (QEI_CONFIG_CAPTURE_A | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP,6400),

    // Zero the position counter
    QEIPositionSet (QEI0_BASE, 0);// initial value

   x=QEIPositionGet(QEI0_BASE);

So when motor is rotating in clockwise direction x increments upto 6400 and then resets but when motor rotates in opposite direction x value changes directly from 0 to 6400 and then starts decreasing to 0, i want to measure change in position in both directions.Is there anyway i can configure QEI to give me change in position in both directions, i mean value of x changes from 0 to 6400 in one direction and from 0 to -6400.

  • The value wraps around, so moving in the positive direction from 6400 it will wrap around back to 0, and moving in the negative direction from 0 it will wrap around back to 6400.

    If you want to start at 0 and be able to count to -6400 and to +6400, then you need to set the limit to 12800, and each time you read the QEI, subtract 6400 to put it in the range -6400 to +6400.

    Note that it will still have the same "wrap around" behavior. So if you are at -6400 and you move in the negative direction, it will wrap around to +6400 and vice versa. If you are controlling a motor and there is a chance that your count will go out of this range, then you may need to handle this using a different approach.