AnsweredAssumed Answered

[solved]stm32f4 quadrature encoder

Question asked by shapovalov.dmitry on Feb 2, 2012
Latest reply on Feb 5, 2014 by marshall.gary.001
  i am trying to work with quadrature encoder (TIM8, pins pc6,pc7).
here is my code:
01./* Enable GPIO clock */
02.RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
03.RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8,ENABLE);
04. 
05.// PA.6,PA.7 for encoder
06. 
07.GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
08.GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
09.GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
10.GPIO_Init(GPIOC,&GPIO_InitStructure);
11. 
12.GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_TIM8);
13.GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_TIM8);
14. 
15.TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
16. 
17. 
18.TIM_TimeBaseStructure.TIM_Period = 0xffff;
19.TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
20.TIM_EncoderInterfaceConfig(TIM8, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
21. 
22.// Initial interuppt structures
23.NVIC_InitStructure.NVIC_IRQChannel = TIM8_BRK_TIM12_IRQn;
24.NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_KERNEL_INTERRUPT_PRIORITY;
25.NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
26.NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
27.NVIC_Init(&NVIC_InitStructure);
28. 
29.NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_TIM13_IRQn;
30.NVIC_Init(&NVIC_InitStructure);
31. 
32.NVIC_InitStructure.NVIC_IRQChannel = TIM8_TRG_COM_TIM14_IRQn;
33.NVIC_Init(&NVIC_InitStructure);
34. 
35.NVIC_InitStructure.NVIC_IRQChannel = TIM8_CC_IRQn;
36.NVIC_Init(&NVIC_InitStructure);
37. 
38.// Clear all pending interrupts
39.TIM_ClearFlag(TIM8, TIM_FLAG_Update | TIM_FLAG_COM | TIM_FLAG_Break | TIM_FLAG_CC1 | TIM_FLAG_CC2 |TIM_FLAG_CC3|TIM_FLAG_CC4);
40. 
41.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);
42. 
43.TIM8->CNT = 0;
44.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..

Outcomes