I cannot offer you a programming example, but some thoughts do come to mind...
It is obvious to you as well that in order to save state, the time values will be written to eeprom, then each "next endpoint" fetched as the current is reached? Have I understood your intent so far? If so, in my mind, I think of the time as distance... and think the absolute difference between now and endpoint will provide either seconds or minutes number until next endpoint (I imagine minutes is resolution enough).
Now, knowing the difference between PWM now and PWMgoal you have like units and can determine the PWM step/ unit of time by division. If the PWMgoal is less than the current value, well... multiply by -1 then add to the current PWM as you would if PWMgoal was higher than current value.
I do not believe the power cut issue should be too hard; again, I hope to interpret your post correctly. The DS1307 has a flag set on power interrupt (and the PIC may set a flag similarly) to indicate this interruption. By reading the previous endpoint in this case (from eeprom) rather than the current time , to duplicate the PWMstep value is easy, then to multiply by the difference between the "then" and current time will put you back in place. Or, it may be you write the step value to eeprom and fetch it from there as needed - even every period, second or minute, is not to often to read the value. OOPS! Rereading your post, this is not necessary - just recalculate step value from current time to endpoint would change the ramp value and end at correct time.
Here is an example of my thinking...
From 1:00 to 2:00 is 60 minutes (current time to next eeprom value). If the ramp to value is 128 and current value is 64, then the step value is 64 divided by 60 or 1,06 units PWM added every minute.
From 2:00 to 3:15 is 75 minutes. If the ramp to value is 50 and current value 200, then the step will be 150 divided by 75 or 2, multiplied by -1 for correct direction.
Using the previous, if the time fails at 2:15, then only recalculate the steps (now 60) into the ramp value (150) and get the new value of -2,5 to reach goal in the time remaining.
HTH-
Bookmarks