Graphing PWM on Relay Box

Post Reply
Paulturner911
Posts: 287
Joined: Wed Jan 23, 2013 12:36 pm

Graphing PWM on Relay Box

Post by Paulturner911 »

Ive had the blessing of Lee writing my WP40 code to randomize the modes. However everytime I check it in the portal it is either 70 or 20, I havent seen it an any other percentage.....

Is there anyways to graph or recall the PWM on the relay box?
Image
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Graphing PWM on Relay Box

Post by lnevo »

Try this:

http://forum.reefangel.com/status/chart ... ilter=PWMD

It looks like though it's just flipping between the 70% and 20%.. Might I have done something wrong...

Here's the code I gave to Paul... could use some other eyes to take a look:

Code: Select all

#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <Wire.h>
#include <OneWire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <LED.h>
#include <RA_TempSensor.h>
#include <Relay.h>
#include <RA_PWM.h>
#include <Timer.h>
#include <Memory.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <ReefAngel.h>


void setup() {
// This must be the first line
ReefAngel.Init(); //Initialize controller
// Ports toggled in Feeding Mode
ReefAngel.FeedingModePorts = Port1Bit | Port7Bit | Port8Bit;
// Ports toggled in Water Change Mode
ReefAngel.WaterChangePorts = Port1Bit | Port7Bit | Port8Bit;
// Ports toggled when Lights On / Off menu entry selected
ReefAngel.LightsOnPorts = Port2Bit | Port3Bit | Port7Bit | Port8Bit;
// Ports turned off when Overheat temperature exceeded
ReefAngel.OverheatShutoffPorts = Port3Bit | Port7Bit | Port8Bit;
// Use T1 probe as temperature and overheat functions
ReefAngel.TempProbe = T1_PROBE;
ReefAngel.OverheatProbe = T1_PROBE;
InternalMemory.OverheatTemp_write( 869 );


// Ports that are always on

////// Place additional initialization code below here


////// Place additional initialization code above here
}

void loop()
{
ReefAngel.Relay.On( Port1 );
ReefAngel.StandardFan( Port2 );
ReefAngel.ActinicLights( Port3 );
ReefAngel.DayLights( Port7 );
ReefAngel.DayLights( Port8 );
//Moonlight Phase 9pm-10am (CH4-CH5)
if ( (hour() >=10) && (hour() <21) )
ReefAngel.PWM.SetChannel( 4,(0) );
else
ReefAngel.PWM.SetChannel( 4, MoonPhase() );
if ( (hour() >=10) && (hour() <21) )
ReefAngel.PWM.SetChannel( 5,(0) );
else
ReefAngel.PWM.SetChannel( 5, MoonPhase() );
//Pump Delay and Over Flow Protection
if (ReefAngel.HighATO.IsActive())
ReefAngel.Relay.On(Port1);
else
ReefAngel.Relay.Off(Port1);
//ATO Protection
if (ReefAngel.LowATO.IsActive())
ReefAngel.Relay.On(Port4);
else
ReefAngel.Relay.Off(Port4);

//Kalk Dose 50sec @ 8pm-12pm (every 15min)
if (hour() >=20 || hour() < 12)
ReefAngel.Relay.Set(Port4, now()%900<50);
else
ReefAngel.Relay.Off(Port4);

//Feed Mode Delay on Pump
static boolean feeding=false;
static unsigned long feedingstarted = now();

if (ReefAngel.DisplayedMenu==FEEDING_MODE)
{
  if (!feeding)
  {
  feeding=true;
  feedingstarted = now();
  }
} else {
  feeding=false;
}

///// Place your custom code below here
// Read memory for RF Wave Settings and use for Tunze/Jaebo
int mode=InternalMemory.RFMode_read();
int speed=InternalMemory.RFSpeed_read();
int duration=InternalMemory.RFDuration_read();

// Change this to what you want your min/max based on vortech speed
// This is for those functions that take both, but only one memory slot.
int minOffset=25;
int maxOffset=25;

int min=speed-minOffset;
int max=speed+maxOffset;

// Add random mode if we set to Mode to 12
if ((now()%SECS_PER_HOUR==0) && mode==12) {
   mode=random(7); // Change the mode once per hour to modes 0-6
}

// keep wavemakers off for first 30 minutes of feeding mode.
if (now()-feedingstarted<=1800 && ReefAngel.DisplayedMenu==FEEDING_MODE) {
ReefAngel.PWM.SetDaylight( 0 );
//ReefAngel.PWM.SetActinic( 0 );
} else if (mode==Constant) { 
// Constant
ReefAngel.PWM.SetDaylight( speed );
//ReefAngel.PWM.SetActinic( speed );
} else if (mode==Lagoon) { 
// Lagoon
ReefAngel.PWM.SetDaylight( SineMode(min,max,duration,true) );
//ReefAngel.PWM.SetActinic( SineMode(min,max,duration,false) );
} else if (mode==ReefCrest) { 
// Reef Crest
ReefAngel.PWM.SetDaylight( ReefCrestMode(speed,duration,true) );
//ReefAngel.PWM.SetActinic( ReefCrestMode(speed,duration,false) );
} else if (mode==ShortPulse) { 
// Short Pulse
ReefAngel.PWM.SetDaylight( ShortPulseMode(min,max,duration,true) );
//ReefAngel.PWM.SetActinic( ShortPulseMode(min,max,duration,false) );
} else if (mode==LongPulse) {
// Long Pulse
ReefAngel.PWM.SetDaylight( LongPulseMode(min,max,duration,true) );
//ReefAngel.PWM.SetActinic( LongPulseMode(min,max,duration,false) );
} else if (mode==TidalSwell) {
// Tidal Swell
ReefAngel.PWM.SetDaylight( TidalSwellMode(speed,true) );
//ReefAngel.PWM.SetDaylight( TidalSwellMode(speed,false) );
} else if (mode=NutrientTransport) {
// Smart_NTM
ReefAngel.PWM.SetDaylight( NutrientTransportMode(min,max,duration,true) );
//ReefAngel.PWM.SetActinic( NutrientTransportMode(min,max,duration,false) );
} else {
// Default 
ReefAngel.PWM.SetDaylight( TideMode(speed,minOffset,maxOffset) );
//ReefAngel.PWM.SetActinic( TideMode(speed,minOffset,maxOffset) );
}

// Add night mode (constant 45%)
if (now%SECS_PER_DAY<30600 && now%SECS_PER_DAY >=73800) { // Time is before 8:30am and after 10:30pm
  ReefAngel.PWM.SetDaylight(45);
}
////// Place your custom code above here

}
Paulturner911
Posts: 287
Joined: Wed Jan 23, 2013 12:36 pm

