Alternate between 2 pump modes at set interval?

Do you have a question on how to do something.
Ask in here.
Post Reply
meadowsad
Posts: 53
Joined: Sat Jun 15, 2013 9:56 am

Alternate between 2 pump modes at set interval?

Post by meadowsad »

I have been looking at PaulTurner911s code for his pumps and I am looking to do something similar. Basically I would like to have one pump do a long pulse between 30% and 80% with 2 second pulses while the other pump is at a constant 30%. After 1 hour I would like the pumps to switch so the constant pump is now pulsing and the pulsing pump is now constant. Also I'd like this to happen between 9am and 10pm.

I know how to set the pump speeds but what I can't figure out is how to switch between the two "modes". So I am thinking of having two modes coded like this;

Code: Select all

if mode=1 {
    ReefAngel.PWM.SetDaylight( LongPulseMode(30,80,2,true));
    ReefAngel.PWM.SetActinic(30);
}

if mode=2 {
    ReefAngel.PWM.SetDaylight(30);
    ReefAngel.PWM.SetActinic( LongPulseMode(30,80,2,true));
}
I understand these if statements won't work but this is the idea I am going for. Then I just want to flip between modes 1 and 2 at the top of every hour while between 8am and 10pm. So I was thinking something like this...

Code: Select all

if (now()%SECS_PER_HOUR==0 && now()%SECS_PER_DAY > 28800  && now()%SECS_PER_DAY <= 72000)
{
// code to change modes goes here
}
The above code seems way off to me so any guidance would be greatly appreciated!
Last edited by meadowsad on Thu Sep 26, 2013 12:22 pm, edited 2 times in total.
meadowsad
Posts: 53
Joined: Sat Jun 15, 2013 9:56 am

Re: Switching between 2 pump modes between certain time

Post by meadowsad »

I have been doing some digging while at work and came up with this;

Code: Select all

static int mode;

mode=1-mode;

    
if (now()%SECS_PER_HOUR==0 && mode==1) 
{
    ReefAngel.PWM.SetDaylight( LongPulseMode(30,80,2,true));
    ReefAngel.PWM.SetActinic(30);
}
else
{
    ReefAngel.PWM.SetDaylight(30);
    ReefAngel.PWM.SetActinic( LongPulseMode(30,80,2,true));
}

Would this work? Is there an easier way to do what I want? Or am I WAAAAAAY off :lol:
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Switching between 2 pump modes between certain time

Post by rimai »

This won't work:

Code: Select all

mode=1-mode;
Try this:

Code: Select all

mode=hour()/2;
Roberto.
meadowsad
Posts: 53
Joined: Sat Jun 15, 2013 9:56 am

Re: Switching between 2 pump modes between certain time

Post by meadowsad »

Thanks for the info, I'll give that a try as soon as I can get this code uploaded to the unit. Will the If statement still be correct with the "mode==1" in it?
meadowsad
Posts: 53
Joined: Sat Jun 15, 2013 9:56 am

Re: Switching between 2 pump modes between certain time

Post by meadowsad »

After messing with the code and doing a bunch of tests this is what I came up with.

Code: Select all

    static int mode;
    static int seconds;
    if (mode==0)
     {
      ReefAngel.PWM.SetDaylight( LongPulseMode(30,80,2,true));
      ReefAngel.PWM.SetActinic(30);
      seconds=seconds++;
      if (seconds==3600)   
       {
        mode=1;
        seconds=0;
       }
      }
     if (mode==1)
      {
       ReefAngel.PWM.SetDaylight(30);
       ReefAngel.PWM.SetActinic( LongPulseMode(30,80,2,true));
       seconds=seconds++;
       if (seconds==3600)   
        {
         mode=0;
         seconds=0;
        }
       }
I just put this in a function then call the function at the times I want. This looks a bit messy so if there is a much easier way to do this I am open to suggestions :)
meadowsad
Posts: 53
Joined: Sat Jun 15, 2013 9:56 am

Re: How to alternate between 2 pump modes every hour?

Post by meadowsad »

I have been playing around with the code and have come up with the code pasted below. At this point I am just messing around and maybe someone else will find this useful. The code below has yet to be tested but it looks like it should work.

Code: Select all

static int mode;
ReefAngel.Timer[1].SetInterval(3600);

if (mode==0)
{
  ReefAngel.Timer[1].Start();
  mode=1;
}
if (ReefAngel.Timer[1].IsTriggered())
{
  mode=0;
}
switch (mode) 
{
  case 0:
    ReefAngel.PWM.SetDaylight( LongPulseMode(30,80,2,true));
    ReefAngel.PWM.SetActinic(30);
    break;
   case 1:
    ReefAngel.PWM.SetDaylight(30);
    ReefAngel.PWM.SetActinic( LongPulseMode(30,80,2,true));
    break;
}
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: How to alternate between 2 pump modes every hour?

Post by rimai »

