combining mills() and micros()

Can we combine millis() and Micros() in same program, just like the one given below
loop()
{
start=micros();

if((start-enD)>=some_value)
{

enD = micros();
do something;
call_routine();
}
}

call_routine()
{
st=millis();
if((st-en)>=some_value)
{

en = millis();

}

Sure.
You don't need to ask for permission

The reason I am asking this is because I have a program with the similar structure as above, but mysteriously freezes after 2 hrs. I was wondering, if this could be the reason. Is there any debug monitor available that can dump before the controller freezes?

What is the type of your variables 'start' and 'end' ? If they are unsigned long, they are limited to 2^32-1 = 4,294,967,295 which is 4294 seconds, almost 1 hour 11 minutes and 30 seconds. Maybe your code does not handle the fact that 'end' becomes lower than 'start'.

gary36:
is there any debug monitor available that can dump before the controller freezes?

No.

Even if there was, how would it know that the program was going to freeze sometime (a few microsecs) in the future?

Put some Serial.print() statements in your code and the last one printed will give you an idea of where the program had got to before the freeze.

Things that cause programs to freeze after some time are the use of the String (capital S) class and writing beyond the bounds of an array.

If you want more help then post your program.

...R

It is possible to use micros() in the same way as millis(), but now you have a millis() timer within a micros() timer. It will be hard to predict what will happen in every situation.
I have an example of millis() within millis(), using a bool variable to enable the other one.

Yes, I am using unsigned long int for the variables. I have manually checked for array bounds and I do not use string class. But the program freezes

gary36:
Yes, I am using unsigned long int for the variables. I have manually checked for array bounds and I do not use string class. But the program freezes

OK, let us know if you need any help.

Good luck.

A L W A Y S
Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

Could I get some tips of how to debug the code myself before seeking help?

+1 for wanting to help yourself !

Google can help you there:

http://www.gammon.com.au/forum/?id=12153