Modulating Valves

Discussion in 'Pascal Logic Code Examples' started by carlg, Dec 31, 2016.

  1. carlg

    carlg

    Joined:
    Jan 29, 2009
    Messages:
    43
    Likes Received:
    0
    Hi I am looking at a way to modulate some water valves,(16 in total).
    The scenario is when GA1 on the Set GA2 ON for 10Mins and Then OFF for 5Mins. And as long as GA1 is On then then it keeps repeating.

    Now I have done this using logic timers, but cant do the full 16 valves as each GA Group takes two logic Timers, PAC cant have more than 20 timers.

    Has anyone got any ideas
     
    carlg, Dec 31, 2016
    #1
  2. carlg

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    You can do this without any timers. Just count down each minute yourself. Since you have to do the same thing for 16 valves you can create an array of the ga's and times and just loop through them each minute:

    Code:
    //Global variables
    
    valveEnableGAs: array[0..16] of char;
    ValveOperateGAs: array[0..16] of char;
    ValveCycleTimes: array[0..16] of char; // Total time in minutes between the start of each cycle (i.e. OFF time + On time
    ValveOnTimes: array[0..16] of char; // On time in minutes;
    ValveStartDelays: array[0..16] of char; // Delay  on startup for each valve (minutes);
    ValveCounters: array[0..16] of integer;
    ValveNo: integer;
    
    // Initialization
    
    valveEnableGAs := #1#3#5#7#9#11#13#15#17#19#21#23#25#27#29#31;  // These are the 16 GSa that enable the valves
    ValveOperateGAs := #2#4#6#8#10#12#14#16#18#20#22#24#26#28#30#32; // These are the GAs of the valves
    ValveCycleTimes := #15#15#15#15#15#15#15#15#15#15#15#15#15#15#15#15; // Time, in minutes, for each complete cycle (i.e. OFF + ON)
    ValveOnTimes := #10#10#10#10#10#10#10##10#10#10#10#10#10#10#10; // Time each valve is on (minutes);
    ValveStartDelays := #0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0; // Number of minutes to delay each valve at startup
    for valveNo := 1 to 16 do valveCounters[ValveNo] := ord(valveStartDelays[ValveNo]); // Set initial delays
    
    //Module
    
    if second <> 0 then exitModule;  // Seconds = 0 once every minute
    for valveNo := 1 to 16 do  // Loop for all 16 valves
    begin
      valveCounters[ValveNo] := valveCounters[ValveNo] - 1; // Decrement minute counter for valve
      if valveCounters[ValveNo] <= 0 then  // If <= 0, timer expired, so start next sequence
      begin
        valveCounters[valveNo] := ord(ValveCycleTimes[ValveNo]); // Reset cycle timer
        if GetLightingState(ord(valveEnableGAs[ValveNo])) then // Only if enabled
          PulseCBusLevel("Local", "Lighting", ord(valveOperateGAs[valveNo]), 100%, "0s", ord(valveOnTimes[ValveNo]) * 60, 0%); // Pulse the valve for the on time
      end
    end;
    
    The global variables just define all the arrays to hold the data, which is setup in the intialisation section. I use character arrays here because you can intialise them in a single line. With integer arrays you can only initialise one element at a time.

    The module first checks if seconds is zero, which will only occur at the start of every minute. It then loops though the valves one at a time. It decrements the current minute counter for the valve, and when it gets to zero, resets the count and the pulses the valve ga for its ON time if the enable GA is ON.

    Currently if the enable GA is turned OFF the cycle will run to completion and then stop. You didn't say how you wanted that to work.

    I haven't run this, but is compiles fine and the idea is sound. If you want to limit the number of valves, just change to FOR loop from 16 down.
     
    Ashley, Jan 1, 2017
    #2
  3. carlg

    carlg

    Joined:
    Jan 29, 2009
    Messages:
    43
    Likes Received:
    0
    Ashley.
    Many thanks will give code a try soon.
    I was looking at arrays and got the on working fine, but couldn't get the off to go. I made it harder by using discrete ON and OFF lines, rather than your Pulse command.

    PS. yes when the control group goes off at any point then the Valve GA will also go off.

    Thanks for your help.
     
    carlg, Jan 1, 2017
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.
Loading...