cancel
Showing results for 
Search instead for 
Did you mean: 

TIM_PWM_INPUT for 8 inputs

cchechio
Associate II
Posted on September 17, 2014 at 14:57

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?
7 REPLIES 7
Posted on September 17, 2014 at 15:06

CH1 or CH2 of TIM1, TIM8, TIM9, TIM12.

JW
cchechio
Associate II
Posted on September 17, 2014 at 15:17

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 undefined 

Posted on September 17, 2014 at 15:37

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

JW

cchechio
Associate II
Posted on September 18, 2014 at 00:14

ok

with TIM9 CH2 PE6 and  TIM12 CH2 PB15  work.

if I add TIM1 CH2 PE11 I had to use the same IRQHandler that I have used with TIM9.

I don't obtain error but my frequency f is = 0.

Question: Where is my error?

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; 

  

    }

Posted on September 18, 2014 at 00:17

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.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cchechio
Associate II
Posted on September 18, 2014 at 00:33

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 is

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;

  }

  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; 

  

    }

Posted on September 18, 2014 at 01:00

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.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..