cancel
Showing results for 
Search instead for 
Did you mean: 

[solved]stm32f4 quadrature encoder

dmitry2399
Associate
Posted on February 02, 2012 at 07:27

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-encoder
4 REPLIES 4
Posted on July 22, 2012 at 20:17

Hello!

What is max speed achieved?

gary
Associate
Posted on February 05, 2014 at 16:01

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,

Gary

Posted on February 05, 2014 at 16:11

TIM_CtrlPWMOutputs(TIM8, ENABLE);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gary
Associate
Posted on February 05, 2014 at 21:18

Thanks very much,

I have passed this on.

Regards,

Gary