2014-09-17 05:57 AM
Hello everyone,
I'm using the board STM32F4-discovery, I redid the example TIM_PWM_INPUT and everything works, I can measure the frequency. The problem occurs when I want to simultaneously measure 8 different speeds. For 4 works well. I used up to now the following interrupt associated with each pin: TIM2_IRQn; -> PB.3 TIM3_IRQn; -> PB.5 TIM4_IRQn; -> PB.7 TIM5_IRQn; -> PA.1 Question: What other pins can be used to measure the other speeds?2014-09-17 06:06 AM
CH1 or CH2 of TIM1, TIM8, TIM9, TIM12.
JW2014-09-17 06:17 AM
So If I use TIM1 CH2 for example pin PA9,
I receive this error:Error[Pe020]: identifier ''RCC_APB1Periph_TIM1'' is undefined Error[Pe020]: identifier ''TIM1_IRQn'' is undefined2014-09-17 06:37 AM
TIM1 and TIM8 are on APB2 and have differentiated interrupt vectors for the various sources. TIM9 is on APB2, too. TIM9 and TIM12 have shared interrupt vectors with other modules.
Read the manual. You may like also my http://www.efton.sk/STM32/STM32F4xx%20misc.pdf JW2014-09-17 03:14 PM
void TIM1_BRK_TIM9_IRQHandler(void)
{ RCC_ClocksTypeDef RCC_Clocks; RCC_GetClocksFreq(&RCC_Clocks); TIM_ClearITPendingBit(TIM9, TIM_IT_CC2); IC9Value = TIM_GetCapture2(TIM9); if (IC9Value != 0) { Frequency9 = (RCC_Clocks.HCLK_Frequency)/2 / IC9Value; } else { Frequency9 = 0; } f=Frequency9/10000.0; RCC_ClocksTypeDef RCC_Clocks11; RCC_GetClocksFreq(&RCC_Clocks11); TIM_ClearITPendingBit(TIM1, TIM_IT_CC2); IC1Value = TIM_GetCapture2(TIM1); if (IC1Value != RESET) { Frequency1 = (RCC_Clocks11.HCLK_Frequency)/2 / IC1Value; } else { Frequency1 = 0; } f=Frequency1/10000.0; }2014-09-17 03:17 PM
You need to QUALIFY the source of your interrupt, and you need to move the
RCC_GetClocksFreq
() code out of the interrupt. These clocks don't change, so you're just wasting timing doing it over and over.2014-09-17 03:33 PM
I was wrong to write,
f1 and f9 are two different frequencies .f9 work and change the value when the frequency of PA6 change.f1 remain =0 always.the code isvoid TIM1_BRK_TIM9_IRQHandler(void){
RCC_ClocksTypeDef RCC_Clocks;
RCC_GetClocksFreq(&RCC_Clocks);
TIM_ClearITPendingBit(TIM9, TIM_IT_CC2);
IC9Value = TIM_GetCapture2(TIM9);
if (IC9Value != 0)
{
Frequency9 = (RCC_Clocks.HCLK_Frequency)/2 / IC9Value;
}
else
{
Frequency9 = 0;
}
f9=Frequency9/10000.0;
RCC_ClocksTypeDef RCC_Clocks11;
RCC_GetClocksFreq(&RCC_Clocks11);
TIM_ClearITPendingBit(TIM1, TIM_IT_CC2);
IC1Value = TIM_GetCapture2(TIM1);
if (IC1Value != RESET)
{
Frequency1 = (RCC_Clocks11.HCLK_Frequency)/2 / IC1Value;
}
else
{
Frequency1 = 0;
}
f1=Frequency1/10000.0;
}
2014-09-17 04:00 PM
It's like you don't pay attention. The TIM1 CC interrupts go to a different IRQ Handler, you should always qualify your sources when there are two or more potential triggers.
void TIM1_BRK_TIM9_IRQHandler(void)
{
if (TIM_GetITStatus(TIM9, TIM_IT_CC2) == SET)
{
TIM_ClearITPendingBit(TIM9, TIM_IT_CC2);
// TIM9 IRQ Source - Do TIM9 Work Here
}
}
void TIM1_CC_IRQHandler(void)
{
if (TIM_GetITStatus(TIM1, TIM_IT_CC2) == SET)
{
TIM_ClearITPendingBit(TIM1, TIM_IT_CC2);
// TIM1 IRQ Source - Do TIM1 Work Here
}
}
You should read your clocks once, in main() into a global variable, doing them repetitively is pointless, and limits your maximum frequency.