Custom sensor config for Westach 399S9 (and other 399-series) temp senders

RaymondJ

New Member
Joined
Nov 25, 2020
Messages
10
Hi folks!

I've been installing a new Dynon HDX setup in my VariEze, which has a Continental O-200 -- and a Westach oil temp sender. Out of the box, Dynon doesn't support the Westach 399S9, but the custom sensor config made it easy enough to figure out.

To cut to the chase, here's a custom sensor config that aims to read w/ 1-2 degF precision between 50 degF and 300degF:

Code:
; Oil temp sensor
; Westach 399S9 5/8-18 (works in O-200)
sensor={
    id=WESTACH 399S9 FLUID TEMP
    function=TEMPERATURE
    pins=C37_P4 C37_P6 C37_P7 C37_P8 C37_P9 C37_P10 C37_P11 C37_P12 C37_P20 C37_P21 C37_P22 C37_P23 C37_P31
    name=OIL
    name=COOLNT
    min_val=30
    max_val=300
    resolution=0
    round=1
    is_piecewise=1
    low_coeff={
        c_x4=225.773140473756
        c_x3=-732.481169562626
        c_x2=938.20080400168
        c_x1=-650.289331085758
        c_x0=418.223102231748
    }
    low_resistance=PULL_UP_1K
    low2high_cross=1.075
    high_coeff={
        c_x4=0.00840837188904419
        c_x3=-3.02084639830709
        c_x2=25.0059469090107
        c_x1=-106.561690888733
        c_x0=283.134726734304
    }
    high_resistance=PULL_UP_1K
    high2low_cross=1.025
}

This allows the sensor to be used on most input pins (4/6/7/8/9/10/11/12/20/21/22/23/31). To use, connect one lead to an aforementioned pin, and the other to a local ground.

I've tested this on my engine and can verify that on a cold boot, CHTs and carb temp agree within 5 degF. The temp also rises as I run the engine, and I'll be watching for possible sensor oddities as I do more run-ups and get more hours.

Here's how I derived this definition, for the curious:
  1. Obtain a sensor specification from the vendor. Luckily, Westach has direct ohm listings on their website (https://www.westach.com/product-page/399-series-temp-senders). I typed in the values into a file, for processing.
  2. Make some assumptions about Dynon ADC properties. The wiki page (https://wiki.dynonavionics.com/Making_your_own_sensor_definitions) has a lot of reallyuseful information, but one thing was unstated: the pull-up voltage. I know that the sensor polynomial is applied to a voltage. I also know that the Westach 399S9 is a NTC thermistor. So, if I know the voltage that the pull-up resistor is connected to, it's pretty straightforward to calculate the input voltage if you view the pull-up + temp sensor combo as a resistor divider.
    1. For my analysis, I assumed 5V -- based on some EE intuition from looking around at the behavior of pins without pull-ups and the acceptable common range specs. (Dynon folks, if I'm wrong, please let me know!)
  3. Do some math. Here's where it gets a little specialized. I've dealt with some approximation theory, so I have someintuition for this -- but it's far from being mathematically clean. This approach works well enough for oil temp data, but for OATs or other sensors where <1deg accuracy would benefit, double check with your local mathematician.
    1. Fit a Steinhart-Hart style equation to the vendor data.While Westach provides a ton of data, I ran into some problems with fitting polynomials directly to these points. For convenience, I fitted a standard Steinhart-Hart plot to the data as an intermediate representation. This gave me reasonable error (<1deg) for most of the usable range.
      • vendor_vs_s-h.png
      • vendor_vs_s-h_error.png
    2. Figure out what this looks like after the voltage divider.Using the formula for a resistor divider, I went from resistance (ohms) to volts (what the EMS-220 actually sees). The pull-up value determines the shape of this graph, and I picked 1000 ohms as it results in fairly linear behavior in the important regions (oil temp on an O-200 is usually between 80-200 degF). The more linear, the better: picking the wrong pull-up value can make this curve unfittable (too much change for the 4th order polynomial to keep up).
      • temp_vs_voltage.png
    3. Fit a piecewise 4th-order polynomial to the voltage curve. Now that I had the temp-voltage curve, I could do the actual fit. The key variable to adjust is the "transition voltage" between the two different polynomials. I adjusted this by hand (mostly as I knew what I was looking for, and gnuplot's fit algorithm had some trouble adjusting the transition voltage). Varying the transition voltage has the effect of changing how much voltage each 4th-order polynomial covers, which also impacts how much error is present on each span. If a polynomial is asked to cover a smaller voltage range, generally it will do a better job of fitting. The overall minimum will be accomplished when the error in each span is roughly equivalent, as shown in the graph below.

      Aside from the transition voltage, the other knob to turn is the total sensor span. If I attempted to maintain accuracy down to 30 degF, the fit error over the whole span increased dramatically (suddenly talking 1-2 deg F and not 0.3 deg F). I decided to sacrifice low temp behavior as nobody (should) be operating very long on frozen oil. 50 degF is enough for a quick cross-check with carb temp and OAT at power-on for where I'm located.

      The "knee" here at ~190deg F is the location of the crossover between the low and high polynomial. I'm not surprised by the discontinuity as I didn't perform any sort of weighting to promote a smooth crossover, and 0.8deg F delta isn't a big deal as we cross through the region.
      • polynomial_vs_s-h_err.png
    4. Validate the results against vendor data. I pulled in the Steinhart-Hart equation because it was convenient, but it's generally better to perform the polynomial fit directly to vendor data if you can. (Every layer of modelling allows assumptions and errors from that layer to come in!) So, I made sure to cross-check our piecewise 4th-order polynomial against what the vendor data says, and it lines up fairly well -- I was happy with the overall fit being within 1-2 deg F, especially since I couldn't read that resolution on my old steam gauges!

      On the second picture, you can see what happens outside of the fit region: the error at 30 degF and 400 degF is atrocious. If my oil temps are reading that, I have other problems!
      • vendor_vs_poly_error_zoomed.png
      • vendor_vs_poly_error.png

All of the work here was done with Gnuplot (http://www.gnuplot.info/), a free open-source plotting/fitting utility which runs on Windows/Linux/most Macs. I'm happy to send the script and input data files via DM or email if you'd like to play around with them (I exceed max post length if included here!).

Let me know if I'm totally off-base or if you have any suggestions!

Thanks,
Raymond
 
Last edited:

jdubner

Member
Joined
Apr 30, 2006
Messages
148
Location
Independence, OR
Nice job digging out the info and curve-fitting, Raymond! Dynon should include it in the Wiki as a working example.

Your "how to" makes me want to hook up some miscellaneous, random analog sensors to my SkyView EMS to display things I haven't thought about until now. Hmmmm . . .
 

Dynon

Dynon Staff
Staff member
Joined
Jan 14, 2013
Messages
14,231
Location
Woodinville, WA
First. Wow. Nicely done.

Also... Yep, you're correct on the 5V.

    1. For my analysis, I assumed 5V -- based on some EE intuition from looking around at the behavior of pins without pull-ups and the acceptable common range specs. (Dynon folks, if I'm wrong, please let me know!)
 
Top