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.

[参考译文] TM4C123 QEI0模块不工作

Guru**** 2305510 points
Other Parts Discussed in Thread: TM4C123GH6PM
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1174682/tm4c123-qei0-module-not-working

主题中讨论的其他器件:TM4C123GH6PM

大家好、我使用的是 TM4C123GH6PM、我使用的是 QEI 模块。 使用示例代码 QEI1模块正在工作... 使用相同的代码、它不适用于 QEI0模块...任何建议...

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Anuprash、您好!

    您能否发布有效的 QEI1代码和无效的 QEI0代码、以便我对它们进行比较?

    此致、

    Ralph Jacobi

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

     FOR QEI1 MODULE TAKEN FROM THE EXAMPLE CODE OF CCS
     
     
    /* -----------------------          Include Files       --------------------- */
    #include <stdint.h>                         // Library of Standard Integer Types
    #include <stdbool.h>                        // Library of Standard Boolean Types
    #include "inc/tm4c123gh6pm.h"               // Definitions for interrupt and register assignments on Tiva C
    #include "inc/hw_memmap.h"                  // Macros defining the memory map of the Tiva C Series device
    #include "inc/hw_types.h"                   // Defines common types and macros
    #include "inc/hw_gpio.h"                    // Defines Macros for GPIO hardware
    #include "inc/hw_qei.h"                     // Macros used when accessing the QEI hardware
    #include "driverlib/debug.h"                // Macros for assisting debug of the driver library
    #include "driverlib/sysctl.h"               // Defines and macros for System Control API of DriverLib
    #include "driverlib/interrupt.h"            // Defines and macros for NVIC Controller API of DriverLib
    #include "driverlib/gpio.h"                 // Defines and macros for GPIO API of DriverLib
    #include "driverlib/qei.h"                  // Prototypes for the Quadrature Encoder Driver
    #include "driverlib/pin_map.h"              // Mapping of peripherals to pins for all parts
    #include "driverlib/rom.h"                  // Defines and macros for ROM API of driverLib
    
    #define VEL_INT_FREQ    10000               // Macro to store the Interrupt frequency of QEI1
    #define QEI1_PPR        4000             // Macro to store the PPR of the QEI1
    
    /* -----------------------      Global Variables        --------------------- */
    volatile uint32_t ui32Qei1Vel;              // Variable to store the velocity of QEI1
    volatile uint32_t ui32Qei1Pos;              // Variable to store the position of QEI1
    volatile int32_t i32Qei1Dir;                // Variable to store the direction of QEI1
    volatile uint16_t ui16Qei1Rpm;              // Variable to store the RPM of QEI1
    
    /* -----------------------      Function Prototypes     --------------------- */
    void QEI1IntHandler(void);
    unsigned long int a;
    /* -----------------------          Main Program        --------------------- */
    int main(void){
    
       // a++;
        // Set the System clock to 80MHz
        ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 |SYSCTL_USE_PLL |SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);
    
        // Enable the clock for peripherals PortC and QEI1
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    
        // Configure the PC5, PC6 for QEI signals
        ROM_GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_5 | GPIO_PIN_6);
        ROM_GPIOPinConfigure(GPIO_PC5_PHA1);
        ROM_GPIOPinConfigure(GPIO_PC6_PHB1);
    
        // Configure the QEI1 to increment for both PhA and PhB for quadrature input with "QEI1_PPR" PPR
        ROM_QEIConfigure(QEI1_BASE, QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_QUADRATURE, QEI1_PPR);
        // Configure the QEI1 for Velocity Calculation, Predivide by 1 at "VEL_INT_FREQ" Hz
        ROM_QEIVelocityConfigure(QEI1_BASE, QEI_VELDIV_1, ROM_SysCtlClockGet() / VEL_INT_FREQ);
        ROM_QEIVelocityEnable(QEI1_BASE);
    
        // Enable the Interrupts for Velocity Timer Expiration of QEI1
        void (*QEI1IntHandler_ptr)(void) = &QEI1IntHandler;
        QEIIntRegister(QEI1_BASE, *QEI1IntHandler_ptr);
        ROM_QEIIntEnable(QEI1_BASE, QEI_INTTIMER);
    
        // Master interrupt enable API for all interrupts
        ROM_IntMasterEnable();
        // Enable the QEI1
        ROM_QEIEnable(QEI1_BASE);
    
        while (1);
    }
    
    /* -----------------------      Function Definition     --------------------- */
    void QEI1IntHandler(void){
        // ISR for Quadrature Encoder Interface 1
    
        // Clear the Interrupt that is generated
        ROM_QEIIntClear(QEI1_BASE, ROM_QEIIntStatus(QEI1_BASE, true));
        // Calculate the number of quadrature ticks in "1 / VEL_INT_FREQ" time period
        ui32Qei1Vel = ROM_QEIVelocityGet(QEI1_BASE);
        // Update the position reading of the encoder
        ui32Qei1Pos = ROM_QEIPositionGet(QEI1_BASE);
        // Update the direction reading of the encoder
        i32Qei1Dir = ROM_QEIDirectionGet(QEI1_BASE);
        // Calculate the velocity in RPM
        ui16Qei1Rpm = ui32Qei1Vel * VEL_INT_FREQ * 60 / QEI1_PPR;
    }
    
    
    
    
    
    
    
    /* -----------------------          Include Files       --------------------- */
    #include <stdint.h>                         // Library of Standard Integer Types
    #include <stdbool.h>                        // Library of Standard Boolean Types
    #include "inc/tm4c123gh6pm.h"               // Definitions for interrupt and register assignments on Tiva C
    #include "inc/hw_memmap.h"                  // Macros defining the memory map of the Tiva C Series device
    #include "inc/hw_types.h"                   // Defines common types and macros
    #include "inc/hw_gpio.h"                    // Defines Macros for GPIO hardware
    #include "inc/hw_qei.h"                     // Macros used when accessing the QEI hardware
    #include "driverlib/debug.h"                // Macros for assisting debug of the driver library
    #include "driverlib/sysctl.h"               // Defines and macros for System Control API of DriverLib
    #include "driverlib/interrupt.h"            // Defines and macros for NVIC Controller API of DriverLib
    #include "driverlib/gpio.h"                 // Defines and macros for GPIO API of DriverLib
    #include "driverlib/qei.h"                  // Prototypes for the Quadrature Encoder Driver
    #include "driverlib/pin_map.h"              // Mapping of peripherals to pins for all parts
    #include "driverlib/rom.h"                  // Defines and macros for ROM API of driverLib
    
    #define VEL_INT_FREQ    10000               
    #define QEI0_PPR        4000            
    
    /* -----------------------      Global Variables        --------------------- */
    volatile uint32_t ui32Qei0Vel;              
    volatile uint32_t ui32Qei0Pos;              
    volatile int32_t i32Qei0Dir;                
    volatile uint16_t ui16Qei0Rpm;              
    
    /* -----------------------      Function Prototypes     --------------------- */
    void QEI0IntHandler(void);
    unsigned long int a;
    /* -----------------------          Main Program        --------------------- */
    int main(void){
    
    
        // Set the System clock to 80MHz
        ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 |SYSCTL_USE_PLL |SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);
    
        // Enable the clock for peripherals PortD and QEI0
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    
        // Configure the PC5, PC6 for QEI signals
        ROM_GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);
        ROM_GPIOPinConfigure(GPIO_PD6_PHA0);
        ROM_GPIOPinConfigure(GPIO_PD7_PHB0);
    
        // Configure the QEI1 to increment for both PhA and PhB for quadrature input with "QEI0_PPR" PPR
        ROM_QEIConfigure(QEI0_BASE, QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_QUADRATURE, QEI0_PPR);
        // Configure the QEI1 for Velocity Calculation, Predivide by 1 at "VEL_INT_FREQ" Hz
        ROM_QEIVelocityConfigure(QEI0_BASE, QEI_VELDIV_1, ROM_SysCtlClockGet() / VEL_INT_FREQ);
        ROM_QEIVelocityEnable(QEI0_BASE);
    
        // Enable the Interrupts for Velocity Timer Expiration of QEI0
        void (*QEI0IntHandler_ptr)(void) = &QEI0IntHandler;
        QEIIntRegister(QEI0_BASE, *QEI0IntHandler_ptr);
        ROM_QEIIntEnable(QEI0_BASE, QEI_INTTIMER);
    
        // Master interrupt enable API for all interrupts
        ROM_IntMasterEnable();
    
        ROM_QEIEnable(QEI0_BASE);
    
        while (1);
    }
    
    /* -----------------------      Function Definition     --------------------- */
    void QEI0IntHandler(void)
    {
        // ISR for Quadrature Encoder Interface 1
    
        // Clear the Interrupt that is generated
        ROM_QEIIntClear(QEI0_BASE, ROM_QEIIntStatus(QEI0_BASE, true));
        // Calculate the number of quadrature ticks in "1 / VEL_INT_FREQ" time period
        ui32Qei0Vel = ROM_QEIVelocityGet(QEI0_BASE);
        // Update the position reading of the encoder
        ui32Qei0Pos = ROM_QEIPositionGet(QEI0_BASE);
        // Update the direction reading of the encoder
        i32Qei0Dir = ROM_QEIDirectionGet(QEI0_BASE);
        // Calculate the velocity in RPM
        ui16Qei0Rpm = ui32Qei0Vel * VEL_INT_FREQ * 60 / QEI0_PPR;
    }
    
    

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    [使用相同的代码引用 userid="541209" URL"~/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1174682/tm4c123-qei0-module-not-working "]它不适用于 QEI0模块....任何建议...

    该代码具有以下配置 QEI0引脚的功能、其中包含对使用端口 C 和 D 的混合引用:

        // Configure the PC5, PC6 for QEI signals
        ROM_GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);
        ROM_GPIOPinConfigure(GPIO_PD6_PHA0);
        ROM_GPIOPinConfigure(GPIO_PD7_PHB0);

    假设您要对 PhA0使用 PD6、对 PhB0使用 PD7、则尝试将代码更改为:

        // Configure the PD6, PD7 for QEI signals
        ROM_GPIOPinTypeQEI(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);
        ROM_GPIOPinConfigure(GPIO_PD6_PHA0);
        ROM_GPIOPinConfigure(GPIO_PD7_PHB0);

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    是否在启动文件中出现问题

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Anuprash、您好!

    很抱歉耽误了我的假期。

    您使用的 PD7是一个 NMI 引脚、默认情况下在器件上被锁定。 您将需要解锁引脚以将其配置为 QEI0操作。

    有关如何操作的详细信息、请参阅以下常见问题解答: https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1020814/faq-how-to-get-locked-gpio-pins-on-tm4c123-devices-to-work

    除此之外、将您的代码与 Chester 观察到 的内容与 QEI0 GPIO 配置的 GPIO_PORTC_BASE 不正确进行比较、其他所有内容似乎都与转换保持一致。 我相信、一旦您添加解锁例程、您就会有一个可用的 QEI0外设。

    此致、

    Ralph Jacobi