Forum: Mikrocontroller und Digitale Elektronik Measurement of time in MCU


von Lars Denker Joergensen (Gast)


Lesenswert?

Hello

I have to perform some timing tests in the Renesas M16C. What is the
best way to calculate the time from start to end? Right now I have
created a counter, which is incremented each 1/10000 second by a timer.
However if I start another timer with an interval of 1/10 second, I get
a deviance of approx. 1/1000 second, when I read the counter at each
interrupt.

Of course I will get some uncertainty on my clock, which is okay. But
is there another (better) way of doing this? A high precision timer,
perhaps? Usage of the subclock? I could use an external timer, but I
don't think I have time to do this...

Thanks
Denker

von peter dannegger (Gast)


Lesenswert?

"A high precision timer, perhaps?"

all hardware timers are high precision and counting exact the crystal
clock without any error.

An error can only occur, if a bad interrupt handler was written, which
was sensitive against the interrupt response time and the delay by
other interrupts.

Typical ways for accurate timer interrupt handlers are:

- use the clear on compare or autoreload feature

- use a compare interrupt and add the desired interrupt time to the
next compare value

- use an overflow interrupt, stop the timer, add the value, where the
timer count must be shorten and start the timer again. The time, where
the timer was stopped, must also be added.



Peter

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.