Coolant and Inlet Air Temps Transfer Required Accuracy??

A thermistor curve calculator and simple code generator program used to develop FreeEMS and generate compile time curves for your custom sensors. Written by Fred and Shameem.
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: Coolant and Inlet Air Temps Transfer Required Accuracy??

Post by Fred »

The tabs are as follows :

Circuit
  • 3 pairs of temp/resistance data (ohm, degrees x 3)
  • Bias resistor value - (in ohms)
  • Temperature scale - (C, K, F)
Data
  • ADC resolution in bits - (8,10)
  • Temp output data type - (unsigned char, unsigned short, unsigned long, signed char, signed short, signed long, float/double)
  • Temp output scaling/shifting - (*X, +Z)
  • Round or truncate? - (round/truncate)
Code
  • Name of the array - (IATTransferTable etc)
  • Array type - (unsigned char, unsigned short, unsigned long, char, short, long, float, double)
  • Keywords to prefix with - (static, const, final, void, etc)
File Format
  • Filename (including extension)
  • End of line type - (mac/*nix/win)
  • Tabs or spaces for identing - (t/s)
  • Indenting level - (0 - ?)
  • Elements per line - (1 - 1024)
  • Pad numbers with spaces? (yes/no)
Comments
  • Textual comments to precede generated data - (GPL, author, date, time, comments, sensor type and name, original data, Steinhart-Hart coefficients, etc)
That is from left to right. The menus will be very simple indeed. Just fill in all fields and hit save sort of thing.

Fred.
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
shameem
LQFP112 - Up with the play
Posts: 135
Joined: Thu May 01, 2008 6:30 pm
Location: Ann Arbor, MI
Contact:

Re: Coolant and Inlet Air Temps Transfer Required Accuracy??

Post by shameem »

I can work on this if you'd like - i am most comfortable with C++ - but can adapt to any language that is common among the developers here...

Also another thought - shouldnt the lookup table be based on "voltage"? Because if it is in "R" then an extra step is required for the processor to convert "V" to "R" - maybe the generated files could have "3" columns (R,V,T) for a given bias resistor and the final table could be (V,T)......
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: Coolant and Inlet Air Temps Transfer Required Accuracy??

Post by Fred »

Well, I've already started, so let me get a bare shell up and running and you can fill out the details perhaps?

Once I have something non-useless I'll send you it.

As for the output, thats exactly what it is :

A direct temperature value for each and every ADC value. 1024 of them for a 10 bit ADC. Given the Resistor and the curve of temp vs resistance for the thermistor you can determine the voltage seen at the cpu for any given temperature or vice versa pretty easily.

Check out the matfactor.inc file with ms2e for an example of how it looks. Their temps are in deg F and *10 format. Ours will be in K and *100 at this stage. The tool should support either :-)

Fred.
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
User avatar
AbeFM
Post Whore!
Posts: 629
Joined: Sat Feb 16, 2008 12:11 am
Location: Sunny San Diego
Contact:

Re: Coolant and Inlet Air Temps Transfer Required Accuracy??

Post by AbeFM »

Fred wrote:
8InchesFlacid wrote:Take the effect this variable will have: Coolant temps perhaps effect when the fans come on, maybe the timing.
Now multiply through the error. Figure out the effect of coolant_temp -> coolant_temp + 5, propagate it.

If it only moves timing by 0.4 degrees, then a 5 degree error is fine. Don't get hung up on how accurate it has to be, intrinsically. Get hung up on how wrong it can be before it has an effect you deem unexceptable.
An excellent point, however, how much effect it has on a given tune will come down to the tuner and setup, not what I think :-)

The thing is, even if it's a bit wrong, as long as it's consistent and you get a different temperature for each ADC point, you can tune to it.
This is a "fudge" thing. If it's right, if it's 100% right, and well understood, then it would be tune-independant. The only reason(s) it needs to be adjustable at all is that people get this wrong in the first place (and actual errors which are unavoidable, lag, etc)

Basically, if you get it "perfect" you should be able to swap sensor types, and only change the values in your thermo table - without lieing in it, or retuning!

So, again, I think it really comes down to how it propegates. I think if you don't look at the size of those effects, you'll spend a lot of time looking at how to make it perfect only to find it doesn't matter, or ignoring it where it does.
User avatar
AbeFM
Post Whore!
Posts: 629
Joined: Sat Feb 16, 2008 12:11 am
Location: Sunny San Diego
Contact:

Re: Coolant and Inlet Air Temps Transfer Required Accuracy??

Post by AbeFM »

I guess the only other thing for me to add (since you seem to be getting along well!) is how many points do we need? I bet you could go from 1024 points to 128. Certainly, it would be nice to have some where my motor actually operates. I don't really care about fantastic accuracy in coolant temps below 50*C. Certainly if my motor is so cold all I'm doing is warming it up, these can be whatever.

Air temps are a different story.

But I think you could save a lot of space by looking at the error in a linear fit midway between the points as a function of the points spacing out a lot. I think you'll find that 20*C might read 22*c, and won't matter one bit, and you can take the 500 bytes back and use them to store naughty pictures of your girlfriend.

<edit for spelling>
shameem
LQFP112 - Up with the play
Posts: 135
Joined: Thu May 01, 2008 6:30 pm
Location: Ann Arbor, MI
Contact:

Re: Coolant and Inlet Air Temps Transfer Required Accuracy??

Post by shameem »

500 bytes for naughty pics :shock:

you mean ascii art? :P
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: Coolant and Inlet Air Temps Transfer Required Accuracy??

Post by Fred »

That was my whole point. You could probably get away with 16, but the cost is in speed. If it turns out this stuff needs to be done on ISR time (looking like it) then it needs to be fast. 1024 points = instant. You simply use the ADC value as the index to the array and you have your temperature there and then. If you make it anything less you are messing around interpolating and calculating and doing multiple lookups etc. The more I think about it, the more I agree with Peter Siebold and the standard way of doing it.

The old saying "optimise last" comes to mind. This way is simple, easy, accurate, fast, the ONLY downside is the 2K of space, which by the time your code to do the math and fudge around with lesser schemes was all in memory, might not be a down side at all.

ASCII art... shocking! :-)

Fred.
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
User avatar
AbeFM
Post Whore!
Posts: 629
Joined: Sat Feb 16, 2008 12:11 am
Location: Sunny San Diego
Contact:

Re: Coolant and Inlet Air Temps Transfer Required Accuracy??

Post by AbeFM »

Ok, ok, wait till we run out of space then.

What I don't see is how this doesn't fall under the category of something that could be done outside of the ISR, and you grab the number when you want it.


in main loop:
Current_Coolant_Temp = Stupid_long_interpolative_calculation_function(ADC count)

ISR:
blah blah blah * Current_Coolant_Temp


(seems faster than looking it up in some big old array)


The draw back? Your data is, oh, 8ms old. Personally, unless I set off nuclear bombs in my motor, the coolant change is always under 1*/second. Plus, this way you can do smoothing, getting higher accuracy from the averaging, and no weird issues from spikes.
Fred wrote: ASCII art... shocking! :-)
If you have an artist's touch, it could be!
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: Coolant and Inlet Air Temps Transfer Required Accuracy??

