touble with a time calculation - Page 2


Closed Thread
Page 2 of 2 FirstFirst 12
Results 41 to 59 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

    the isr updates EL0,EL1 , EL2 during the call

    the isr reloads timer1 every 10ms , then updates EL0-2 variables during that call and displaying them take time ,

    a long as the running display is clearly correct for EL2 =EL1 - set_times for sec,min, hour ,day , then i think it be ok.

    at the moment its just show the totaly wrong values for duration of the set time

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    thanks guys

    ill try both ways i rather not have wrong calculations but i also know this interupt is serviced every 10ms , and the E0-2 varables should be correct for that amount of time ??

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    that's the wrong way to think about it , you can never know when the 10ms period will start or finish , this way is better.
    the interrupt latency with a 32mHZ clk will be about 10uS anyway , time to copy 4 bytes to a buffer say 4 uS , the interrupt will only be deferred 4uS plus another couple for the int disable enable worst case you'll hardly notice

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    hI GUYS , using the code by steve seems to work , a small change cos i use EL1 values to show the current time value , so any changes that change the EL1 values in the calculating the EL2 , is not possible so i need to copy the values of EL1 to EL3 , then use EL3 as a temp group

    I am trying to disable the interupt whilest in the ISR subroutine , before the copy of EL0 to EL1-3 , then re -enable interrupt after ,

    but i get a interrupt priority state not found error when compile atm

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    it serves no purpose to stop the isr from within the isr , its a waste of time copying the el vars to a buffered copy inside the isr .
    time in your case is in essence a multi byte var , the value is volatile and cannot be guaranteed outside the isr when the isr is running.
    the correct procedure is
    disable isr
    copy bytes to buffer
    enable isr
    do your subtraction

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    ok done that , cheers

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    steve was wodering what the code may be if i was to use the el1 values plus event1 setting to the overrun point , and use say event 2 seting to show the amount time left before overrun , eg EL0 is counting up , copied to EL1 for display , Event 1 setts time for the overrun , Event2 sets time to show time before reching the overrun time , EL3 displays the time counting down to reach time set by Event1 time.

  8. #8
    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

    Probably easy to do. Post some code from the relevant section for me to look at.

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    ok well EL0 is counting up , EL1 and EL3 are copys of EL0
    EL4 is the time left in the event

    Event1_OT = time duration of event
    Event2_OT = Time when to display the timeleft clock
    i
    f EVent1_OT all 0 then disable time left clock
    if Event2_OT all 0 then no timeleft clock

    Event2_OT can not be > Event1_OT set time

    Code:
     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 ' Disable El2 Counter   
              EL2_Allow = 0  ' clear Flag so EL4 wont start   
        else
              EL2_Allow = 1  ' Event1 setting Higher than 0 so allow EL4 to be enabled if Event2 settings are higher than 0 
        endif
        
    
    ' ---------------------
    
     if  Event2_OT_Day = 0 and Event2_OT_hour  = 0 and Event2_OT_Min = 0 and _  
           Event2_OT_sec = 0 and Event2_OT_100th = 0 then 
             EL4_Allow = 0  ' disable Event End Timer - EL4 
       else
             EL4_Allow = 1  ' Allow Event End Timer - EL4 
       endif 
       if EL2_Allow = 1 and EL4_Allow = 1 then                        ' if Event1 times set and Event2 times set then allow EL4_enable to start Event End timer 
          
           if EL1_Days    <= Event2_OT_Day and EL1_Hours   <= Event2_OT_Hour and _
              EL1_Minutes <= Event2_OT_Min and EL1_Seconds <= Event2_OT_Sec  and _
              EL1_100th   <= Event2_OT_100th then EL4_Enable = 1                                ' show clock when time left in event
    all i have so far

  10. #10
    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

    Have you got any further?

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