cancel
Showing results for 
Search instead for 
Did you mean: 

Tachometer

vinicius_acvasconcelos
Associate II
Posted on May 28, 2009 at 16:54

Tachometer

6 REPLIES 6
vinicius_acvasconcelos
Associate II
Posted on May 17, 2011 at 13:12

I`m using the st code example ''PWM_Input''. It's working perfect, but the problem is the minimum frequency to measure is 1100Hz.

I wanna to measure frequency starts with 10Hz. How can I modified this example to measure 10Hz, thre is any prescaler to devide the 72Mhz?

The code:

TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;

TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

TIM_ICInitStructure.TIM_ICFilter = 0x0;

TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);

/* Select the TIM2 Input Trigger: TI2FP2 */

TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2);

/* Select the slave Mode: Reset Mode */

TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);

/* Enable the Master/Slave Mode */

TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);

/* TIM enable counter */

TIM_Cmd(TIM2, ENABLE);

/* Enable the CC2 Interrupt Request */

TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);

void TIM2_IRQHandler(void)

{

/* Clear TIM2 Capture compare interrupt pending bit */

TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);

/* Get the Input Capture value */

IC2Value = TIM_GetCapture2(TIM2);

if (IC2Value != 0)

{

/* Frequency computation */

velmotor = (72000000/ IC2Value);

}

else

{

velmotor= 0;

}

}

Thanks.

jaroslaw2
Associate II
Posted on May 17, 2011 at 13:12

Try this:

Code:

<BR>TIM2->PSC=(u16)iPrescalerForPWMI; <BR>

[ This message was edited by: jaroslaw.oska on 25-05-2009 14:38 ]

vinicius_acvasconcelos
Associate II
Posted on May 17, 2011 at 13:12

The PSC is used select the numbers of envents to capture, I wanna only one envent(the period to measure the frequency).

Quote:

On 25-05-2009 at 14:36, Anonymous wrote:

Try this:

Code:

<BR><BR>TIM2->PSC=(u16)iPrescalerForPWMI; <BR><BR>

[ This message was edited by: jaroslaw.oska on 25-05-2009 14:38 ]

[ This message was edited by: vinicius_acvasconcelos on 25-05-2009 16:54 ]

vinicius_acvasconcelos
Associate II
Posted on May 17, 2011 at 13:12

I solved the problem :-] using a function to devide the tim clock, for 655535. Now the frequency step is around 0.016Hz. I'm able to measure the 40 Hz.

TIM_PrescalerConfig(TIM2, 0x1987, TIM_PSCReloadMode_Immediate);

TIM2_IRQHandler:

/* Clear TIM2 Capture compare interrupt pending bit */

TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);

/* Get the Input Capture value */

IC2Value = TIM_GetCapture2(TIM2);

velmotor = (11017.5975/ IC2Value);

jaroslaw2
Associate II
Posted on May 17, 2011 at 13:12

Did you see function you've used?

void TIM_PrescalerConfig(TIM_TypeDef* TIMx, u16 Prescaler, u16 TIM_PSCReloadMode)

{

/* Check the parameters */

assert_param(IS_TIM_ALL_PERIPH(TIMx));

assert_param(IS_TIM_PRESCALER_RELOAD(TIM_PSCReloadMode));

/* Set the Prescaler value */

TIMx->PSC = Prescaler;

/* Set or reset the UG Bit */

TIMx->EGR = TIM_PSCReloadMode;

}

vinicius_acvasconcelos
Associate II
Posted on May 17, 2011 at 13:12

Quote:

On 26-05-2009 at 07:06, Anonymous wrote:

Did you see function you've used?

void TIM_PrescalerConfig(TIM_TypeDef* TIMx, u16 Prescaler, u16 TIM_PSCReloadMode)

{

/* Check the parameters */

assert_param(IS_TIM_ALL_PERIPH(TIMx));

assert_param(IS_TIM_PRESCALER_RELOAD(TIM_PSCReloadMode));

/* Set the Prescaler value */

TIMx->PSC = Prescaler;

/* Set or reset the UG Bit */

TIMx->EGR = TIM_PSCReloadMode;

}

You are write. I had mistake PSC for IC1PS. The correct is change the PSC and not the IC prescaler.

Thanks