# Need formula to calculate head pressure from Volumes of CO2 ### Help Support Homebrew Talk: #### trimixdiver1

##### Well-Known Member
Im programing a carbonation calculator into my PLC to control my Brite Tank

Im looking for a formula that will give me the pressure to carbonate to, I will have the Temp of the tank and will know what volumes I want.

Thanks!!!

#### ajdelange

##### Well-Known Member
V = (P + 14.695)*(0.01821 + 0.090115*exp( -(T-32)/43.11) ) - 0.003342

with P in PSIG and T in °F is a pretty good (rmse = 0.01 Vol; peak error -0.044 Vols @37 °F, 10 psig, 3.27 Vols) fit to the ASBC table.

#### trimixdiver1

##### Well-Known Member
Formula isnt working, program says an error

#### ajdelange

##### Well-Known Member
As you can see it is indeed a perfectly valid equation. I cannot explain this but the last minus sign was not a really a minus sign. i edited it and it copies and pastes into two programs OK now.

#### trimixdiver1

##### Well-Known Member
Thanks, will try tomorrow

#### trimixdiver1

##### Well-Known Member
((R1096 + 14.695) * (0.01821 + (0.090115 ** (-(R1090 - 32) / 43.11)))) - 0.003342

This is how it lays out in my PLC

r1096 is pressure
r1090 is temperature

still not correct.

Also Im trying to input the volumes and output the pressure. Im not great with long equations, thanks

#### ajdelange

##### Well-Known Member
Don't know what language you are working in but 2 ** 3 in FORTRAN means raise 2 to the 3rd power with result = 8. Here we are raising a number to a power but it is e = 2.71828..., not 0.090115. The appropriate function in FORTRAN would be EXP and a FORTRAN compiler would have no problem with the formula as given in #2. If your compiler (or its math libraries) don't have an EXP function you will have to get it by recognizing that EXP(x) is equivalent to 2.718281828 ** x in FORTRAN notation.

Getting pressure from volume and temperature is a simple matter of solving for P

P = (V + 0.003342)/(0.01821 + 0.090115*exp( -(T-32)/43.11) ) -14.695

#### trimixdiver1

##### Well-Known Member
((R1096 + 0.003342) / (0.01821 + (0.090115 * (2.718282 ** (-(R1090 - 32) / 43.11))))) - 14.695

R1096 is Vols
R1090 is Temp

Im so lost right now.....

Here is a copy of the DoMore PLC instructions

The Math Raise to a Power operator ( ** ) will calculate the result of a base raised to the power of an exponent. The result of this calculation will always be a Real (floating point) value and should be placed in a Real memory location to preserve the fractional portion. This is especially important if the exponent is negative or if the exponent is a Real value,

Any value raised to the 0 power is 1. The value 0 raised to any power is 0. Note: 0 raised to the 0 power is 1.

The base and exponent can be any mix of signed integers, unsigned integers, real (floating point) numbers or discrete values. They can be any numeric or discrete memory location or any numeric or discrete structure member.

Traditional math precedence rules are used to solve the math expression. The use of parentheses to remove any ambiguity in the processing order is encouraged.

Refer to the examples below:

Signed Integers: assume D1 = 2 and D2 = 3

D0 = D1 ** D2

D0 = 2 ** 3
D0 = 8

Both the base and the exponent are integer memory locations.

The result is placed in an integer memory location.

D0 = (D1 ** D2) ** D1

D0 = (2 ** 3) ** 2
D0 = 8 ** 2

D0 = 64

The base and exponents are integer memory locations.

The result is placed in an integer memory location.

D0 = D1 ** (D2 ** D1)

D0 = 2 ** (3 ** 2)
D0 = 2 ** 8

D0 = 256

The base and exponents are integer memory locations.

The use of parentheses specifies the order of operation which yields a different result than the same values above.

The result is placed in an integer memory location.

R0 = D1 ** 0.5

R0 = 2 ** 0.5

R0 = 1.414

The base is an integer memory locations, the exponent is a Real constant.

The exponent is non-integer, which will generate a non-integer result. Place the result in a Real memory location to preserve the fractional portion.

The result is placed in a Real memory location.

R0 = D1 ** -3

R0 = 2 ** -3

R0 = 0.1250

The base is an integer memory locations, the exponent is an integer constant.

The exponent is negative, which will generate a non-integer result. Place the result in a Real memory location to preserve the fractional portion.

The result is placed in a Real memory location.

Numeric Structure Members: assume D1 = 10 and Timer T0.Acc = 5ms

D0 = D1 ** T0.Acc

D0 = 10 ** 5

D0 = 100000

The base is an integer memory location, the exponent is a structure member.

The .Acc member of a Timer structure contains the amount of time in milliseconds that has accumulated in a Timer.

The result is placed in an integer memory location.

Casting Numeric Values: assume DLV2000 and DLV2001 as a 32-bit Real = 123.45

R0 = DLV2000:RD ** 2

R0 = 123.45 ** 2

R0 = 15239.9

The base is using the 'Real and DWord' cast operators, the exponent is an integer constant.

The result is placed in a floating point memory location.

DLV memory locations are 16-bit Unsigned used by external DirectLOGIC devices. In this example a remote DirectLOGIC CPU has written a 32-bit floating point value into two successive DLV memory locations. Using the :RD cast operator will interpret the 32-bit value in DLV2000 and DLV2001 as a REAL number.

#### ajdelange

##### Well-Known Member
If I cut your line from the post, change R1096 to 2.73175 volumes and R1090 to 40 °F and replace ** with ^ which is the raise to a power operator in the program I use and then type

&#8226;print ((2.73175 + 0.003342) / (0.01821 + (0.090115 * (2.718282 ^(-(40 - 32) / 43.11))))) - 14.695

it returns 14.695 which is the correct answer. IOW you have an instruction which, as far as I can tell, is correct. The instructions you posted confirm this. The only thing I can think of the variables you are passing are not floating point numbers.

I don't know what else I can advise here. You have a formula which compilers can understand. Perhaps you could break it down into smaller parts, trying each one out in Excel, for example.

#### trimixdiver1

##### Well-Known Member
((R1096 + 0.003342) / (0.01821 + (0.090115 * (2.718282 ^ (-(R1090 - 32) / 43.11))))) - 14.695

With
R1096 = 2.75
R1090= 32.0

I get -0.920851

My numbers are REAL

Dont know whats going on?