Hello Robert,

On 01/16/2012 06:49 AM, Robert Epprecht wrote:
> "pito"<p...@volna.cz>  writes:
>
>> long time back I used these words for time measurements:
> [...]
>
> Thanks, looks easier then i thought it would be.
> Will try to do something similar.
>
> Is there a special reason you selected timer 2?
> I was thinking about using timer 0.


"Measuring time" is more diverse than it seems.

* Do you want to know, how long something takes?
   Start and Stop condition are in the programm.

Then use any timer, feed it any availabe clock_source/prescaler
combination. Clear the timer register, start the timer, stop
and read the timer ...


* Do you want to measure the length of an external
   event? An external pulse length maybe?

Then you can use a timer providing the Input-Capture
feature. The rising edge of the external pulse triggers
the start of the timer, the falling edge triggers the
timer to stop. You need to wait or poll for the event
to finish, but then you just read the timer register ...


* Do you want to keep track of time? Like in a clock?
   And maybe periodically run some functions?

Then you could use any timer as well. But you could
also use timer2, which dann be connected to a clock
crystal running at 32768 Hz. If the prescaler is
off, this gives 128 timer overflows per second.
I call them "ticks".

The mainloop runs a routine, which will see that a tick
has elapsed. This routine does all the bookkeeping
of ticks, seconds, minutes, hours, day, month, year.
If a second (or any defined intervall) is over, it will
set a flag.

The rest of the main loop checks these flags and if set,
calls the work to be done. These are called
job.tick, job.sec ... in my application.

If tracking time like this is not accurate enough, add
a phase shift register to the mix. It will basically say:
after so many ticks, make some correction.


* Do you want to measure a frequency of an external pulse
signal?

a. count N of them, measure the elapsed time t: f=N/t
b. measure the time between consequtive rising edges: f=1/t
c. measure some given time intervall and count the pulses: f=N/T


* Do you want to produce a pulse train with specific timings?

PWM might do the job. Waiting and bit banging might do the job.
Extra periphery might do the job, e.g. a 1wire controller connected
to twi.


It all depends on the conditions. How long is the time, you
want to measure? How accurate should it be?


I can provide code for some of these, if you are interested.

Cheers,
Erich


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel

Reply via email to