Re: Graphing PWM on Relay Box

Post by Paulturner911 »

How did you find that graph?

It starts to do what we want on 21st @22:22 when I did the upload. It seems that it is maybe cycling short pulse, long pulse, and NTP, but excluding lagoon and reefcrest.

I uploaded the night mode last night, but I didnt get to see if it cycled down to 40. Looking at the chart it doesnt seem that it did.

I really appreciate all of the help.
Image
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Graphing PWM on Relay Box

Post by lnevo »

there's a thread somewhere about the graphs, you can get all your portal details in a graph for any of the data points. I didn't see the pwm value going to the 45% we expected...not sure what I did wrong :(
Paulturner911
Posts: 287
Joined: Wed Jan 23, 2013 12:36 pm

Re: Graphing PWM on Relay Box

Post by Paulturner911 »

I didnt upload the night mode until last night. I dont see it on the graph either, and my IP just went on the unknow address tyrant......Just started this about a month ago. The IP doesnt change on my 2wire router, and I have to unplug and replug the wifi attachment to get it back on line. BUT, one fix at a time..... I was thinking maybe the random code should go after the feedmode/wave maker and before the vortec modes? I know placement is important with this....just a thought. Let me know what you think.
Image
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Graphing PWM on Relay Box

Post by lnevo »

The feedmode check doesnt care about modes...

I think i know what is happening...code coming soon...
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Graphing PWM on Relay Box

Post by lnevo »

Ok, try this for the random section. The idea now is that we set rmode to the mode we want when in that mode which we change once per hour. Before the mode would get changed at the top of each hour, but then revert to what was in memory. So it was only good for one second. Now we make it persistent if we're in mode 12.

Code: Select all

// Add random mode if we set to Mode to 12
static int rmode;

if (now()%SECS_PER_HOUR==0) {
  rmode=random(7); // Change the mode once per hour to modes 0-6
}
if (mode==12) {
  mode=rmode;   
}
Paulturner911
Posts: 287
Joined: Wed Jan 23, 2013 12:36 pm

Re: Graphing PWM on Relay Box

Post by Paulturner911 »

Just checking placement.......replace like this?


int max=speed+maxOffset;

// Add random mode if we set to Mode to 12
static int rmode;

if (now()%SECS_PER_HOUR==0) {
rmode=random(7); // Change the mode once per hour to modes 0-6
}
if (mode==12) {
mode=rmode;
}

// keep wavemakers off for first 30 minutes of feeding mode.


Thanks!
Image
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Graphing PWM on Relay Box

Post by lnevo »

Yea looks right.
Paulturner911
Posts: 287
Joined: Wed Jan 23, 2013 12:36 pm

Re: Graphing PWM on Relay Box

Post by Paulturner911 »

Ill upload tonight and let you know if we are up and running :) also get a chance to test the night mode.

