2015-08-20 06:26 AM
Hi ,
Please i have to measure frequency from 1Hz to 3Khz with timer 1 (16bits)My SysTick clk = 72Mhz, so i set the prescalor to (1000-1) .So i have a Counter Clock=72Kand than i can capture frequency starting from 1Hz. but the problem that i capture as a minimum a value=12362 which gives a frequency= 72k/12362=5.8hz # 1hz ! i can't understand why it can't capture less than 5.8hz2015-08-20 06:46 AM
Have you allowed for the fact that the counter is going to overflow once or twice during one second ?
Show the code that processes the capture register values. Cheers, Hal2015-08-20 11:21 AM
72000 > 65536
A 72KHz clock will advance 72000 ticks in one second. A 16-bit counter only has 16-bits, and will wrap.You'll need to use a bigger prescaler, or auto-range so you can get better resolution/precision.Consider using a part with a 32-bit timer.2015-08-21 05:49 AM
I don't know will it be possible for you to setup timer interrupt in this mode, but i know that you can generate overflow interrupt, so when you get first edge, you set overflow variable as zero, and increment each time you get overflow.
After that, simple math will allow you to get +17b timer. freq~1/(overflow*65536+timer_value)*88nsvoid InitializeTimer()
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
NVIC_InitTypeDef nvicStructure;
TIM_TimeBaseInitTypeDef timerInitStructure;
timerInitStructure.TIM_Prescaler = 40000;
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = 500;
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
timerInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM2, &timerInitStructure);
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
TIM_Cmd(TIM2, ENABLE);
nvicStructure.NVIC_IRQChannel = TIM2_IRQn;
nvicStructure.NVIC_IRQChannelPreemptionPriority = 0;
nvicStructure.NVIC_IRQChannelSubPriority = 1;
nvicStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicStructure);
}
void TIM2_IRQHandler()
{
if (TIM_GetITStatus(TIM2,TIM_IT_CC2) != RESET)
{
overflow++;
TIM_ClearITPendingBit(TIM2,TIM_IT_CC2);
}
}
2015-08-22 05:08 AM
Thank you ,
but the timer will overflow will be after at the ticks number 65535 and it's able to reach 72000 ticks per second2015-08-22 05:14 AM
I really appreciate ! thanks every body for replying
in my case i have only 16 bit timer and i can't synchronize both timers to get 32 bit timer!the hardware that i'm working on restricts me!2015-08-22 07:29 AM
Let's see if a picture really is worth a 1000 words. See attached.
As Clive1 suggested, change the prescalar. Cheers, Hal ________________ Attachments : TIMEFREQSimple.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1Ek&d=%2Fa%2F0X0000000bk3%2FakzwqQth2rBEoCGu0OyDyjzZSWDr_5aRLjoceT7WGsc&asPdf=false2015-08-22 04:48 PM
It would help if my math was correct. See attached corrected figure.
Cheers Hal ________________ Attachments : TIMEFREQSimple.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1Dx&d=%2Fa%2F0X0000000bk1%2FeYEWnLRphok0B0AThVeHfvLYTqGm5PVf1MFC0pMAU_w&asPdf=false2015-08-24 01:29 AM
Thank you Baird and clive,
it's clear i'll try this.