time measurement question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2010-01-18 8:25 PM
time measurement question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:07 AM
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:07 AM
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:07 AM
Ciao Etaphi,
thanks for the advice! It works. bye, Spectre :D- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:07 AM
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:07 AM
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2011-05-17 6:07 AM
ok