Thanks!!!
Image
Paulturner911
Posts: 287
Joined: Wed Jan 23, 2013 12:36 pm

Re: Graphing PWM on Relay Box

Post by Paulturner911 »

It is cycling between the modes! It didnt go into night mode though. It seems pretty sharp, maybe the reefcrest and lagoon just havent been called much.

Thanks Lee
Image
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Graphing PWM on Relay Box

Post by lnevo »

Lets see over a longer duration and I'll double check the night mode..
Paulturner911
Posts: 287
Joined: Wed Jan 23, 2013 12:36 pm

Re: Graphing PWM on Relay Box

Post by Paulturner911 »

Quick question....
If I make changes in the portal for the modes such as duration to make the short pulse longer will those changes reflect when I activate our random mode again?

It's kind of hard to grasp how it's cycling when the portal graph is updating every five minutes... Ntp and short pulse seem the same since Ntp never peaks within the hour.
I'm getting a good amount of ramping up and down, but it seems to mostly switch 30/70 the majority of cycles. I'm hoping for more ramping than pulsing. What could I change?
Image
Paulturner911
Posts: 287
Joined: Wed Jan 23, 2013 12:36 pm

Re: Graphing PWM on Relay Box

Post by Paulturner911 »

Could I do this for the night mode???

if (hour() >=21 || hour() < 10)
ReefAngel.PWM.SetDaylight(45);


Just trying to fix it.....
Image
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Graphing PWM on Relay Box

Post by lnevo »

No i see the problem. Change the && in my statement to ||

Or your commands would work too but without :30 in the time. Your logic helped me realize what was wrong.
Paulturner911
Posts: 287
Joined: Wed Jan 23, 2013 12:36 pm

Re: Graphing PWM on Relay Box

Post by Paulturner911 »

Is there anyway to limit the random modes to certian modes? I see that they are number 1-6, but how would I know which mode is tied to which number, and how would I write it?

// Add random mode if we set to Mode to 12
if ((now()%SECS_PER_HOUR==0) && mode==12) {
mode=random(1,2,3,5,6); // Change the mode once per hour to modes 0-6
}
Image
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Graphing PWM on Relay Box

Post by lnevo »

I'm doing exactly that. Take a look at the RFCustom function in my INO for an example.
Paulturner911
Posts: 287
Joined: Wed Jan 23, 2013 12:36 pm

Re: Graphing PWM on Relay Box

Post by Paulturner911 »

Im going to start an INO thread for myself...Im at work now so Im just gonna stick a few thing I would like here until I get my code from home.
I think this is what I need from your INO

void SetRF() {
int ntmDelay=InternalMemory.read(Mem_B_NTMDelay)*60;
int ntmTime=InternalMemory.read(Mem_B_NTMTime)*60;
static time_t t;

vtMode=InternalMemory.RFMode_read();
vtSpeed=InternalMemory.RFSpeed_read();
vtDuration=InternalMemory.RFDuration_read();

if (now()-t > ntmDelay && now()-t < ntmTime+ntmDelay) {
// Post feeding mode
vtMode=Smart_NTM;
vtSpeed=InternalMemory.read(Mem_B_NTMSpeed);
vtDuration=InternalMemory.read(Mem_B_NTMDuration);
} else if (!sun.IsDaytime() && InternalMemory.read(Mem_B_NightRF)) {
vtMode=Night;
vtSpeed=InternalMemory.read(Mem_B_NightSpeed);
vtDuration=InternalMemory.read(Mem_B_NightDuration);
} else {
if (vtMode!=Night && ReefAngel.RF.Mode==Night)
ReefAngel.RF.SetMode(Night_Stop,0,0);
}

if (ReefAngel.DisplayedMenu==FEEDING_MODE && InternalMemory.read(Mem_B_FeedingRF)) {
t=now(); // Run post feeding mode when this counter stops
} else {
(vtMode==Custom) ? RFCustom() : ReefAngel.RF.SetMode(vtMode,vtSpeed,vtDuration);
}
}

