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 T1T3 and P1P9 (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. 
Quote:

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() Once you've got the methods available for use, you can put them in a program like this: Code: int main 
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. 
Quote:
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. 
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:
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... 
1 Attachment(s) Quote:
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 05:06 AM. 
Copyright © 2019 My Math Forum. All rights reserved.