Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
5 years, 11 months ago.
TIM2 STM32F767 (hardware counter)
Hi,
I'm trying to setup TIM2 as a counter ( code bellow)
TIM2
RCC -> APB1ENR |= 0x00000001; //TIM2 enabled TIM2 -> CR1 &= 0xFFFE; //TIM2 counter disable TIM2 -> PSC = 0x0; //Prescaler = 0 (no division) TIM2 -> ARR = 0xFFFFFFFF; //Autoreload TIM2 -> CR1 &= 0xFFEF; //Up Counting TIM2 -> CR1 &= 0xFCFF; //tDTS = tCK_INT TIM2 -> CCMR1 &= 0xFFFFFFFD; //CC1 channel is configured as input, IC1 is mapped on TI1 TIM2 -> CCMR1 |= 0x00000001; TIM2 -> CCER &= 0xFFF5; //Circuit is sensitive to TIxFP1 rising edge TIM2 -> CCER |= 0x0001; //Capture enabled TIM2 -> SMCR &= 0xFFFEFFDF; //Filtered Timer Input 1 (TI1FP1) TIM2 -> SMCR |= 0x00000057; //External Clock Mode 1 TIM2 -> CR1 |= 0x0001; //TIM2 counter enable while (true) { printf("%d\r\n", TIM2 -> CNT); }
I'm feeding pin 29 (D32, PA0) of the connector CN10 with 1kHz pulse. For some reason the code isn't working. I'll be very appreciated if someone could help me!
Thank you, Hugo
1 Answer
5 years, 11 months ago.
I was unaware that I needed to define the pin as an Alternate Function Mode and to route it from TIM2_CH1 to PA0.
solution
GPIOA -> MODER |= 0x00000002; // Define pin as AF GPIOA -> AFR[0] |= 0x00000001; //Route PA0 to TIM2_CH1
Hugo
Assigned to
5 years, 11 months ago.This means that the question has been accepted and is being worked on.