2013-10-20 10:17 AM
hello dear forum,
I am trying to read an AB encoder with stm32f4 timer_1 I got the encoder signals through 75175 to timer_1_ch1 and ch2 pins I can see square waves of A and B with osciloscope the codes are below - any help appreciated - thank youvoid
Encoderinit(
void
) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_TIM1);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource11,GPIO_AF_TIM1);
/* 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(TIM1, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(TIM1,TIM_EncoderMode_TI12,TIM_ICPolarity_Rising,TIM_ICPolarity_Rising );
TIM_ITConfig(TIM1,TIM_IT_Update , ENABLE);
TIM_Cmd(TIM1, ENABLE);
TIM1->CNT=0;
}
and in the main loop I read enkoder 100 times a second but always value 0
main{
..................
Encoderinit()
..................
while
(1){
..................
enkoder=TIM1->CNT;
}
#tim-encoder #tim-encoder #stm32f4-timer-encoder
2013-10-20 12:07 PM
hello - the problem solved
2013-10-20 12:53 PM
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
??2013-10-21 05:23 AM
hello - the problem is solved
it was a mistake of me while reading the TIM1->CNT the above initialization code is correct for anyone who is searching for help in this issue with this occasion I want to ask if I can program the input capture filter IC1F , IC2F(TIMx_CCMR1)
while the timer is in encoder mode ? I mean is the input capture filter active in encoder mode ? thank you
2013-10-21 06:47 AM
Yes you can enable captures in encoder mode. I use capture on CC1 to detect when the encoder count changes and on CC3 to detect the index.
Jack Peacock2013-10-21 09:26 AM
hello thank you for the answers
what I want ask is , there is filter at the input stage of timer inputs to eliminate fals triggering it is sampling the timer input and if it is always ''1'' for example for a period of programmed filter time the timer only then captures or counts ( sorry this is my best english hope you understand ) what I want ask is is this filter active when in encoder mode ? ( IC1F IC2F ) CCMR register the manual says:IC1F[3:0]
: Input capture 1 filter
This bit-field defines the frequency used to sample TI1 input and the length of the digital filter applied
to TI1. The digital filter is made of an event counter in which N events are needed to validate a
transition on the output
Yes you can enable captures in encoder mode. I use capture on CC1 to detect when the encoder count changes and on CC3 to detect the index.
Jack Peacock2013-10-21 09:35 AM
The pins are feed though a synchronizer, likely at the pin by the AHB clocks, and then by the TIM at it's APB/TIM clock. You'd have to digest the docs.
Filter elements of the TIM are controlled at a rate specified byTIM_TimeBaseStructure.TIM_ClockDivision
2013-10-21 12:16 PM
Yes the digital filter is used in encoder mode, and it does make a difference. My setup is a single-ended Avago HEDS-5540 optical encoder on the end of a NEMA 17 or 23 stepper, with 800 count wheels (2x sampling for 400 half setps on a 1.8 degree motor).
Some ad hoc experimenting gave a good reading at digital filter set to 5, not so good at 7. This is on an STM32F405 at 168MHz, using TIM4 for a rotary encoder and TIM5 for linear encoder. Jack Peacock