Logic


Closed Thread
Results 1 to 5 of 5

Thread: Logic

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583

    Default Logic

    Hi Guys,

    Needs a little more advise to help sort out a small logic issue that I can't get my head round

    Following on from my previous threads, I use a word variable counter1 to count the minutes from midnight, and use other variables that are either < = > this counter to turn lights on etc. As the main outputs will come on and off in the same day this counter method works fine, but where the logic falls over is if the on times are pre-midnight, and the off times are post midnight as the counter resets back to zero at midnight. I've therefore tried adding a day counter so that at midnight the variable changes from 0 to 1, and then is reset at mid-day.

    This output would normally be on say from any time between 8pm and 11pm one day and then go off any time the next day, for example on at 8pm then off at 12.00 noon next day, so the on time would equal 1200 and off time would be 720. This is what I've tried, but still fails

    Code:
    if  counter1 => sumplighton then 
    high sump_light
    Endif
    
    If sumplightoff < sumplighton and daycount=0 then
    LOW sump_light
    endif
    
    If sumplightoff < sumplighton and daycount=1 then
    high sump_light
    endif
    
    
    IF counter1 => sumplightoff and daycount=0 then
    LOw sump_light
    Endif
    Any help would be appreciated

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Logic

    This doesn't really answer your question but why don't you have one ON-time and one OFF-time?

    For example
    Code:
    If Output1 = OFF THEN
       If Counter1 = Output1OnTime Then
         Output1 = ON
      ENDIF
    
    ELSE    ' Output is ON
    
      If Counter1 = Output1offTime Then
        Output1 = OFF
      ENDIF
    
    ENDIF
    Now, there are 1440 minutes in 24hours.
    If Output1OnTime = 1438 and OutputOffTime = 2 the output will turn on at 23:58 and off at 00:02.
    If OutputOnTime = 2 and OutputOffTime = 1438 the output will turn on at 00:02 and off 23:58.

    If you have multiple outputs then you can preferably use arrays to store states, on and off times and simply index thru them each time your minutes counter "tick" to see if any needs changing state.

    /Henrik.

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Logic

    Must be the cold in my head that's causing me to make things too complicated...

    Code:
    If daycount = 0 THEN
       If Counter1 = sumplighton Then
         high sump_light
         daycount = 1
      ENDIF
    ENDIF
    
    IF daycount = 1 THEN
      If Counter1 = sumplightoff Then
        low sump_light
        daycount = 0
      ENDIF
    ENDIF
    based on your example I came up with the above which works just fine !

    Thanks Henrik

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


    Did you find this post helpful? Yes | No

    Default Re: Logic

    sumplight off time = sumplight on time + sumplight duration
    if sumplight off time > 1440 then sumplight off time = sumplight off time - 1440 and set next day flag

    ...
    then we have a flag (slf) that is 1 when sumplight is on else 0 and a next day flag (ndf) that is set to 1 when offtime overflows else 0
    the ndf flag is cleared at midnight in you time routine , the chklight sub is called once every minute

    chklight: check light subroutine
    if slf=0 then
    if count >= on time then
    slf=1
    offtime = count+duration
    ndf=0
    if offtime >1440 then
    offtime=offtime -1440
    ndf=1
    endif
    turn on light
    endif

    else
    if ndf=1 then return
    if count >= offtime then
    slf=0
    turn off light
    endif
    endif
    return




    return

  5. #5
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Logic

    Richard, thanks for the input.

    I've made one modification to include a > in the first line of the code I posted above and it's been running fine. But thanks as always for your contribution

    Malcolm

Similar Threads

  1. Time logic
    By Scampy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 28th October 2013, 14:40
  2. Logic Probe Recommendations
    By retepsnikrep in forum Off Topic
    Replies: 3
    Last Post: - 12th June 2011, 20:35
  3. PORTA Logic - Be the processor
    By Darrel Taylor in forum FAQ - Frequently Asked Questions
    Replies: 29
    Last Post: - 9th March 2009, 18:18
  4. Logic Level Triac
    By emavil in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th November 2006, 18:18
  5. Fuzzy logic?
    By Damir in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 28th August 2006, 12:03

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