I have an issue that I can not measure frequency more the 400 KHZ??? I have been measuring it on pin PB_10 [Timer2, Channel3], Some one have idea how to implement code for this pin, I have been successfuly done to measure frequency at pin : PA_0 [timer2, channel1]. but could do that on channel3 for timer2 [PB_10].
The configuration for PA_0 is :
// Select PA_0 pin for frequency counter
GPIOA->AFR[0] &= 0xfffffff0;
GPIOA->AFR[0] |= GPIO_AF1_TIM2;
GPIOA->MODER &= ~(GPIO_MODER_MODER0);
GPIOA->MODER |= 0x2;
// Initialize Timer2(32bit) for an external up counter mode
RCC->APB1ENR |= ((uint32_t)0x00000001);
TIM2->CR1 &= (uint16_t)(~(TIM_CR1_DIR | TIM_CR1_CMS | TIM_CR1_CKD)); // count_up + div by 1
TIM2->ARR = 0xFFFFFFFF;
TIM2->PSC = 0x0000;
TIM2->CCMR1 &= (uint16_t)~TIM_CCMR1_IC1F; // input filter
TIM2->CCER = TIM_CCER_CC1P; // positive edge
TIM2->SMCR &= (uint16_t)~(TIM_SMCR_SMS | TIM_SMCR_TS | TIM_SMCR_ECE);
TIM2->SMCR |= (uint16_t)(TIM_TS_TI1FP1 | TIM_SMCR_SMS); // external mode 1
TIM2->CR1 |= TIM_CR1_CEN; //Enable the TIM Counter */
what is to be done for changing tghis configuration for channel3, timer2 for PB_10 pin, any idea???
Mbed does not have a built-in API for measuring the frequency so you will have to write your own. Some community members have posted their own solutions and here are two examples that might prove useful:
Please find the below Information related to program/board
What target are you using? → Nucleo -64 (STM32F401RE)
What version of Mbed are you using? → 5.8
How are you generating the input signal? → Function generator [upto 8-10 MHZ]
Can you post your complete program? → I have to do POC for frequency counting at pin PB_10 [Timer 2, channel3], I have found the refrence and made changes for requirement from below reference code of KenjiArai, but could not do as far:
Might be some configuration issue, assigned to register value of
And I am reading TIM2-> CNT register for frequency with GATE time of 2 seconds.
Kindly review register’s configuration once and let me know what changes are required. at my end I could not debug for Timer register.
************************************************************************************************************************************************************* eInfochips Business Disclaimer: This e-mail message and all attachments transmitted with it are intended solely for the use of the addressee and may contain legally privileged and confidential information. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to this message and please delete it from your computer. Any views expressed in this message are those of the individual sender unless otherwise stated. Company has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email. *************************************************************************************************************************************************************
************************************************************************************************************************************************************* eInfochips Business Disclaimer: This e-mail message and all attachments transmitted with it are intended solely for the use of the addressee and may contain legally privileged and confidential information. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to this message and please delete it from your computer. Any views expressed in this message are those of the individual sender unless otherwise stated. Company has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email. *************************************************************************************************************************************************************
************************************************************************************************************************************************************* eInfochips Business Disclaimer: This e-mail message and all attachments transmitted with it are intended solely for the use of the addressee and may contain legally privileged and confidential information. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to this message and please delete it from your computer. Any views expressed in this message are those of the individual sender unless otherwise stated. Company has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email. *************************************************************************************************************************************************************
Please clarify - you are successfully counting on PB_10? If so - how fast can you count?
We haven’t been able to exercise this code, but it doesn’t appear that are taking advantage of the prescalar feature of the input capture. You can try setting TIM2_CCMR.IC2PSC and IC1PSC bits to 11b such that a capture is made only every 8 events.
It looks like we might not have bit defines for TIM2, but you can use those for TIM1 (from stm32f401xe.h):