Have a headache - need some suggestions with code logic


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Have a headache - need some suggestions with code logic

    The Ds1307 has onboard user memory - if you run the IC battery backed, you will have the current time when power is restored. Also you could store your PWM variables there as well, and be resilient to power cut corruption.

    I would suggest that it may be easier to use minutes (word Var) for your calcs internally, 1440 minutes per day, 3600 secs per hour.

    So for your first 14:00 - 14:30 that would be start at 840 minutes and end at 870 minutes, difference being 30mins = 1800 secs - divide that by 128 which gives 1 per 14secs approx increase of PWM value.

  2. #2
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: Have a headache - need some suggestions with code logic

    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-

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: Have a headache - need some suggestions with code logic

    I would use Darrel's interrupts to measure time.

    http://www.picbasic.co.uk/forum/showthread.php?t=3251

    Robert

Similar Threads

  1. Code check and refinement suggestions?
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 31st July 2013, 03:37
  2. Replies: 3
    Last Post: - 13th September 2008, 18:40
  3. Your Suggestions: Assembly code material?
    By dw_picbasic in forum General
    Replies: 1
    Last Post: - 2nd February 2007, 18:33
  4. Pushbutton code routine suggestions?
    By jessey in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd September 2005, 02:02
  5. DS1820 headache
    By Calco in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 12th August 2004, 01:28

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts