Salinity temp compensation?

Expansion modules and attachments
ahmedess
Posts: 173
Joined: Sun May 22, 2011 2:29 pm

Re: Salinity temp compensation?

Post by ahmedess »

I m using the correct place now but still changing the temperature constant or even changing the salinity calibration temperature manually does not change anything in the displayed salinity value. i think its not calculating the compensation formula. heres my code that i m using in the library now:

Code: Select all

#if defined SALINITYEXPANSION
	unsigned long tempsal=0;
	unsigned long avrgsal=0;
    
for (int a=0;a<20;a++)
    {
    	tempsal+=Salinity.Read();
    }

	avrgsal=tempsal/20;

          double SalCompensation;
		if (TempSensor.unit)
	
		SalCompensation=avrgsal/(1+((Params.Temp[T1_PROBE]-InternalMemory.SalTempComp_read())*InternalMemory.Alpha_read()/100000));

		else

		SalCompensation=avrgsal/(1+((Params.Temp[T1_PROBE]-InternalMemory.SalTempComp_read())*0.001165));

	Params.Salinity=round(SalCompensation);
	Params.Salinity=map(Params.Salinity, 0, SalMax, 60, 390); 
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Salinity temp compensation?

Post by rimai »

Which line are you changing?
Make sure it is the section that starts on 738
https://github.com/reefangel/Libraries/ ... l.cpp#L738
Roberto.
ahmedess
Posts: 173
Joined: Sun May 22, 2011 2:29 pm

Re: Salinity temp compensation?

Post by ahmedess »

It is
ahmedess
Posts: 173
Joined: Sun May 22, 2011 2:29 pm

Re: Salinity temp compensation?

Post by ahmedess »

I m changing the section at line 738, any clue for why is it not working
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Salinity temp compensation?

Post by rimai »

Not sure... Just wait for the update...
I'm planning to release this weekend.
Roberto.
ahmedess
Posts: 173
Joined: Sun May 22, 2011 2:29 pm

Re: Salinity temp compensation?

Post by ahmedess »

I ve updated the libraries to 1.0.4 and I have a question about the salinity compensation code in the libraries

What is the use of "Salinity.TemperatureCompensation"?

Code: Select all

void ReefAngelClass::ApplySalinityCompensation()
{
	// Salinity Compensation was contributed by ahmedess
	// http://forum.reefangel.com/viewtopic.php?p=7386#p7386
	// Credits to dazza1304
	// http://forum.reefangel.com/viewtopic.php?f=3&t=2670	
	if (Salinity.TemperatureCompensation!=-1 && Params.Temp[TempProbe]>0)
	{
		double SalCompensation;
		double SalConstant=Salinity.TemperatureCompensation;
		if (Salinity.TemperatureCompensation==0)
		{
			if (TempSensor.unit)
				SalConstant=InternalMemory.Alpha_read()/100000; // 0.0024;
			else
				SalConstant=0.001333;
		}
		SalCompensation=Params.Salinity/(1+((Params.Temp[TempProbe]-InternalMemory.SalTempComp_read())*SalConstant));
		Params.Salinity=round(SalCompensation);
	}	
}
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Salinity temp compensation?

Post by rimai »

Here is the update log:
http://forum.reefangel.com/viewtopic.php?f=7&t=1473
The way to use the compensation is:

Code: Select all

ReefAngel.Salinity.SetCompensation(0);
Or if you want to provide your own constant:

Code: Select all

ReefAngel.Salinity.SetCompensation(0.0024);
Roberto.
ahmedess
Posts: 173
Joined: Sun May 22, 2011 2:29 pm

Re: Salinity temp compensation?

Post by ahmedess »

You mean that i need to place the above line in my code to enable compensation ottherwise it will be disabled as default
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Salinity temp compensation?

Post by rimai »

Correct
Roberto.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Salinity temp compensation?

Post by rimai »

I want to make sure we use for a while before I turn it into enabled by default.
Roberto.
ahmedess
Posts: 173
Joined: Sun May 22, 2011 2:29 pm

Re: Salinity temp compensation?

Post by ahmedess »

okay I've tested the code but i have made a minor change to it. I created a memory location for the salinity constant "Alpha" and I have placed this line into my code:

Code: Select all

ReefAngel.Salinity.SetCompensation(InternalMemory.Alpha_read()/100000);
The problem is no matter what value I set Alpha to the compensation remains the same. I have tried many values starting from 240 and changed it from 1 to 1000 and the salinity value stays the same.

However, when i change the "Salinity Temp Compensation" value to a different one the salinity changes. I've been trying to figure out why this is happening but I couldnt find a solution. Could it be this part of the code "InternalMemory.Alpha_read()/100000" the controller is not calculating properly?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Salinity temp compensation?

