touble with a time calculation


Closed Thread
Results 1 to 40 of 59

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    hows this going to work
    if Days => Set_Day and Hours => Set_Hour and _
    Minutes => Set_Min and Seconds => Set_Sec and _
    100th => Set_100th then OT_Enable = 1

    imagine set day=0 set hour=1 set min=30
    if hour = 2 and min=29 then it will test false when it should be true

    u need to think in terms of timestamp
    timestamp= sec+min*60 +hour*3600 etc day * whatever. (unix does it from some arcane date in 1980 in microseconds)
    then compare timestamp
    this will not solve rollovers however

    from wiki
    unix timestamp 00:00:00 UTC on January 1, 1970
    Last edited by richard; - 13th May 2014 at 07:46.

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    just for the sake of an argument on a raspberry pi
    you could just go datetime.datetime(now)-settime and you wold get a RESULT in years,months,days,hours,minutes,seconds and microseconds
    a pi costs about 40 bucks has 512m of ram usb and Ethernet built in . makes life easy

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

    Quote Originally Posted by richard View Post
    just for the sake of an argument on a raspberry pi
    you could just go datetime.datetime(now)-settime and you wold get a RESULT in years,months,days,hours,minutes,seconds and microseconds
    a pi costs about 40 bucks has 512m of ram usb and Ethernet built in . makes life easy
    Are you advising us all to use Raspbbery Pi?

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    not at all however it depends on the size of the task ,think of moving bricks with a Toyota corolla if you only need to move a few its fine, to move 10000 would be an ordeal better suited to a tray truck with hydraulic loader.
    pbp is a great product but if you want to do a lot with floats, longs , singed math , datetime objects colour gui's etc then other platforms and languages make life a lot easier.

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

    Easy does not increase understanding.

    Unfortunately we live in a plug and play world. The Pi was created to address the issue of children not understanding how computers work and introduce them to programming so it is made easy to produce quick results and grab their imagination. What it does not do is teach electronics. But as I have never had one my opinion is not a first hand informed one.

    Anyway this thread is about time calculation not Pi and have we just hijacked a thread which is against the rules?

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    do I understand the problem correctly
    I'm assuming we have a set time day-h:m:s.xx ie day 0 hour 2 minute 30 sec 28.34 and that we then subsequently read a clock and calculate the elapsed time between now and the set time if and only if the now time is greater than the set time .
    is this right ?

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

    Richard No.

    longpole001's program counts down to set time then counts up after set time.

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

    so far this is the only place the comparison is made , the flag is used from that point for the other routines

    I am down to he last 5k of code space on 128k chip and a fair way to go , i have sd card / code running so i now have to some how make the menu's , some fonts etc all run from the fat16 card , which will need to be somehow index to the menu data, fonts etc , which i not done before ,

    so after this clock bit is done, and some oher issues , this will be the next task and i am sure another thread

    but examples if anyone has any where the sd card code can


    a. a routine that copies the selected lookup table into the created indexed file on the SD , which is accumulative , and returns the indexed start point + data length , the next free point of file for next entry , value back to the program where the routine was called.
    c. after output file has been made by the routine above , it is removed from the compile
    d. the code that gets the stored data from the start point + length references , fills the required lookup table, as used

    i am not sure if SDFS can have more than 1 open file at a time for reading and writing on the fly,but i can see it may need to for other data file creation

    regards

    Sheldon





    the code can make an indexed output hex file of the selected data of the varable sized lookup tables that need to be placed into that hex file
    c data with an indexing system for the hex file to find the data which will be on the sd card
    d. method and code to assemble the data back into the required lookup table using the index.

    i am sure its been done but i could not find an example so far in pbp

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

    I have done the routine you intend using an SD card for but I used on board EEPROM (18F452).

    The data in the EEPROM could be changed within the program using keypad and serial LCD display.

    However to place the initial data into the EEPROM I created a program just to do that thereby saving code space. But you are thinking in terms of "code"?

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    EL2_Allow is a Var bit , atm , and that code would require it to become VAR byte , i am getting very full on this chip and every byte less in mem is a good move ,

    i am thinking since the value i am looking for is either 0 or 1 , can i leave the variable as a BIT , even though values higher than 1 are going to occur ?

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

    Quote Originally Posted by longpole001 View Post
    EL2_Allow is a Var bit , atm , and that code would require it to become VAR byte , i am getting very full on this chip and every byte less in mem is a good move
    Tight for space is a very good reason to make the code more efficient.

    Obviously you have a routine that sets the time could you set the EL2_Allow and other "flags" within that code. I am thinking that at present the same comparisons are made multiple times in different places.

    I am also led to believe that compound statements are inefficient.

    Code:
    EL2_Allow =  0
    EL2_Allow =  EL2_Allow + Event1_OT_Day
                        EL2_Allow + Event1_OT_hour 
                        EL2_Allow + Event1_OT_Min         ' if all values are 0 , then don't enable the overrun timer 
                        EL2_Allow + Event1_OT_sec 
                        EL2_Allow + Event1_OT_100th
    is more efficient than

    Code:
    EL2_Allow =  Event1_OT_Day + _
                        Event1_OT_hour + _
                        Event1_OT_Min + _            ' if all values are 0 , then don't enable the overrun timer 
                        Event1_OT_sec + _
                        Event1_OT_100th
    can you explore this idea by trying both ways. This is food for thought for both of us which is very interesting.

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

    A clock does not have values of

    24 hours
    60 min
    60 sec
    100 100th

    for example a clock showing 59 seconds will change to 0 on the next second.

    the calculation

    if Seconds - Set_Sec <0 then
    OT_Minutes = OT_Minutes - 1
    OT_Seconds = 60 - Set_Sec + Seconds
    endif

    should be

    if Seconds - Set_Sec <0 then
    OT_Minutes = OT_Minutes - 1
    OT_Seconds = 59 - Set_Sec + Seconds
    endif

    and the same for the other < comparisons.

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    yes it should as its look for 0 only value , also removing the "and" will reduced compile size as well a little , good idea

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


    Did you find this post helpful? Yes | No

    Default Re: touble with a time calculation

    that cool steve , let me know if i can give any further details

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

    No problem Sheldon apart from me being a perfectionist of course. There are some parts of the code that are hard for me to follow, which has set me thinking.

    This

    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
    is easier to read like this

    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
    you could also do something like

    Code:
    EL2_Allow =  Event1_OT_Day + _
                        Event1_OT_hour + _
                        Event1_OT_Min + _            ' if all values are 0 , then don't enable the overrun timer 
                        Event1_OT_sec + _
                        Event1_OT_100th
    if  EL2_Allow = 0 then  EL2_Enable = 0 ' Disable El2 Counter
    Just thoughts that need testing out. I am wondering if bitwise comparators could be used in the last version. Could also possibly have

    Code:
    EL2_Enable =  Event1_OT_Day + _
                        Event1_OT_hour + _
                        Event1_OT_Min + _            ' if all values are 0 , then don't enable the overrun timer 
                        Event1_OT_sec + _
                        Event1_OT_100th
    Would that work?

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