Encoder, Direction Bit toggles with every Pulse, Count 1 or 0. Posted on April 16, 2012 at 23:13
Hello, I've set up a STM32 with an incremental optical two channel encoder.
The counter direction bit toggles between 0 and 1 every count. As a result, the counter never gets pass 1. The counter reads 0,1,0,1,0,1...
I've tried all the counter modes, polarity settings, and channel counting settings.
Has anyone experienced this before? Any ideas?
Thanks
void ecdr_TIM2_init(void)
{
//Enable bus.
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
//Setting encoder inputs.
GPIO_init(GPIO_Mode_AF, GPIO_OType_PP, GPIO_Speed_25MHz, GPIO_PuPd_NOPULL, Encoder_TIM2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1 | GPIO_PinSource0, GPIO_AF_TIM2);
// NVIC_InitTypeDef NVIC_InitStructure; //Hold intr settings.
//Enabling interrupts for Timer 5.
// NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
// NVIC_Ini