Will not work.
Because when the timer triggers, you assign mode=0 and in the very next loop, if (mode==0) will be true and assign mode=1 and start timer again.
Sorry, my recommendation was wrong last time :(
Try this:

Code: Select all

mode=hour()%2;
This will result in mode being 0 for even hours and 1 for odd hours.
Roberto.
meadowsad
Posts: 53
Joined: Sat Jun 15, 2013 9:56 am

Re: How to alternate between 2 pump modes every hour?

Post by meadowsad »

Thanks!

What I am really trying to mimic is the functionality of interval mode on a Tunze 7096 wave controller. They have a setting where you set the minimum speed, maximum speed, pulse duration and interval. This "wave pattern" would work as follows; the first pump runs at the minimum speed and the second pump pulses to the maximum speed for the pulse duration, the pump roles are flipped according to the interval.

It would be AWESOME if I could come up with something like ReefAngel.DCPump.Mode=Interval. But I have no idea how to start there.

Is this even possible since the pumps are doing something different and the pumps aren't sync'd or antisync'd?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: How to alternate between 2 pump modes every hour?

Post by lnevo »

You can do what your doing but add a check if ReefAngel.DCPump.Mode==Custom
meadowsad
Posts: 53
Joined: Sat Jun 15, 2013 9:56 am

Re: How to alternate between 2 pump modes every hour?

Post by meadowsad »

You might be giving me more credit than I deserve! I have looked at the wave patterns and I am starting to understand how they work but I don't understand how I can have one pump doing one thing while the other pump is doing something else.

So if I call the wave pattern with something like

Code: Select all

ReefAngel.PWM.SetDaylight( IntervalMode( 30, 80, 2, 3600, true));
ReefAngel.PWM.SetActinic( IntervalMode( 30, 80, 2, 3600, false));


with the wave pattern code looking like

Code: Select all

byte IntervalMode(byte MinSpeed, byte MaxSpeed, int PulseDuration, int Interval, boolean PulseSync)
  {
    static int mode;
    static int seconds;
    byte tspeed=0;
    mode=hour()%2;
    if (mode==0)
      {
        tspeed=(now()%(PulseDuration*2)<PulseDuration?MinSpeed:MaxSpeed);
          if (PulseSync)
	    return (tspeed==MinSpeed)?MaxSpeed:MinSpeed;
          else
	    return tspeed;
        seconds=seconds++;
        if (seconds==Interval)   
          {
           mode=1;
           seconds=0;
          }
      }
     if (mode==1)
       {
         tspeed=(now()%(PulseDuration*2)<PulseDuration?MinSpeed:MaxSpeed);
	  if (PulseSync)
	    return tspeed;
	  else
	    return (tspeed==MinSpeed)?MaxSpeed:MinSpeed;
         seconds=seconds++;
         if (seconds==Interval)   
           {
           mode=0;
           seconds=0;
          }
       }
  }
will this work since 1 "mode" flips the PulseSync?

EDIT: Yeah this doesn't work...
meadowsad
Posts: 53
Joined: Sat Jun 15, 2013 9:56 am

Re: Alternate between 2 pump modes at set interval?

Post by meadowsad »

Ok... So after digging through code and trying to wrap my head around what these wave patterns are doing I am making progress. This is what I have so far.

Code: Select all

    byte IntervalMode(byte MinSpeed, byte MaxSpeed, int PulseDuration, byte PumpNumber)
      {
        static int mode;
        byte pspeed=0;
        mode=hour()%2;
        if (mode==0 && PumpNumber==1)
          {
            pspeed=(now()%(PulseDuration*2)<PulseDuration?MinSpeed:MaxSpeed);
            return pspeed;
          }
         if (mode==1 && PumpNumber==1)
           {
             pspeed=MinSpeed;
             return pspeed;
           }
         if (mode==0 && PumpNumber==2)
          {
            pspeed=MinSpeed;
            return pspeed;
           }
         if (mode==1 && PumpNumber==2)
           {
             pspeed=(now()%(PulseDuration*2)<PulseDuration?MinSpeed:MaxSpeed);
             return pspeed;
           }
      }
So I call this with

Code: Select all

ReefAngel.PWM.SetDaylight( IntervalMode( 30, 80, 2, 1));
ReefAngel.PWM.SetActinic( IntervalMode( 30, 80, 2, 2));
What I would like to do is have the mode changed to 0 or 1 by an interval that I can specify when I call this code. For example; I want mode to change every 1min. As it is right now mode is hard coded to change every hour. Any suggestions on how to do this would be greatly appreciated! Also any tips to clean this up or simplify it would be welcomed!
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Alternate between 2 pump modes at set interval?

Post by rimai »

Try this:

Code: Select all

byte IntervalMode(byte MinSpeed, byte MaxSpeed, int PulseDuration, int Interval, boolean PulseSync)
{
  if (now()%(Interval*2)<Interval)
    return PulseSync?LongPulseMode(MinSpeed,MaxSpeed,PulseDuration,true):MinSpeed;
  else
    return PulseSync?MinSpeed:LongPulseMode(MinSpeed,MaxSpeed,PulseDuration,true);
}
Roberto.
Post Reply