2015-04-26 01:50 PM
Hi, I have problem with encoder mode. AS5040 is in quadrature output. I use this code and it doesnt work, where is the problem?
void gpio_conf(void) {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 | RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void TIM1_Configuration(void) {
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_Period = 65535;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(TIM1, TIM_EncoderMode_TI1, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
TIM_Cmd(TIM1, ENABLE);
}
#stm32 #encoder #mode
2015-04-26 02:56 PM
Presuming the pins are correct
void TIM1_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_Period = 65535; // Maximal
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; // Not used
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(TIM1, TIM_EncoderMode_TI1, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
TIM_CtrlPWMOutputs(TIM1, ENABLE);
TIM_Cmd(TIM1, ENABLE);
}
2015-04-27 05:24 AM
I think thats it doesnt work. I check it with this code and nothing.
int main(void) {
rcc_conf();
gpio_conf();
TIM1_Configuration();
while (1) {
test = TIM1->CNT;
if(test > 1) {
led_conf(1,1); //led on
}
}
}
2015-04-27 05:40 AM
PB8 and PB9 relate to TIM1_CH1 and TIM1_CH2 how exactly?
2015-04-27 06:14 AM
I dont understand. The pins are connect to AS5040 to 3 and 4 pin.
http://circuits.datasheetdir.com/374/AS5040-pinout.jpg2015-04-27 07:17 AM
Ok, but does the STM32 Data Sheet suggest the pins relate to TIM1 or are you just inventing connectivity?
http://www.st.com/web/en/resource/technical/document/datasheet/CD00161566.pdf
2015-04-27 09:11 AM
Oh, I think about PB13 and PB14, I change it, but it doesnt help.
2015-04-27 12:09 PM
Ok, and those are the NEGATED channels. You need to use TIM1_CH1 and TIM1_CH2
So PE9/PE11 as remapped pins, PA8/PA9 in non-remapped. The pin options here are pretty limited.2015-04-27 11:02 PM
2015-04-28 08:54 AM
Ok, thank you for this. So if I cant do it with encoder mode how can I do this? With interruption?