|
|
Component
FreeCntr
Time measurement based on counter value (suitable for short time periods)
Component Level: Low
Category:
CPU Internal Peripherals-Timer
Typical Usage:
(Examples of a typical usage of the component in user code.
For more information please
see the page Component Code
Typical Usage.)
Assume component name is "FC1".
(1)
MAIN.C
void main(void)
{
unsigned char i;
FC1_TTimerValue Time;
FC1_Reset(); /* reset the counter */
for(i = 0; i < 255; ++i); /* for-cycle */
/* get measured time of whole for-cycle */
if (FC1_GetCounterValue(&Time) == ERR_OK) {
#if defined(FC1_UP_COUNTER)
/* MilliSeconds = Time * 1000 / FC1_COUNTER_INPUT_CLOCK_HZ; */
#elif defined(FC1_DOWN_COUNTER)
/* MilliSeconds = ((FC1_TTimerValue)(-Time)) * 1000 / FC1_COUNTER_INPUT_CLOCK_HZ; */
#else
#error UP/DOWN COUNTER not defined
#endif
}
}
(2)
MAIN.C
void main(void)
{
FC1_TTimerValue Time_Start, Time_End, Diff;
FC1_GetCounterValue(&Time_Start);
/* something to measure */
FC1_GetCounterValue(&Time_End);
#if defined(FC1_UP_COUNTER)
Diff = (FC1_TTimerValue)(Time_End - Time_Start);
#if defined(FC1_RESET_ON_COMPARE) /* Reset on compare selected? */
if (Time_End < Time_Start) Diff += (FC1_TTimerValue)FC1_PERIOD_VALUE;
#endif
#elif defined(FC1_DOWN_COUNTER)
Diff = (FC1_TTimerValue)(Time_Start - Time_End);
#if defined(FC1_RESET_ON_COMPARE) /* Reset on compare selected? */
if (Time_Start < Time_End) Diff += (FC1_TTimerValue)FC1_PERIOD_VALUE;
#endif
#else
#error UP/DOWN COUNTER not defined
#endif
/* MilliSeconds = Diff * 1000 / FC1_COUNTER_INPUT_CLOCK_HZ; */
}
|