Hi all,
I need a help about function operation. I wrote a function that measures the passed time and returns 1 when reaches the input value using timer of the microcontroller. Timer of microcontroller always counts up and function gets timer value when it is called first time, calculates when to terminate and returns 1 when it reaches the input value. Can I use the same function simultaneously to measure another passed time if the variables of the function are all local?
measure_time (t1000);
measure_time (t250);
I want the function return 1 for the t250 when it reaches 250ms and return 1 for t1000 when it reaches 1000ms. Does this function store the local values at different locations of the memory and operate well?
Code:
unsigned char measure_time (unsigned short miliseconds)
{
unsigned long first_ent,ftimer_first, ftimer_last,fcount_first, fcount_last, fcount_before ;
if (!first_ent)
{
ftimer_first = TMR1; // get first timer value
fcount_first = t_count; // get ms begin value
fcount_last = fcount_first + miliseconds; // last ms value
first_ent = 1;
if (fcount_last > 0xFFFF) // if last value is bigger than max t_count value
{
fcount_before = 0xFFFF - fcount_first;
fcount_last = miliseconds - fcount_before;
}
}
ftimer_last = TMR1; // get last timer value
if (t_count == fcount_last && ftimer_last >= ftimer_first) // exit loop
{
first_ent = 0;
return 1;
}
return 0;
}
If not how can I deal with it? Would like to see your answers soon, thanks in advance.
Erhan