Hi,
I have used the GPIO to simulate the encoder signals, I copy the code here, if you have time, pls have a try.
BR
XiangJun Rong
#include "board.h"
#include <stdio.h>
void QEI(void);
void GPIO_Output(void);
/*****************************************************************************
* Private types/enumerations/variables
****************************************************************************/
#define TICKRATE_HZ1 (1000) /* 10 ticks per second */
/*****************************************************************************
* Public types/enumerations/variables
****************************************************************************/
/*****************************************************************************
* Private functions
****************************************************************************/
/*****************************************************************************
* Public functions
****************************************************************************/
/**
* @brief Handle interrupt from SysTick timer
* @return Nothing
*/
uint32_t index,counter;
bool P2_15waveform[80]={true,true,false,false,true,true,false,false,true,true,false,false,true,true,false,false,\
true,true,false,false,true,true,false,false,true,true,false,false,true,true,false,false,\
true,true,false,false,true,true,false,false,true,true,false,false,true,true,false,false,\
true,true,false,false,true,true,false,false,true,true,false,false,true,true,false,false,\
true,true,false,false,true,true,false,false,true,true,false,false,true,true,false,false};
bool P2_23waveform[80]={false,true,true,false,false,true,true,false,false,true,true,false,false,true,true,false,\
false,true,true,false,false,true,true,false,false,true,true,false,false,true,true,false,\
false,true,true,false,false,true,true,false,false,true,true,false,false,true,true,false,\
false,true,true,false,false,true,true,false,false,true,true,false,false,true,true,false,\
false,true,true,false,false,true,true,false,false,true,true,false,false,true,true,false};
bool P2_19waveform[80]={true,true,false,false,false,false,false,false,false,false,false,false,false,false,false,false,\
false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,\
false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,\
false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,\
false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false};
uint32_t revolutionReading[100];
void SysTick_Handler(void)
{
Board_LED_Toggle(0);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 15, P2_15waveform[index]);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 23, P2_23waveform[index]);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 19, P2_19waveform[index]);
index++;
if(index>=80)
{
index=0;
revolutionReading[counter]=LPC_QEI->INXCNT;
counter++;
if(counter>=100) counter=0;
}
}
/**
* @brief main routine for systick example
* @return Function should not exit.
*/
int main(void)
{
/* Generic Initialization */
SystemCoreClockUpdate();
Board_Init();
QEI();
/* Enable and setup SysTick Timer at a periodic rate */
SysTick_Config(SystemCoreClock / TICKRATE_HZ1);
GPIO_Output();
index=0;
counter=0;
/* LEDs toggle in interrupt handlers */
while (1) {
// __WFI();
}
return 0;
}
//QEI signal connection
//On Embedded Artist AB2103 mother board/daughter card board, the LPC4088EFT208 is populated
//P1_20 is connected to J1_88, QEI_PHA. pin32 of J5
//P1_23 is connected to J1_91. QEI_PHB, pin 23 of J5
//P1_24 is connected to J1_92, QEI_INdex, pin27 of J3
void QEI(void)
{
//pin assignment
//P1.20 QEI_PHA
Chip_IOCON_PinMuxSet(LPC_IOCON,0x1, 20, 0x03);
//P2.23 QEI_PHB
Chip_IOCON_PinMuxSet(LPC_IOCON,0x1, 23, 0x03);
//P1.24 QEI_IDX
Chip_IOCON_PinMuxSet(LPC_IOCON,0x1, 24, 0x03);
//QEI clock enable
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_QEI);
//QEI code
}
//on the LPC4088 board,
//GPIO70 <---->P2.15----------->pin 54 on J5
//GPIO74 <---->P2.23------------>pin 56 on J5
//GPIO71 <---->P2.19------------>pin46 on J5
void GPIO_Output(void)
{
/* Sets up DEBUG UART */
asm("nop");
/* Initializes GPIO */
Chip_GPIO_Init(LPC_GPIO);
Chip_IOCON_Init(LPC_IOCON);
Chip_GPIO_SetPortMask(LPC_GPIO, 2, 0x00);
//P2.25 configured as GPIO
Chip_GPIO_WriteDirBit(LPC_GPIO, 2, 15, true);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 15, true);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 15, false);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 15, true);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 15, false);
Chip_GPIO_SetPinToggle(LPC_GPIO, 2,15);
Chip_GPIO_SetPinToggle(LPC_GPIO, 2,15);
Chip_GPIO_SetPinToggle(LPC_GPIO, 2,15);
Chip_GPIO_SetPinToggle(LPC_GPIO, 2,15);
//P2.23 configured as GPIO
Chip_GPIO_WriteDirBit(LPC_GPIO, 2, 23, true);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 23, true);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 23, false);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 23, true);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 23,false);
Chip_IOCON_PinMuxSet(LPC_IOCON,2,19,0x00);
Chip_GPIO_WriteDirBit(LPC_GPIO, 2, 19, true);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 19, true);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 19, false);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 19, true);
Chip_GPIO_WritePortBit(LPC_GPIO, 2, 19, false);
}