简体   繁体   中英

Stm32f303vc discovery tim3 is not working

I would like to configure tim3 ch1 ch2 as encoder mode, I have the same code on tim2( it's also general purpose timer) and it's working good. Maybe there's another bits should I set but I cant find them.

I was trying to configure this timer to work without any outputs, just generate interrupt after set period of time but it's not working as well.

    //TIM2 CH1 PA0 CH2 PA1 AF1
    //TIM3 CH1 PE2 CH2 PE3 AF2

    RCC->APB1ENR |= RCC_APB1ENR_TIM2EN | RCC_APB1ENR_TIM3EN ;
    RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOEEN;

    GPIOA->MODER |= GPIO_MODER_MODER0_1 |  GPIO_MODER_MODER1_1;
    GPIOE->MODER |= GPIO_MODER_MODER2_1 |  GPIO_MODER_MODER3_1;

    GPIOA->AFR[0] |= 0X00000011;
    GPIOE->AFR[0] |= 0X00002200;


    TIM2->SMCR = TIM_SMCR_SMS_0;
    TIM2->CCMR1 = TIM_CCMR1_CC1S_0|TIM_CCMR1_CC2S_0;
    TIM2->ARR = 24;
    TIM2->DIER = TIM_DIER_UIE;
    TIM2->CR1= TIM_CR1_CEN;

    TIM3->SMCR = TIM_SMCR_SMS_0 ;
    TIM3->CCMR1 = TIM_CCMR1_CC1S_0 | TIM_CCMR1_CC2S_0;
    TIM3->ARR = 24;
    TIM3->DIER = TIM_DIER_UIE;
    TIM3->CR1= TIM_CR1_CEN ;

enter image description here

Set SMCR to 0

Your code sets both timers to encoder mode 1, see the description of the SMCR register in the reference manual.

0001: Encoder mode 1 - Counter counts up/down on TI1FP1 edge depending on TI2FP2 level.

In this mode, the timer counter is incremented or decremented by the signals on then CH1 and CH2 input, instead of the internal clock. There must be some other component on the board, or line noise when they are unconnected, that managed to trigger TIM2 a few times.

PE2 is connected to an output of another IC

Check the schematics in the board user manual. PE2 is connected to the DRDY output of the onboard accelerometer.

You can use the CubeMX tool to find available pins for TIM3. Select your board in the Board Selector screen, it will show that PE2 and PE3 are already connected to something.

Set TIM3 combined channels to encoder mode, it will assign some free pins to the timer. You can then hold down CTRL and click on the pin to see alternatives (they will blink in blue), and you can drag the pin assignments with the mouse.

好的,我找到了一个解决方案 :) 如果我将 TIM3 CH1 分配给 PB4,将 CH2 分配给 PB5,它工作得很好,但我不明白为什么,有人可以解释一下吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM