Announcement

Collapse
No announcement yet.

How do you 'know' if a time event?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do you 'know' if a time event?

    How do you 'know' if a scheduled time event happened while the PLC was either in STOP mode or not powered?
    Since the P-Series family has no DATEDIFF / TIMEDIFF functionality, I wrote my own.
    It is big and a bit ugly - and is not optimized in any way, yet. But it seems to work.
    I did some testing by setting the PAC date to various day in previous weeks - and a few days from previous months.
    I would set the CPU date t a previous week.month, go STOP MODE, then set data back to today, the go RUN MODE.
    The routine caught every check so far.

    i.e. On Sunday morning "00:00:00", my calibration/verification data is supposed to be invalidated.
    If the P3K is not powered at this time, it is not able to evaluate the DoW and hour/minute/second.


    The PLC calcs total days since 01/01/1970 - including leap days.
    - it seems that the online 'elapsed days' sites (the ones that I looked at) are off by one - they must be counting TODAY, even though today has not elapsed.

    Using this routine:
    The PLC keeps track of its On_time days and DoW every 2 seconds.
    Then at Power On, it calcs elapsed days to the power-on date and stores the PoR_DoW.
    It subtracts the On_time elapsed days from the PoR elapsed days.
    If that diff >= 7 days, we missed it.
    If that diff < 7 days, subtract the On_time_DoW from the PoR_DoW. If that diff is negative, we missed it.

    If we missed the event, twiddle whatever bits to alert operator.

    DoW = Day of Week
    PoR = Power On Reset

    mashva - is this familiar?

    I tried twice to post an image. Huh?
    Maybe P-series could get a mnemonic export? Oh, would that be a serialized java object about 1.5Kb per instruction............
    Last edited by kewakl; 10-28-2019, 11:01 AM.

  • #2
    Could not ADD to the previous post....

    Rung 12 is (NOP)
    It made the lower part too big to get in one screenshot
    Attached Files
    Last edited by kewakl; 10-28-2019, 10:54 AM.

    Comment


    • #3
      Familiar, indeed! So what about if the day the event occurred WAS a leap day? Would it get added as part of the MONTH loop, or in the rungs 19-23 section?

      Comment


      • #4
        guess we'll find out next year
        look at Feb 2020

        [edit] without going thru it all again, I would guess that rungs 19-23 *should* be required to handle it, since if that day is Feb 29, then the WHOLE month has not elapsed.
        Food for thought.
        Last edited by kewakl; 11-18-2019, 08:44 AM.

        Comment


        • #5
          The math seems to work.

          Code:
          Days elapsed 01/01/1970 --> 02/29/2020  = 18320
          Days elapsed 01/01/1970 --> 11/18/2019  = 18217
          
          Days remaining Nov 2019 = 12
          Dec 2019 = 31
          Jan 2020 = 31
          Feb 2020 = 29
          ---------------------
          sum        103
          
          (02/29/20) 18320
          (11/18/19) 18217
          --------------------
          diff       103

          Comment


          • #6
            Originally posted by kewakl View Post
            then the WHOLE month has not elapsed.
            Food for thought.
            Yea I guess that's it. It would be in the last section.

            Now, as long as we dont lose data from DayInMonth()...xD

            Comment

            Working...
            X