Post by rimai »

Could be.
Are you sure that you are reading the correct memory location?
Just print somewhere on the screen what the controller is reading from InternalMemory.Alpha_read();
Roberto.
ahmedess
Posts: 173
Joined: Sun May 22, 2011 2:29 pm

Re: Salinity temp compensation?

Post by ahmedess »

I m using ReefAngel Status to change the value in memory. I have Alpha placed in memory location 3 and when i read the value in location 3 it gets the correct value I changed it to. Do you think it might differ if i print on the screen InternalMemory.Alpha_read();

this is part of my custom memory locations in globals.h:

Code: Select all

//custom memory locations (0-199)
#define CustomVarsStart           0
#define Mem_B_DP4Timer            CustomVarsStart
#define Mem_I_DP4RepeatInterval	  CustomVarsStart+1
#define Mem_I_Alpha			  CustomVarsStart+3
ahmedess
Posts: 173
Joined: Sun May 22, 2011 2:29 pm

Re: Salinity temp compensation?

Post by ahmedess »

I ve done as you said and the value of internalmemory.alpha_read() changes properly to the value I set it to
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Salinity temp compensation?

Post by rimai »

I'm thinking you may have a casting issue when you are dividing the value, since it is an int value and the function calls for a double.
Try this:

Code: Select all

ReefAngel.Salinity.SetCompensation((doube)InternalMemory.Alpha_read()/100000);
If this doesn't work, try this:

Code: Select all

double temp=InternalMemory.Alpha_read();
temp/=100000;
ReefAngel.Salinity.SetCompensation(temp);
Roberto.
ahmedess
Posts: 173
Joined: Sun May 22, 2011 2:29 pm

Re: Salinity temp compensation?

Post by ahmedess »

Finally!!

this one is working: ReefAngel.Salinity.SetCompensation((double)InternalMemory.Alpha_read()/100000);

Thanks alot
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Salinity temp compensation?

Post by binder »

When using the compensation, do we need to set the compensation temperature as well as enabling it? I would think that we would want to tell it what temperature we plan on using but I'm not 100% positive. Could somebody clarify please?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Salinity temp compensation?

Post by rimai »

When you enable the compensation, you should recalibrate.
It will store the temperature in which the calibration happened in the internal memory and use it as reference.
To enable compensation and use the default alpha value, use this:

Code: Select all

ReefAngel.Salinity.SetCompensation(0);
Roberto.
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Salinity temp compensation?

Post by binder »

Ok cool. I didn't know it stored the temperature used during the calibration.
I already have the SetCompensation(0) line in my code. I just didn't know about the temperature stored.

Does it have to be calibrated to 35ppt or can we change that value? Or does it really matter if it's calibrated to 35ppt? I believe I run my tank salinity slightly lower (around 1.024 or 32ppt).
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Salinity temp compensation?

Post by rimai »

Yes, needs to be calibrated at 35ppt and you can't change it :(
If you want to create a FlexibleSalinityCalibration() function ;), maybe others could benefit from it too :)
Roberto.
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Salinity temp compensation?

Post by binder »

rimai wrote:Yes, needs to be calibrated at 35ppt and you can't change it :(
If you want to create a FlexibleSalinityCalibration() function ;), maybe others could benefit from it too :)
Maybe. I will see. :)
It seems like I don't even have enough time to get stuff done that I "need" to get done.
dazza1304
Posts: 154
Joined: Sat Aug 04, 2012 4:22 am

Re: Salinity temp compensation?

Post by dazza1304 »

rimai wrote:When you enable the compensation, you should recalibrate.
It will store the temperature in which the calibration happened in the internal memory and use it as reference.
To enable compensation and use the default alpha value, use this:

Code: Select all

ReefAngel.Salinity.SetCompensation(0);
Quick question, where to I place this in my code - in the initialisation or loop? Sorry if a silly question!

Cheers..
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Salinity temp compensation?

Post by rimai »

setup()
Roberto.
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Salinity temp compensation?

Post by howaboutme »

hi all,

bumping this thread.

can someone confirm that this code is all that's needed (other than recalibrate) to enable temp compensation for salinity?

Code: Select all

ReefAngel.Salinity.SetCompensation(0);
I'm trying to follow the initial developments in this thread but at the end it does look like the above is it?

Thanks!
Jack
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Salinity temp compensation?

Post by rimai »

That is it.
Roberto.
howaboutme
Posts: 246
Joined: Tue Jan 28, 2014 11:10 am
Location: Northern VA

Re: Salinity temp compensation?

Post by howaboutme »

rimai wrote:That is it.
thanks!
Jack
Post Reply