This is going to be a strange request. I must warn that I am new to embedded programming and therefore what is obvious to you may not be to me. I am trying to implement a real time clock program with the data then being transmitted on CAN. I am getting some warning when I compile my code and cannot understand what I need to do. Any help would be appreciated. I will be posting my code in parts as I cannot exceed a certain character limit.
Agreed. Well for right now I just want to make sure that I am able to successfully keep track of time and account for a day rollover. After making the necessary changes I currently find that from 18:59:59 there is a sudden jump to 19:44. Here is what I got on the CAN network: 2944.019787 1 Statistic: D 1 R 0 XD 0 XR 0 E 0 O 0 B 0.20% 2944.798350 1 CAN_ID Rx d 6 18 59 06 10 20 08 2945.019787 1 Statistic: D 1 R 0 XD 0 XR 0 E 0 O 0 B 0.20% 2945.798605 1 CAN_ID Rx d 6 18 59 06 10 20 08 2946.019787 1 Statistic: D 1 R 0 XD 0 XR 0 E 0 O 0 B 0.19% 2946.798860 1 CAN_ID Rx d 6 18 59 06 10 20 08 2947.019787 1 Statistic: D 1 R 0 XD 0 XR 0 E 0 O 0 B 0.20% 2947.799115 1 CAN_ID Rx d 6 18 59 06 10 20 08 2948.019787 1 Statistic: D 1 R 0 XD 0 XR 0 E 0 O 0 B 0.20% 2948.799430 1 CAN_ID Rx d 6 19 44 06 10 20 08 2949.019787 1 Statistic: D 1 R 0 XD 0 XR 0 E 0 O 0 B 0.20% 2949.799705 1 CAN_ID Rx d 6 19 44 06 10 20 08 2950.019787 1 Statistic: D 1 R 0 XD 0 XR 0 E 0 O 0 B 0.20% 2950.800020 1 CAN_ID Rx d 6 19 44 06 10 20 08
So, if you ask a question here directly whenever you get stuck - exactly how will you learn how to find errors in your code? Exactly what do _you_ do right now, to figure out where you go wrong? Are you single-stepping in the debugger? Are you looking at the intermediaries?
"[...] account for a day rollover."
But you are not.
What use do you have of the time.daysb variable, when you always start with the value zero?
time.daysb = 0; if (time.daysa > time.daysb) { current_day = current_day + 1; } time.daysb = time.daysa;
After your counter reaches past 86400 - what do you think will happen on every call to the function?
What Per is saying is true. Seems like you are new to programming. It is ok to be a little ambitious in the beginning but be prepared to fight it out. Keep checking your code. Usually you will notice something wrong every 2-3 times. Also see if you can do some debugging when the code is running.
Try initializing time.daysb to 0 outside the function. Otherwise it will always be 0 and on a rollover time.days will always be greater. Also try ending the if-else ladder with just an else. Better way to end execution of the ladder.