touble with a time calculation


Closed Thread
Results 1 to 40 of 59

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    well after a few more tests that did not work well , yes , when you enter a event period of 10sec for the event time or 1 min or 1 hour , 1day then code answers earlier will allow for the <0 error when it roles over , but its does not when you combine Event set time for say 1 m 10 sec

    so lets start again
    sounds simple but its giving me a problem
    GOAL
    ------
    the count up elapsed base timer is counting up from 0 , when the set time values are => then time set for the event the Overtime clock is enabled starts counting up to show the time past the set time

    code references
    ---------------
    Base Elapsed timer is set to count up = EL1
    Overtime Clock = EL2
    Event1_OT_xxx = Time set duration for event


    EL1 has the standard time duration if statements enabled so that sec = 60 then sec = 0 , min = min +1 , same for hour , day 0 then 1 min , etc etc for counting up


    Code:
    '-------  Event overrun timer 1-------- 
         if EL1_Days => Event1_OT_Day    and EL1_hOURS => Event1_OT_Hour  and _
            EL1_Minutes => Event1_OT_Min and EL1_Seconds => Event1_OT_Sec and _
            EL1_100th => Event1_OT_100th then EL2_Enable = 1
         
        if  Event1_OT_Day = 0 and Event1_OT_hour  = 0 and Event1_OT_Min = 0 and _  ' if all values are 0 , then dont enable the overrun timer 
            Event1_OT_sec = 0 and Event1_OT_100th = 0 then  EL2_Enable = 0
      
         if EL2_Enable = 1 THEN     ;  EL2 = EL1 current values - set overrun value  
            EL2_Days    = EL1_Days    - Event1_OT_Day  
            EL2_Hours   = EL1_Hours   - Event1_OT_hour
            EL2_Minutes = EL1_Minutes - Event1_OT_Min 
            EL2_Seconds = EL1_Seconds - Event1_OT_sec
            EL2_100th   = EL1_100TH   - Event1_OT_100th
         endif

    addings code to allow for <0 error ( EL1_Seconds - Event1_OT_sec) - this occurs when secs role over 1min but the work arround is not working when combined with sat set times of 1min 10 sec


    any further sugestions

  2. #2
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    Code:
         if EL2_Enable = 1 THEN     ;  EL2 = EL1 current values - set overrun value  
    
           EL2_100th   = EL1_100TH   - Event1_OT_100th+100
            if EL2_100th<100 then 
              EL1_Seconds=EL1_Seconds-1
           Else
             EL2_100th=EL2_100th-100
          endif
    
        EL2_Seconds = EL1_Seconds - Event1_OT_sec+60
          if EL2_Seconds<60 then 
            EL1_Minutes=EL1_Minutes-1
         else
           EL2_Seconds =EL2_Seconds -60
         endif
    
           EL2_Minutes = EL1_Minutes - Event1_OT_Min +60
         if EL2_Minutes<60 then
           EL1_Hours=EL1_Hours-1
         else
           EL2_Minutes =EL2_Minutes -60
         endif
    
           EL2_Hours   = EL1_Hours   - Event1_OT_hour+24
         if EL2_Hours<24 then
            EL1_Days=EL1_Days-1
         else
           EL2_Hours   =EL2_Hours   -24
         endif
    
      EL2_Days    = EL1_Days    - Event1_OT_Day  
           
    endif
    Just something to try

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,653


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    steve has the right idea for the math but since el1/el2 vars can be updated via the isr at any time during the calcs the results will vary.

    statisticly it will fail about 4-5 times per hundred calcs based on :-
    I think chances of failure are 1/60+1/60+1/100+1/24 I might be wrong about the stats

  4. #4
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    If isr affects EL1 vars create Temp_EL1 vars at the start of the routine and use these for the calculation.

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,653


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    won't work . the isr can change the values as u copy them to the temp vars ,been there done that

  6. #6
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    Ok some problems do not have an answer.

    Bye

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,653


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    only solution I know is to disable isr and copy vars to a buffer then enable isr and then perform calcs on the buffered data.
    it may mean the odd lost interrupt / whats worse incorrect calcs or missed ints
    only the designer can make that call .

Similar Threads

  1. Help with calculation
    By Megahertz in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th August 2012, 17:10
  2. CHECKSUM CALCULATION, Please Help!
    By wasilus in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd August 2012, 07:55
  3. Calculation Problem - value goes to zero after 65
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 12th March 2010, 05:10
  4. calculation
    By lerameur in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 20th May 2008, 16:28
  5. CRC Calculation - Need a little help
    By Steve43 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 13th March 2005, 01:23

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