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.

TM4C123GXL QEI0 not working

Hi, I'm using TM4C123GXL evaluation board.

I tried to use QEI with Peripheral Drive Library, but only one QEI module seem to be working.

QEI1 is OK, when I connect encoder channel A and B to PC5 and PC6(QEI module 1), I can see encoder count increment.

However when I connect the same encoder signals to PD6 and PD7(QEI module 0), the encoder count just doesn't change very much(a random number +-1), any suggestion what could be the problem?

I think I'm using almost the same code for QEI 0 and QEI 1.

Thanks.

Here's the code:

	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
	//--------------
	//     QEI
	//--------------

	SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI1);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);//QEI0
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);//QEI1

	//
	GPIOPinConfigure(GPIO_PD6_PHA0);
	GPIOPinConfigure(GPIO_PD7_PHB0);
	GPIOPinConfigure(GPIO_PC5_PHA1);
	GPIOPinConfigure(GPIO_PC6_PHB1);

	//
	GPIOPinTypeQEI(GPIO_PORTD_BASE, GPIO_PIN_6);
	GPIOPinTypeQEI(GPIO_PORTD_BASE, GPIO_PIN_7);
	GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_5);
	GPIOPinTypeQEI(GPIO_PORTC_BASE, GPIO_PIN_6);

	//
	QEIConfigure(QEI0_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 25030);
	QEIConfigure(QEI1_BASE, (QEI_CONFIG_CAPTURE_A_B | QEI_CONFIG_NO_RESET | QEI_CONFIG_QUADRATURE | QEI_CONFIG_NO_SWAP), 25030);

	QEIEnable(QEI0_BASE);
	QEIEnable(QEI1_BASE);

	//--------------
	//     UART
	//--------------

	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
	UARTEnable(UART0_BASE);
	//--------------
	//  Loop
	//--------------

	uint32_t duty_cycle = 100;
	uint32_t pos1 = 0;
	uint32_t pos2 = 0;
	char buffer[20]={0};

	while(1)
	{
		SysCtlDelay(5000000);

		pos1 = QEIPositionGet(QEI0_BASE);
		pos2 = QEIPositionGet(QEI1_BASE);

		//the following is just to convert pos to char for UART output
		uint32_t n = pos1;

		int i = 0;

		bool isNeg = false;

		unsigned int n1 = isNeg ? -n : n;

		while(n1!=0)
		{
		    buffer[i++] = n1%10+'0';
		    n1=n1/10;
		}

		if(isNeg)
		    buffer[i++] = '-';

		buffer[i] = '\0';
		int t = 0;
		for(;t < i/2;t++)
		{
		    buffer[t] ^= buffer[i-t-1];
		    buffer[i-t-1] ^= buffer[t];
		    buffer[t] ^= buffer[i-t-1];
		}
		//
		i=0;
		while(buffer[i])
		{
			UARTCharPut(UART0_BASE, buffer[i]);
			i++;
		}

		UARTCharPut(UART0_BASE, ' ');
	}

  • Hi Wang,

         PD7 defaults as NMI. You, need an unlocking code to set its alternate function. Search in the forum for that code or use the PinMux Utility.

    -kel

  • Yet another victim of this long known - and (pardon) "issue allowed to linger" situation run wild.

    At some time would not (some) better highlight of these sensitive, NMI bound pins, make sense?  Yes - several (I recall two) plain text, paragraph warnings alert & describe.  But clearly - those are missed - and missed often.

    Past M3 (now NRND MCUs) proudly/boldly "splashed" such NRND proclamations in bright/bold RED atop first page of MCU manuals.  (sure to be noted!)

    Has not the need for similar - targeting this ongoing, "missed NMI default" long been established? 

    As a "stop-gap" would not *** NMI! (read pg xxx) married to each/every reference to the candidate NMI pins - throughout the MCU manual - improve this situation?  Or the status quo can continue - and NMI's victim count expand even further...  Note: it appeared surprisingly quick/easy to emblazon every past M3 MCU manual with NRND - difficult to imagine why the suggested, improved, NMI highlights/warnings appear so rejected.

  • I have read the workshop workbook pdf for Tiva Connected Launchpad, and there is a portion that discusses about
    these NMI pins, and how to unlock it. But, for experienced engineers, most probably they will skip reading this workbook pdf, and would think that this document is for newbie or noob only.

    So, in addition to cb1's suggestion, I think a sticky post with regards to these NMI pins would help.

    -kel

  • Thanks, Problem solved!