My Math Forum (http://mymathforum.com/math-forums.php)
-   Elementary Math (http://mymathforum.com/elementary-math/)
-   -   Simplifying an equation (http://mymathforum.com/elementary-math/343303-simplifying-equation.html)

 camerart January 29th, 2018 02:49 AM

Simplifying an equation

1 Attachment(s)
Hi,
I am not much of a mathematician or computer programmer, but I'm trying to include an equation into a program.

Here is the equation:

What happens is the program READs 12x Temperature/Pressure addresses, to give T1-T3 and P1-P9 (Shown in the equation as dig_X)

I want to READ these values first then add them into the program while simplifying it.

Any help would be much appreciated.
cheers, Camerart.

 Joppy January 29th, 2018 03:11 AM

Quote:
 Originally Posted by camerart (Post 587748) Hi, I am not much of a mathematician or computer programmer, but I'm trying to include an equation into a program. Here is the equation: What happens is the program READs 12x Temperature/Pressure addresses, to give T1-T3 and P1-P9 (Shown in the equation as dig_X) I want to READ these values first then add them into the program while simplifying it. Any help would be much appreciated. cheers, Camerart.
The code in the text file is quite hard to read. Can you highlight which line(s) you are referring to?

 Benit13 January 29th, 2018 03:31 AM

It looks like a C program. I would copy and paste the code into a new file and the wrap those two different pieces of functionality into two separate methods. For example, you could do something like:

Code:

double GetTemperatureAsDouble()
{
<code here for the Page 45 method>
}

char* GetTemperatureAsString()
{
<code here for the page 46 method>
}

I'm not very good at C or C++, but I don't think you'd have to change much except to make sure the types for the methods and the return variables in the code match and make sure that there's declarations in the methods for all of the relevant variables.

Once you've got the methods available for use, you can put them in a program like this:

Code:

int main
{
double mytemp;
char* tempString;

myTemp = GetTemperatureAsDouble();
tempString = GetTemperatureAsString();

return 0;
}

If the program is more sophisticated you might need to make a .dll and then call the functions using an interface declaration. I have no idea how to do that though.

 camerart January 29th, 2018 03:36 AM

Hi J,
It is hard to read, and I'm trying to reduce it so it is simpler.

NOTE: DOUBLE is a double precision floating point number ~ 16 digits precision.

Take this line:
var1 = (((double) adc_t) / 16384.0 –((double) dig_t1) / 1024.0) * ((double) dig_t2) ;

I have READ and calculated all of the 'dig_xx' elements from the module, so I think it could be shortened to something like this:
var1 = (((double) adc_t) / 16384.0 –((27100) / 1024.0) * ((double) 25631)
var1 = (((adc_t) / 16384.0 –(26.46484375 * ( 25631)
var1 = (((adc_t) / 16384.0 –678,320.41015625

I'm sure there are a few mistakes already, and I have no confidence to try.

Are you able to read Python, as I have a similar equation?

c.

 camerart January 29th, 2018 04:40 AM

Quote:
 Originally Posted by Benit13 (Post 587751) It looks like a C program. I would copy and paste the code into a new file and the wrap those two different pieces of functionality into two separate methods. For example, you could do something like: Code: double GetTemperatureAsDouble() {     } char* GetTemperatureAsString() {     } I'm not very good at C or C++, but I don't think you'd have to change much except to make sure the types for the methods and the return variables in the code match and make sure that there's declarations in the methods for all of the relevant variables. Once you've got the methods available for use, you can put them in a program like this: Code: int main {     double mytemp;     char* tempString;     myTemp = GetTemperatureAsDouble();     tempString = GetTemperatureAsString();     return 0; } If the program is more sophisticated you might need to make a .dll and then call the functions using an interface declaration. I have no idea how to do that though.
Hi B,
I am not using C, but Oshonsoft BASIC, which has all sorts of gotchas.
This is not really a computing question, but a mathematical one. I am trying to 'simplify down' the equation mathematically, them write it and test it as i go along.
C.

 Benit13 January 29th, 2018 05:03 AM

Okay, I understand. No wonder you're having trouble then... the quality of code is awful (very 1980s!) and the comments refer to the pages of a book or article, so do you have the book/article it is referring to?

Quote:
 Originally Posted by camerart (Post 587753) Hi J, It is hard to read, and I'm trying to reduce it so it is simpler. NOTE: DOUBLE is a double precision floating point number ~ 16 digits precision. Take this line: var1 = (((double) adc_t) / 16384.0 –((double) dig_t1) / 1024.0) * ((double) dig_t2) ; I have READ and calculated all of the 'dig_xx' elements from the module, so I think it could be shortened to something like this: var1 = (((double) adc_t) / 16384.0 –((27100) / 1024.0) * ((double) 25631) var1 = (((adc_t) / 16384.0 –(26.46484375 * ( 25631) var1 = (((adc_t) / 16384.0 –678,320.41015625 I'm sure there are a few mistakes already, and I have no confidence to try. Are you able to read Python, as I have a similar equation? c.
I am very familiar with python, so feel free to post stuff using that.

I don't know anything about ADCs, but, after a quick Google search (see for example Calculate temperature from ADC value of MCP9701A sensor | Microchip), it seems as if the equation is a conversion that relates an ADC voltage value (as outputted from an ADC connected to a temperature sensor) to the temperature being sensed. The equation is probably something like

$\displaystyle T = A (V - B)$

where T is temperature (in Celsius), V is ADC voltage (in Volts) and A and B are coefficients that dictate the calibration of the sensor and ADC component. A is a "temperature coefficient" and B is an "offset" .

If you have

$\displaystyle T = V / 16384.0 – 678320$

Then you have

$\displaystyle A = \frac{1}{16384} = 0.000061$

and

$\displaystyle B = 678320 * 16384 = 1.11 \times 10^{10}$

Those values don't seem like sensible values for a calibration scheme though for an ADC...

 camerart January 29th, 2018 05:25 AM

1 Attachment(s)
Quote:
 Originally Posted by Benit13 (Post 587759) Okay, I understand. No wonder you're having trouble then... the quality of code is awful (very 1980s!) and the comments refer to the pages of a book or article, so do you have the book/article it is referring to? I am very familiar with python, so feel free to post stuff using that. I don't know anything about ADCs, but, after a quick Google search (see for example Calculate temperature from ADC value of MCP9701A sensor | Microchip), it seems as if the equation is a conversion that relates an ADC voltage value (as outputted from an ADC connected to a temperature sensor) to the temperature being sensed. The equation is probably something like $\displaystyle T = A (V - B)$ where T is temperature (in Celsius), V is ADC voltage (in Volts) and A and B are coefficients that dictate the calibration of the sensor and ADC component. A is a "temperature coefficient" and B is an "offset" . If you have $\displaystyle T = V / 16384.0 – 678320$ Then you have $\displaystyle A = \frac{1}{16384} = 0.000061$ and $\displaystyle B = 678320 * 16384 = 1.11 \times 10^{10}$ Those values don't seem like sensible values for a calibration scheme though for an ADC...
Hi B,
Here's a similar Python program:

The addresses may be different, I haven't check them fully, till you like the look of it.

Notes are marked ################
All between @@@@@@@@@@@@@@ has been READ and calculated seprately, so fixed.

C.

 All times are GMT -8. The time now is 01:59 AM.