Post by Fred »

8InchesFlacid wrote:What I don't see is how this doesn't fall under the category of something that could be done outside of the ISR, and you grab the number when you want it.
Noise rejection. To avoid noise from injector flyback and ignition flyback (possibly even the alternator slightly) the plan is to sample all ADCs synchronously and to do the averaging on the final variable. If we sample synchronously, but use the sample and average asynchronously then we will be losing samples. I don't know if that matters or not, and would only happen at umpteen million rpm, but it seems ugly. Then again doing mundane things like that in the ISR seems ugly too. We will see.
in main loop:
Current_Coolant_Temp = Stupid_long_interpolative_calculation_function(ADC count)

ISR:
blah blah blah * Current_Coolant_Temp


(seems faster than looking it up in some big old array)
It is not possible to be faster than instantly addressing the memory directly as in

temp = temps[adc];

That says "take the value of length (data type (16)) from address (*temps + adc) and store it in the address (*temp)"

You CAN'T beat that, even if you want to :-)
The draw back? Your data is, oh, 8ms old. Personally, unless I set off nuclear bombs in my motor, the coolant change is always under 1*/second. Plus, this way you can do smoothing, getting higher accuracy from the averaging, and no weird issues from spikes.
Well, it may be somewhat idealist of me to even try to sample the way I am going to, but I'd like to try to make it work. I can use two counters to see how many samples are lost at various rpms with the transfer and averaging done asynchronously. At the moment it will be zero, but I can insert a "sleep 20 ms" in the main loop to ensure it's realistic.

Fred.
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
shameem
LQFP112 - Up with the play
Posts: 135
Joined: Thu May 01, 2008 6:30 pm
Location: Ann Arbor, MI
Contact:

Re: Coolant and Inlet Air Temps Transfer Required Accuracy??

Post by shameem »

Here's the result of 10 mins of hacking with console based c++ code - the values are based on the ones in the excel sheet

