CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Time difference with ds1302[RESOLVED]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sf



Joined: 02 Jul 2007
Posts: 9

View user's profile Send private message

Time difference with ds1302[RESOLVED]
PostPosted: Sat Jun 28, 2008 3:35 am     Reply with quote

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







PostPosted: Sat Jun 28, 2008 3:57 am     Reply with quote

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







PostPosted: Sat Jun 28, 2008 4:48 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jun 28, 2008 6:33 am     Reply with quote

Your ancestors will hate you for causing the Y3K bug! Wink
_________________
The search for better is endless. Instead simply find very good and get the job done.
Ttelmah
Guest







PostPosted: Sat Jun 28, 2008 7:14 am     Reply with quote

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

View user's profile Send private message

[RESOLVED]
PostPosted: Sun Jun 29, 2008 3:28 am     Reply with quote

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







PostPosted: Sun Jun 29, 2008 4:15 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group