void RFCustom() {
static boolean changeMode, firstTime=true;
byte rcSpeed, rcSpeedAS;

byte tideSpeed=tide.CalcTide();
byte tideMin=InternalMemory.read(Mem_B_TideMin);
byte tideMax=InternalMemory.read(Mem_B_TideMax);
byte tideMode=InternalMemory.read(Mem_B_TideMode);
float pumpOffset=(float) InternalMemory.read(Mem_B_PumpOffset)/100;
byte RandomModes[]={ ReefCrest, TidalSwell, Smart_NTM, Lagoon, ShortPulse, LongPulse };

if (now()%SECS_PER_DAY!=0) changeMode=true;
if ((now()%SECS_PER_DAY==0 && changeMode) || firstTime) {
tideMode=random(100)%sizeof(RandomModes);
InternalMemory.write(Mem_B_TideMode,tideMode);
changeMode=false;
firstTime=false;
}

ReefAngel.CustomVar[Var_TideMode]=tideMode+1;

switch (RandomModes[tideMode]) {
case ReefCrest: {
rcSpeed=ReefCrestMode(tideSpeed,tideMin,true);
rcSpeedAS=ReefCrestMode(tideSpeed,tideMin ,false);
break;
}
case TidalSwell: {
rcSpeed=TidalSwellMode(tideSpeed+tideMin,true);
rcSpeedAS=TidalSwellMode(tideSpeed+tideMin,false);
break;
}
case Smart_NTM: {
vtDuration=InternalMemory.read(Mem_B_NTMDuration);
rcSpeed=NutrientTransportMode(tideSpeed-tideMax,tideSpeed+tideMin,vtDuration*100,true);
rcSpeedAS=NutrientTransportMode(tideSpeed-tideMax,tideSpeed+tideMin,vtDuration*100,false);
break;
}
case Lagoon: {
rcSpeed=SineMode(tideSpeed-tideMin,tideSpeed+tideMin,vtDuration*60,true);
rcSpeedAS=SineMode(tideSpeed-tideMin,tideSpeed+tideMin,vtDuration*60,false);
break;
}
case ShortPulse: {
vtDuration=InternalMemory.read(Mem_B_NTMDuration);
rcSpeed=ShortPulseMode(tideSpeed-tideMax,tideSpeed+tideMin,vtDuration*100,true);
rcSpeedAS=ShortPulseMode(tideSpeed-tideMax,tideSpeed+tideMin,vtDuration*100,false);
break;
}
case LongPulse: {
rcSpeed=LongPulseMode(tideSpeed-tideMax,tideSpeed+tideMin,vtDuration,true);
rcSpeedAS=LongPulseMode(tideSpeed-tideMax,tideSpeed+tideMin,vtDuration,false);
break;
}
}

ReefAngel.RF.SetMode(Custom,rcSpeedAS*pumpOffset,tide.isOutgoing());
ReefAngel.RF.SetMode(Custom,rcSpeed,tide.isIncoming());
}



AND THIS
void NextRFMode() {
vtMode++;

if (vtMode > 12) {
vtMode=0;
vtSpeed=50; // Constant
} else if (vtMode == 1) {
vtSpeed=40; // Lagoon
} else if (vtMode == 2) {
vtSpeed=45; // Reef Crest
} else if (vtMode == 3) {
vtSpeed=55; vtDuration=10; // Short Pulse
} else if (vtMode == 4) {
vtSpeed=55; vtDuration=20; // Long Pulse
} else if (vtMode == 5) {
vtSpeed=InternalMemory.read(Mem_B_NTMSpeed);
vtDuration=InternalMemory.read(Mem_B_NTMDuration); // Smart_NTM
} else if (vtMode == 6) {
vtSpeed=50; vtDuration=10; // Smart_TSM
} else if (vtMode == 7) {
vtSpeed=InternalMemory.read(Mem_B_NightSpeed);
vtDuration=InternalMemory.read(Mem_B_NightDuration);
vtMode=9; // Night
} else if (vtMode == 10) {
vtSpeed=65; vtDuration=5; // Storm
} else if (vtMode == 11) {
vtSpeed=45; vtDuration=10; // Custom
}

if (vtMode!=InternalMemory.RFMode_read())
InternalMemory.RFMode_write(vtMode);
if (vtSpeed!=InternalMemory.RFSpeed_read())
InternalMemory.RFSpeed_write(vtSpeed);
if (vtDuration!=InternalMemory.RFDuration_read())
InternalMemory.RFDuration_write(vtDuration);


I would also like the controller to display the Vortec Mode.
I havent decided how to run the random, but my graph sure doesnt look like yours. It may be my offsets, but it mostly 70/30 and when its reefcrest it just swings right around 43 but does not rise or fall more then 5ish?!?!

I see you have the daily wave form randomiozed, I thik this is what I will run with....

Also could you explain wifi alert? Not sure what that means.

Thanks!!!
Image
Post Reply