Hi, I am doing simple subtraction of two long variables, out of which one variable I have declared as volatile unsigned long TODCounter = 0; I am updating TODCounter variable in TOD Interrupt routine. I have different timeout duration for different operations. To calculate the timeout duration I am storing TODCounter value in one of the unsigned long variable before the starting the operation (StartTime) and checking the difference between current value of TODCounter and (StartTime). To calculate the same I am using the following function ************************************************************************ ************************************** Long_abs (WaitTimer, &TimeDiff); // Function Called void long_abs (unsigned long StartTime, unsigned long* Difference) { if (StartTime - TODCounter < 0) { *Difference = StartTime - TODCounter + MAX_LONG; } else { *Difference = StartTime - TODCounter; } } ************************************************************************ ************************************** After subtraction I suppose to get the actual difference between those values but I am getting very strange results. What could be the reason for above strange results? Please find attached image. Regards, Nitin | |||
| |||
**************************Disclaimer************************************ Information contained in this E-MAIL being proprietary to Wipro Limited is 'privileged' and 'confidential' and intended for use only by the individual or entity to which it is addressed. You are notified that any use, copying or dissemination of the information contained in the E-MAIL in any manner whatsoever is strictly prohibited. *************************************************************************** |
Unsigned long substraction problem...
Started by ●January 17, 2003