Page 3 of 3

Re: Salinity temp compensation?

Posted: Tue Apr 23, 2013 12:51 pm
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); 

Re: Salinity temp compensation?

Posted: Tue Apr 23, 2013 4:29 pm
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

Re: Salinity temp compensation?

Posted: Tue Apr 23, 2013 9:56 pm
by ahmedess
It is

Re: Salinity temp compensation?

Posted: Thu Apr 25, 2013 4:15 pm
by ahmedess
I m changing the section at line 738, any clue for why is it not working

Re: Salinity temp compensation?

Posted: Thu Apr 25, 2013 9:14 pm
by rimai
Not sure... Just wait for the update...
I'm planning to release this weekend.

Re: Salinity temp compensation?

Posted: Sun Apr 28, 2013 2:31 pm
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);
	}	
}

Re: Salinity temp compensation?

Posted: Sun Apr 28, 2013 7:08 pm
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);

Re: Salinity temp compensation?

Posted: Mon Apr 29, 2013 2:26 am
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

Re: Salinity temp compensation?

Posted: Mon Apr 29, 2013 8:09 am
by rimai
Correct

Re: Salinity temp compensation?

Posted: Mon Apr 29, 2013 8:10 am
by rimai
I want to make sure we use for a while before I turn it into enabled by default.

Re: Salinity temp compensation?

Posted: Mon Apr 29, 2013 12:18 pm
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?

Re: Salinity temp compensation?

Posted: Mon Apr 29, 2013 12:21 pm
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();

Re: Salinity temp compensation?

Posted: Mon Apr 29, 2013 12:30 pm
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

Re: Salinity temp compensation?

Posted: Mon Apr 29, 2013 12:46 pm
by ahmedess
I ve done as you said and the value of internalmemory.alpha_read() changes properly to the value I set it to

Re: Salinity temp compensation?

Posted: Mon Apr 29, 2013 1:27 pm
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);

Re: Salinity temp compensation?

Posted: Mon Apr 29, 2013 1:38 pm
by ahmedess
Finally!!

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

Thanks alot

Re: Salinity temp compensation?

Posted: Thu Aug 15, 2013 9:22 am
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?

Re: Salinity temp compensation?

Posted: Thu Aug 15, 2013 9:33 am
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);

Re: Salinity temp compensation?

Posted: Thu Aug 15, 2013 9:41 am
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).

Re: Salinity temp compensation?

Posted: Thu Aug 15, 2013 9:45 am
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 :)

Re: Salinity temp compensation?

Posted: Thu Aug 15, 2013 9:50 am
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.

Re: Salinity temp compensation?

Posted: Mon Aug 26, 2013 2:41 am
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..

Re: Salinity temp compensation?

Posted: Mon Aug 26, 2013 8:11 am
by rimai
setup()

Re: Salinity temp compensation?

Posted: Fri Feb 12, 2021 3:07 pm
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!

Re: Salinity temp compensation?

Posted: Fri Feb 12, 2021 3:11 pm
by rimai
That is it.

Re: Salinity temp compensation?

Posted: Fri Feb 12, 2021 3:22 pm
by howaboutme
rimai wrote:That is it.
thanks!