简体   繁体   English

stm32f303vc 发现 tim3 不起作用

[英]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.我想将 tim3 ch1 ch2 配置为编码器模式,我在 tim2 上有相同的代码(它也是通用定时器)并且运行良好。 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 SMCR设置为0

Your code sets both timers to encoder mode 1, see the description of the SMCR register in the reference manual. 您的代码将两个定时器都设置为编码器模式 1,请参阅参考手册中对 SMCR寄存器的描述。

0001: Encoder mode 1 - Counter counts up/down on TI1FP1 edge depending on TI2FP2 level. 0001:编码器模式 1 - 计数器根据 TI2FP2 电平在 TI1FP1 边沿向上/向下计数。

In this mode, the timer counter is incremented or decremented by the signals on then CH1 and CH2 input, instead of the internal clock. 在此模式下,定时器计数器由 CH1 和 CH2 输入上的信号而不是内部时钟递增或递减。 There must be some other component on the board, or line noise when they are unconnected, that managed to trigger TIM2 a few times. 电路板上肯定有其他组件,或者它们未连接时的线路噪声,设法触发了 TIM2 几次。

PE2 is connected to an output of another IC PE2连接到另一个IC的输出

Check the schematics in the board user manual.检查电路板用户手册中的原理图。 PE2 is connected to the DRDY output of the onboard accelerometer. PE2 连接到板载加速度计的 DRDY输出

You can use the CubeMX tool to find available pins for TIM3.您可以使用 CubeMX 工具查找 TIM3 的可用引脚。 Select your board in the Board Selector screen, it will show that PE2 and PE3 are already connected to something.在 Board Selector 屏幕中选择您的电路板,它会显示 PE2 和 PE3 已经连接到某些东西。

Set TIM3 combined channels to encoder mode, it will assign some free pins to the timer.将 TIM3 组合通道设置为编码器模式,它将为定时器分配一些空闲引脚。 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.然后您可以按住CTRL并单击引脚以查看替代项(它们将以蓝色闪烁),并且您可以使用鼠标拖动引脚分配。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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