2008-03-17 09:58 PM
Count the frequency of 3 external signals
2011-05-17 03:26 AM
Hello,
I would like to measure the frequency of 3 differents signal (max frequency = 100kHz). What is the best way to handle this problem? > Use the Timers 2,3 and 4 in Input Capture mode and check the value of the counter register each second > Use an interruption to detect new pulse > Use an external counter and retrieve its value each second (which one?) > others ideas? Have you some configuration example to use a Timer in Input Capture mode? Thank you in advance for your advices.2011-05-17 03:26 AM
I have used an other way to measure frequency : I use a standard input and retrieve the value each second. Here is the code.
It works up to 450kHz, on 3 different inputs. Here is the main code : int main (void) { /* System Clocks Configuration */ RCC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* Configure the GPIOs */ GPIO_Configuration(); /* Configure the USART1 */ USART_Configuration(); /* Clear reset flags */ RCC_ClearFlag(); /* private variables declaration */ bool bln_HF1,bln_F1,bln_E1; bool bln_HF2,bln_F2,bln_E2; bool bln_HF3,bln_F3,bln_E3; unsigned int value=0; int cpt1=0,cpt2=0; /* Infinite loop */ while (1) { /* If 1s has passed */ if(TimeDisplay == 1) { /* Display counter values */ printf(''cpt1 : %d / cpt2 : %d/ cpt2 : %d\t'',cpt1,cpt2,cpt3); cpt1=0; } /* Rising edge detection and incrementation of counter 1 (PC1) */ bln_E1=GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_1); bln_F1=~bln_HF1&bln_E1; bln_HF1=bln_E1; if (bln_F1) cpt1++; /* Rising edge detection and incrementation of counter 2 (PB9) */ bln_E2=GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9); bln_F2=~bln_HF2&bln_E2; bln_HF2=bln_E2; if (bln_F2) cpt2++; /* Rising edge detection and incrementation of counter 2 (PA0) */ bln_E3=GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0); bln_F3=~bln_HF3&bln_E3; bln_HF3=bln_E3; if (bln_F3) cpt3++; } }