cancel
Showing results for 
Search instead for 
Did you mean: 

time measurement question

epassoni9
Associate II
Posted on January 19, 2010 at 05:25

time measurement question

7 REPLIES 7
epassoni9
Associate II
Posted on May 17, 2011 at 15:07

Hi,I have an hard question.

I have an external interrupt generated by the power line (50hz).

I'm using an stm8s and I'm using the STM8S207RBT6 and the pin PE6 for the external interrupt.

All hardware timers are available.

I can't use a different pin.(So no input capture for example)

I want to measure the time between one interrupt and the next one.

Is it possible to do it with an hardware timer(tim1,tim2,tim3,tim4) ?

thanks in advance,

Spectre

fggnrc
Associate II
Posted on May 17, 2011 at 15:07

Hello Spectre!

If a counter is running, you can make a software input capture by reading its value. Then you do the usual math...

Of course, this math is easier if the auto-reload counter value is maximum (i.e. 0xFFFF if your timer counts upwards).

There is also another way to measure the power line frequency.

The external interrupt handler increments a variable which is reset after a given time period. For instance, if this variable is reset after 10 seconds, its value is the mains frequency in tenths of Herz.

Ciao

EtaPhi

epassoni9
Associate II
Posted on May 17, 2011 at 15:07

Ciao Etaphi,

thanks for the advice!

It works.

bye,

Spectre :D

epassoni9
Associate II
Posted on May 17, 2011 at 15:07

Ciao Etaphi 🙂 ,

My idea is to use an hardware timer(like tim4) as free running counter by resetting its counter on the first interrupt,and read the counter value (and reset it again) on the next interrupt.

Do you agree with me ?

Best regards

Spectre

fggnrc
Associate II
Posted on May 17, 2011 at 15:07

TIM4 doesn't suit your needs.

It can measure up to 2.024 ms time intervals @ 16 MHz.

It's better to use TIM3 or TIM2 and choose a prescaler so that timer resolution is optimal.

Besides timer choice, your idea works!

Ciao

EtaPhi

dhutchison1945
Associate II
Posted on May 17, 2011 at 15:07

dhutchison1945
Associate II
Posted on May 17, 2011 at 15:07

ok