2010-12-02 02:47 AM
Encoder Problem
2011-05-17 05:17 AM
hello , do you have oscilloscope ?
can you look at the A B signals of encoder on the oscilloscope ? ( becouse I have the same code like you and I can read encoder with this code ) second ) is the compiler giving any warnings during compilation ?2011-05-17 05:17 AM
Hi,Thiago Navarro
I copyed your code into my project and it works.Please check if your encoder working properly.By the way,there seems a strange problem with this code,though TIM2 is configed into COUNTUP mode,the TIM2->CNT value keeps decreasing instead of increasing.From: Thiago Navarro
Posted: Thursday, December 02, 2010 11:47 AMSubject: Encoder ProblemHey, I am trying to work this encoder interface, but I haven´t had good results. When I debug my code , roll the encoder and watch the TIM2->CNT, its value is always (0 or 65535) or (0 or 1). Here is my code.
#include ''stm32f10x_conf.h''
#include ''misc.h''
void RCC_Configuration(void);
void GPIO_Configuration(void);
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
void TIM2init(void) {
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 0xffff;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(TIM2,TIM_EncoderMode_TI12,TIM_ICPolarity_Rising,TIM_ICPolarity_Rising );
TIM_Cmd(TIM2, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void RCC_Configuration(void)
{
/* TIM2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* GPIOC clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
}
int main (void){
RCC_Configuration();
GPIO_Configuration();
TIM2init();
while(1){
uint16_t current = TIM2->CNT;
}
}
If someone had any ideas, I will be very glad!!
thanks
2011-05-17 05:17 AM
Hey, Thanks for the
answers.
I did what you said, but It look like to work normal. I do not understand why it is happening!!There aren´t warnings in my code. Let I ask something... Do I have to roll in a fixed velocity?? Because I am rolling with my hand.
Thanks again!!
2011-05-17 05:17 AM
Forget this last question, Of course its doesn´t matter!! I think everything can be a problem... =/
2011-05-17 05:17 AM
YEAHHHHHH!!! I got it!! I don´t why its worked but worked =] I only changed the TIM2 to TIM3 ( and the Pins ). Anybody knows why?!
Thanks =DD