2012-02-01 10:27 PM
i am trying to work with quadrature encoder (TIM8, pins pc6,pc7).
here is my code:
/* Enable GPIO clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8,ENABLE);
// PA.6,PA.7 for encoder
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_TIM8);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_TIM8);
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 0xffff;
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(TIM8, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
// Initial interuppt structures
NVIC_InitStructure.NVIC_IRQChannel = TIM8_BRK_TIM12_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_KERNEL_INTERRUPT_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_TIM13_IRQn;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM8_TRG_COM_TIM14_IRQn;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM8_CC_IRQn;
NVIC_Init(&NVIC_InitStructure);
// Clear all pending interrupts
TIM_ClearFlag(TIM8, TIM_FLAG_Update | TIM_FLAG_COM | TIM_FLAG_Break | TIM_FLAG_CC1 | TIM_FLAG_CC2 |TIM_FLAG_CC3|TIM_FLAG_CC4);
TIM_ITConfig(TIM8, TIM_IT_Update | TIM_IT_COM | TIM_IT_Break | TIM_IT_CC1 | TIM_IT_CC2 |TIM_IT_CC3|TIM_IT_CC4, ENABLE);
TIM8->CNT = 0;
TIM_Cmd(TIM8, ENABLE);
TIM8_CC_IRQHandler interrupt is triggered, but counter register not incrementing/decrementing...
what am I doing wrong?
P.S. problem solved.
it was the
wrong
signal levels
.. #stm32f4-quadrature-encoder2012-07-22 11:17 AM
Hello!
What is max speed achieved?2014-02-05 07:01 AM
Hi Dmitry,
We have some developers working with the quadrature encoder interface. They have it working with a simple timer (timer 3) but have not been able to get it working with an advanced timer (timer 8). Could you please indicate if the code you posted is a working version of your code? You indicated that your timer 8 solution worked after you sorted out the levels from the encoder, but were there any other code changes at all?Cheers,Gary2014-02-05 07:11 AM
TIM_CtrlPWMOutputs(TIM8, ENABLE);
2014-02-05 12:18 PM
Thanks very much,
I have passed this on.Regards,Gary