View previous topic :: View next topic |
Author |
Message |
sf
Joined: 02 Jul 2007 Posts: 9
|
Time difference with ds1302[RESOLVED] |
Posted: Sat Jun 28, 2008 3:35 am |
|
|
Hi, i´m on a project that need to know the total time that a motor is working,
but my problem is when:
Start date/hour: 2008/06/30 23H 00m 00s
End date/hour: 2008/07/01 1H 00m 00s
The difference in seconds give me 2584800 seconds
While if :
Start date/hour: 2008/06/29 23H 00m 00s
End date/hour: 2008/06/30 1H 00m 00s
give the expect result: 7200 seconds.
I´m using the code post here: http://www.ccsinfo.com/forum/viewtopic.php?t=25611
What i´m doing wrong?
Thank´s on advance!!!!
Last edited by sf on Sun Jun 29, 2008 3:30 am; edited 1 time in total |
|
|
Ttelmah Guest
|
|
Posted: Sat Jun 28, 2008 3:57 am |
|
|
Note the comment at the start of the code. It expect '08', not '2008'.
I'd expect this is causing an arithmetic 'wrap'.
Best Wishes |
|
|
sf_ Guest
|
|
Posted: Sat Jun 28, 2008 4:48 am |
|
|
Yes, I enter 08 in the year and the result is the same |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sat Jun 28, 2008 6:33 am |
|
|
Your ancestors will hate you for causing the Y3K bug! _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Ttelmah Guest
|
|
Posted: Sat Jun 28, 2008 7:14 am |
|
|
Are you running a V4 compiler?. Any chance you are in ANSI mode, not in CCS mode?. If so, the arithmetic will wrap. You need to change all the 'int32' entries to read 'unsigned int32'. The ANSI mode, defaults to using signed arithmetic, while the CCS mode defaults to using unsigned. This would cause the results to go screwy.
Have put your 'test' values, diectly into the posted code, and it works fine for me.
Best Wishes |
|
|
sf
Joined: 02 Jul 2007 Posts: 9
|
[RESOLVED] |
Posted: Sun Jun 29, 2008 3:28 am |
|
|
if I had done like you, introduced the values directly, I will don´t had this error , i put the values, directly into the code, and it works fine.
So it´s my mistake on introduction the values.
Thank´s, I learn another thing, to test a function eliminate all the unnecessary code, just the basic. |
|
|
Ttelmah Guest
|
|
Posted: Sun Jun 29, 2008 4:15 am |
|
|
You will see this pointed out by the 'old hands', very often here. The standard 'rule', is to keep removing code, till the problem disappears. You have then narrowed down where to look.
Best Wishes |
|
|
|