Code: Select all

#include <iostream.h>
#include <math.h>

int main(int argc, char* argv[])
{
	double r1=0,r2=0,r3=0,t1=0,t2=0,t3=0,x1=0,y1=0,x2=0,y2=0,x3=0,y3=0,a=0,b=0,c=0,y1c=0,y2c=0,y3c=0, rb=0, i=0,v=0;
	
	cout << "ThermFactor\n\nPlease provide three resistance-temperature measurments \nfrom your sensor and the program will calculate coefficients \nand generate a lookup table\n" ;

	/*
	cout << "\nPlease Enter Resistance Value 1(ohms): ";
	cin  >> r1;
	cout << "\nPlease Enter Temperature Value 1(c): ";
	cin  >> t1;
	cout << "\nPlease Enter Resistance Value 2(ohms): ";
	cin  >> r2;
	cout << "\nPlease Enter Temperature Value 2(c): ";
	cin  >> t2;
	cout << "\nPlease Enter Resistance Value 3(ohms): ";
	cin  >> r3;
	cout << "\nPlease Enter Temperature Value 3(c): ";
	cin  >> t3;
    */

	r1=5503.67;t1=-10;
	r2=1990;t2=10;
	r3=800.5;t3=30;

	x1=1/(t1+273.5);
	x2=1/(t2+273.5);
	x3=1/(t3+273.5);
	y1=log(r1);
	y2=log(r2);
	y3=log(r3);
	y1c=pow(y1,3);
	y2c=pow(y2,3);
	y3c=pow(y3,3);

	c=(((y2-y1)*(x3-x1))-((y3-y1)*(x2-x1)))/(((y3c-y1c)*(y2-y1))-((y2c-y1c)*(y3-y1)));
	b=((x2-x1) - (c*(y2c-y1c)))/(y2-y1);
	a=x1-b*y1-c*y1c;


	cout<<"A:"<<a<<"\n"<<"B:"<<b<<"\n"<<"C:"<<c<<"\n";



	r1=990;
	y1=log(r1);
	y1c=pow(y1,3);
	x1=1/(a+b*y1+c*y1c);
	cout<< "For Resistance 990 ohms, T="<<x1-273.5 <<"\n";
	r1=2040;
	y1=log(r1);
	y1c=pow(y1,3);
	x1=1/(a+b*y1+c*y1c);
	cout<< "For Resistance 2040 ohms, T="<< x1-273.5 <<"\n";


	/*
	cout << "\nPlease Enter Bias Resistance Value(ohms): ";
	cin  >> rb;
	cout << "\nPlease Enter Bias Voltage Value(v): ";
	cin  >> v;
	*/

	rb=1000;
	v=5;

	i=v/rb;


	cout<<"Volt"<<"\t"<<"Temp"<<"\t"<<"Res"<<"\n";
	for (int loop=1;loop<1024;loop++)
	{
		r1=loop/i;
		y1=log(r1);
		y1c=pow(y1,3);
		x1=1/(a+b*y1+c*y1c);
		cout<<loop<<"\t"<<x1-273.5<<"\t"<<r1<<"\n";
	}

	return 0;
}

Code: Select all

ThermFactor

Please provide three resistance-temperature measurments 
from your sensor and the program will calculate coefficients 
and generate a lookup table
A:0.00171881
B:0.000227724
C:1.79706e-007
For Resistance 990 ohms, T=25.1358
For Resistance 2040 ohms, T=9.48451
Volt	Temp	Res
1	65.2426	200
2	46.8215	400
3	36.8097	600
4	30.0145	800
5	24.9088	1000
6	20.8391	1200
7	17.4671	1400
8	14.5955	1600
9	12.0996	1800
10	9.89576	2000
11	7.92499	2200
12	6.14445	2400
13	4.52196	2600
14	3.03277	2800
15	1.65743	3000
16	0.380422	3200
17	-0.810845	3400
18	-1.92673	3600
19	-2.97583	3800
20	-3.96539	4000
21	-4.90153	4200
22	-5.78952	4400
23	-6.63385	4600
24	-7.43847	4800
25	-8.20678	5000
26	-8.94179	5200
27	-9.64616	5400
28	-10.3222	5600
29	-10.9721	5800
30	-11.5977	6000
31	-12.2006	6200
32	-12.7824	6400
33	-13.3444	6600
34	-13.8879	6800
35	-14.414	7000
36	-14.9238	7200
....
1020	-66.5179	204000
1021	-66.5309	204200
1022	-66.5438	204400
1023	-66.5567	204600

Post Reply