Associate II
June 1, 2020
Question
Why my timer encoder mode oscillates in the same values?
- June 1, 2020
- 4 replies
- 1391 views
Hi, i'm using my STM32F7 nucleo 144 and i'm learning about timer encoder mode and i follow the example in the datasheet but when i check the CNT register it oscillates in the same values and if i use the A0-A1 pins the encoder works bad, can somebody help me please?
// ******************* PORT ****************
RCC->AHB1ENR |=0x03; // Turn on A,B clocks
// *******************************************
// ******************* PINS *****************
GPIOA->MODER |=0x800; // Alternative A5
GPIOA->AFR[0] =0x100000; // Alternative function AF1
GPIOB->MODER |=0x80; // Alternative B3
GPIOB->AFR[0] =0x1000; // Alternative Function AF1
// *******************************************
// ******************* ENCODER TIMER********
RCC->APB1ENR |=0x01; // Turn on the TIM2 clock
TIM2->ARR =1000; // Maximun count
TIM2->CCMR1 |=0x0101; // select TI1 and TI2
TIM2->SMCR |=0x03; // Encoder mode 3
TIM2->CR1 |=0x01; // Timer On
// *******************************************