|Click on our menu buttons immediately below to find MegaSquirt® information quickly:|
MegaShift™ ADC Calculations
When setting up the MShift™/GPIO ADC channels for 'non-standard' usage, there are a number of considerations:
So if the relationship is linear, the conversion is OilPress = 60/512 = 0.117 × ADCcount
In the INI you find this in the [OutputChannels] section. There are lines like:
OilPress = scalar, U16, 21, "volts", 0.00488, 0.0
Where 0.00488 and 0.0 are the factors you would change (0.00488, 0.0 changes a 1024 ADC count value to a 0-5V reading).
And where "OilPress" is the name TunerStudioMS will use for the value calculated from the information returned from the controller. ('scalar' means the magnitude is important, not necessarily the individual bits; and 'U16' means it is an Unsigned integer with a length of 16 bits - i.e. a value between 0 and 65535 = 216).
21 is the offset, in bytes, that the relevant value is from the start of the outpc structure (aka. the "Output Channels"). Other offsets for ADC channels are:
(already returned as Volts, not an ADC count)
The exact line you change depends on which ADC input you used for the oil pressure sensor (if you used the linepressure input, the line has offset of 21, but if you used the line pressure input, you must set the software to return the ADC count and not the pressure). You can call it anything you like by changing the 'OilPress' label. You can edit the INI with any plain text editor, such as Notepad. The calculator below will help you to determine the appropriate values to enter.
; Name = Case-sensitive, user-defined name for this gauge configuration. ; Var = Case-sensitive name of variable to be displayed, see the ; OutputChannels block in this file for possible values. ; Title = Title displayed at the top of the gauge. ; Units = Units displayed below value on gauge. ; Lo = Lower scale limit of gauge. ; Hi = Upper scale limit of gauge. ; LoD = Lower limit at which danger color is used for gauge background. ; LoW = Lower limit at which warning color is used. ; HiW = Upper limit at which warning color is used. ; HiD = Upper limit at which danger color is used. ; vd = Decimal places in displayed value ; ld = Label decimal places for display of Lo and Hi, above. ;Name Var Title Units Lo Hi LoD LoW HiW HiD vd ld ... oil_pressure = OilPress, "Oil Pressure", "psi", 0, 100, 5, 15, 80, 90, 0, 0
The conversion is already taken care of when OilPress is returned from the controller by the equation we used above.
; Channel Label Type Format ; -------------- ---------- ----- ------ ... entry = OilPress, "OP", float, "%.2f"
anywhere you like (the datalog will contain the values in columns in the order you list them. The entry tells TunerStudioMS to datalog the variable OilPress with the heading OP as a floating number (not an integer) with 2 decimal places (%.2f).
For the INI factors, the format is :
Name = scalar, U16, offset, "units", multiplier, constant
or in the case of the default values from the calculator:
OilPress = scalar, U16, 21, "psi", 0.175, -29.825