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: Read signal from encoder does not wait for signal.

Part Number: EK-TM4C123GXL
Other Parts Discussed in Thread: EK-TM4C1294XL

Tool/software: Code Composer Studio

Hi,

This question probably shows a great  lack of knowledge. I have code to read from a rotary encoder with the line qeiPosition = QEIPositionGet(QEI0_BASE). When there is no encoder attached, the program sails past this statement. I was expecting it to wait at that point until a signal from the encoderr arrived. Does the code need an interrupt handler to wait for the signal?

While I was waiting for an answer, in case it does I added code for an interrupt handler. I was trying to register the interrupt handler in a C++ file with: 

GPIOIntRegister(GPIO_PORTD_BASE,PORTDIntHandler);

The compiler gives the message:

#169 argument of type "void (*)()" is incompatible with parameter of type "void (*)() C"

Which seems to be saying void (*)() is different from void (*)() which is slightly confusing to say the least. However, a C file compiles without error. I would like to stick with C++ though if possible. 

Thank you

 

 

 

  • Hi William,

      The QEIPositionGet does not wait for the signal. It merely reads the Position register when you call the function. Please see below. 

    uint32_t
    QEIPositionGet(uint32_t ui32Base)
    {
    //
    // Check the arguments.
    //
    ASSERT((ui32Base == QEI0_BASE) || (ui32Base == QEI1_BASE));

    //
    // Return the current position counter.
    //
    return(HWREG(ui32Base + QEI_O_POS))

    }

    If you want to register an QEI interrupt you should be calling QEIIntRegister(),

    I'm not too sure why you are getting a compile error. Instead of doing the dynamic registering of the interrupt I will suggest you assign the interrupt vector statically to see if resolves the issue. You will update the startup_ccs.c file like below. You can reference some of the TivaWare examples such as <TivaWare_Installation>/examples/boards/ek-tm4c1294xl/interrupts to get an idea how the interrupts are configured. 

    Please also note the difference between static and dynamic configuration of the interrupt. Below is the excerpt. You can find the details in the peripheral driver library user's guide. 

  • Greetings,

    William Herschel said:
    qeiPosition = QEIPositionGet(QEI0_BASE). When there is no encoder attached, the program sails past this statement.

    That's doubtful (Sails Past) - and may be confirmed by your subsequent 'read' of "qeiPosition."      Almost all encoders my group (& clients') have employed - enforced no such 'Gating Encoder' demands.    Your 'read' - absent any 'expected' signals upon each Phase & Index input - will reflect the 'API's handling of this 'encoder AWOL' condition.'

    C++ code issue 'strays' from the 'MCU centric' focus here - likely is better handled by more 'C++ inviting venues.'

    [edit] 0959:   Vendor's Charles response & mine have just 'crossed.'    The API code he's exposed  (unfortunately) offers no explanation of  how 'key' Register: "QEI_O_POS" is processed and/or updated.     (my group has developed additional code to specifically, 'Test for abnormal QEI Input Signalling' - to include, 'Absence of expected signals!')     

    Our group's 'additional code' - then (importantly) notifies the MCU that:

    • Motor has halted
    • Potential 'encoder power' and/or 'cable issues' (may) have occurred.

    It should not be 'mandatory' to employ an interrupt to, 'Properly & Regularly' read the encoder.    (other than a Timer-based interrupt - which occurs w/sufficient frequency - and (only) when the motor is running.)

  • Thanks Charles for the explanation of interrupts. It’s going to take me a while to get to grips with it. I obviously would want a static configuration as the encoder will be changing position at a relatively high angular frequency.

    Cheers

    William