Manipulating ADC6 values for an Oil Pressure Gauge

This is a forum for discussing the development and testing of alpha MS2/Extra code. Documentation
(Runs on MS2 and Microsquirt)

Moderators: jsmcortina, muythaibxr

Post Reply
patbarber
MS/Extra Newbie
Posts: 8
Joined: Mon Jan 08, 2018 1:55 pm

Manipulating ADC6 values for an Oil Pressure Gauge

Post by patbarber »

I am trying to use my AIM Solo DL as a digital Dash in my 84 ½ Formula Ford.

I am using a MicroSquirt as the sensor interface converting all the sensor inputs and making the values available on CAN to be pulled by the Solo DL. Other than lighting a few LED's and the CAN bus, no other output features are being used. Where the sensors match the intended function of the Microsquirt, such as TPS, RPM (OPTO+-),CLT, I have had Great Success. Where the sensors do not match, well, this is where the challenge lies. I am trying to get an oil pressure sender to provide oil pressure to my device, will only limited success.

AIM Solo DL will not display the actual oil pressure on the display, just ADC Counts. This might not sound so bad, other than the ADC counts are inversely proportional to the actual pressure. Low counts = high pressure, High counts=low pressure. This makes it confusing to see high numbers when the engine is off and lower numbers when it is running. BTH, the sensor is connected to ADC6(I guess that was in the title). I had similar plans to add a Hall effect sensor to VR2, but let’s tackle this one first.

I have upgraded to registered version of TunerStudio. This allows me to create custom variables and custom gauges. This works great on the PC, unfortunately, it didn’t work on my Solo DL because:
1.The new variables seem to remain local to the PC
2.Even with the new variables, they are not part of the memory stack being queried by Solo DL.

I have tried to create an expression similar to ADC6={0.0 + (100.0 - 0.0) * ((adc6 - 813.0 )/( 175.0 - 813.0 )) But unfortunately this did not seem to work. I believe that because ADC6 is not part of the *.MSQ file, it does not become part of the tune burned to the MS.

Is there a way that I can mathematically change one of the variables already in the MSQ file so that it reads 0-100. In perhaps clearer terms, a function similar to what is done with TPS. The calibration of this sensor worked great!
Attachments
custom.ini
Custom Gauge file
(5.15 KiB) Downloaded 56 times
Barber-OIl Pressure-ADC6.msq
MSQ file
(119.17 KiB) Downloaded 83 times
Patrick Barber
robs
Master MS/Extra'er
Posts: 564
Joined: Sun Jan 17, 2010 4:26 pm
Location: Sydney, Australia

Re: Manipulating ADC6 values for an Oil Pressure Gauge

Post by robs »

Modifying expressions in the INI file will only affect TunerStudio -- they tell the PC how to manipulate the values read from the Megasquirt.

The Megasquirt firmware always outputs the same set of values. The ones you are interested in are defined in the Megasquirt firmware and only described in the [OutputChannels] section of the .INI file. It seems to me there are two possibilities to get your SoloDL to display the oil pressure as you want:

1. If the SoloDL itself can be configured to do the calculation, that's the best way to go. I don't know anything about this gadget, but it says "fully User customizable pages", which I'd have thought would allow scaling and offsetting values read from the ECU.

2. Custom firmware for the Megasquirt which provides your ADC6 value already cooked. Not all that hard to do, but it means one-off firmware for you.

Thinking about it some more, it is *possible* that the SoloDL does understand the INI file. How did you tell it that it was talking to a MicroSquirt running version X.X.X of the MS2/Extra firmware via CAN bus? That's where the mapping from polled blob of data to [OutputChannels] values happens, and it would make sense for you to be able to adjust those values somewhere near there.

Perhaps your best step would be to ask SoloDL Technical Support.

Have fun,

Rob.
patbarber
MS/Extra Newbie
Posts: 8
Joined: Mon Jan 08, 2018 1:55 pm

Re: Manipulating ADC6 values for an Oil Pressure Gauge

Post by patbarber »

robs wrote: 1. If the SoloDL itself can be configured to do the calculation, that's the best way to go. I don't know anything about this gadget, but it says "fully User customizable pages", which I'd have thought would allow scaling and offsetting values read from the ECU.

2. Custom firmware for the Megasquirt which provides your ADC6 value already cooked. Not all that hard to do, but it means one-off firmware for you.

Thinking about it some more, it is *possible* that the SoloDL does understand the INI file. How did you tell it that it was talking to a MicroSquirt running version X.X.X of the MS2/Extra firmware via CAN bus? That's where the mapping from polled blob of data to [OutputChannels] values happens, and it would make sense for you to be able to adjust those values somewhere near there.

Perhaps your best step would be to ask SoloDL Technical Support.

Have fun,

Rob.
Thanks Rob.
I have included a PDF file with a lot more detail on my situation. My original post was a text summary of my findings.
Long story short. The Solo DL pulls data from MS. At Some point, the team at AIM Sports received a variable list and address locations and created their config file. They have done this for ~100 other OEM ECU's. While they provide something that looks like a configuration editor, math can only be done in post processing and I want real time data for my dash.

My direction now is to try to change the code and create a custom .S19 file for my setup. I have identified where the ADC6 variable(and others) get manipulated and stored. Most of these are manipulated in the C code file called MS2_Extra_Misc.C.The manipulation takes place in the function called get_adc(). The problem I have run into is that this code does all of its arithmetic in Assembly Language. :? It is a bit discouraging because the MS2_Extra_Main.C does all of its arithmetic in C which is considerably easier to code. I am not sure how to tell the compiler that I want to evaluate my expression in C, but I will continue to look. I understand why it is assembly code; it is significantly faster and more efficient than C.

Just for reference, here is the expression;
outpc.adc6=(-0.1567*ATD0DR6)+127
Seems simple enough, it is simple aX+b expression which takes the value from the AD converter, transforms it, then places it in the global variable outpc.adc6 which is used by CAN and data logger.
Attachments
AIM Solo DL Oil Pressurea.pdf
(630.48 KiB) Downloaded 64 times
Patrick Barber
racingmini_mtl
Super MS/Extra'er
Posts: 9128
Joined: Sun May 02, 2004 6:51 am
Location: Quebec, Canada
Contact:

Re: Manipulating ADC6 values for an Oil Pressure Gauge

Post by racingmini_mtl »

patbarber wrote:Just for reference, here is the expression;
outpc.adc6=(-0.1567*ATD0DR6)+127
Seems simple enough, it is simple aX+b expression which takes the value from the AD converter, transforms it, then places it in the global variable outpc.adc6 which is used by CAN and data logger.
Except that the code doesn't use floating point variables or operations since the CPU would not deal well with those. You'll need to find a way to convert that to the integer equivalent (for example, where does the 0.1567 comes from?).

Jean
jbperf.com Main site . . . . . . . . . . . . . . . . . . . . . . jbperf.com Forum
Image
robs
Master MS/Extra'er
Posts: 564
Joined: Sun Jan 17, 2010 4:26 pm
Location: Sydney, Australia

Re: Manipulating ADC6 values for an Oil Pressure Gauge

Post by robs »

I read the pdf file and you've obviously been systematic about this. Rather than cut'n'paste values into those PARAM_x parameters, I'd try plugging in known values and seeing what it does to the reading. Your expression wants to scale first, then offset. INIZ_SCALA sounds like where I'd start. Strange that it's zero though... I'd have expected it to be 1.0. Anyhow I'd start with it. FINE_SCALA sounds like final scaling, probably done after offsets and not what you need. Here's how I'd proceed:
  1. Set INIZ to 1.023E03 and FINE to 0.0. If that only gives you zeroes, try FINE = 1.0. Expecting this to give you the same readings you've been getting (0psi ~ 810).
  2. Change INIZ to -1.60E02 (i.e. -.1567*1023). This should give oil pressures 127 psi below correct value.
  3. Experiment with PARAM_x values, plugging in 1.27E02 to each in turn (restoring them to 0 if they don't work).
Fair enough that the support people at AIM Sports aren't fussed about an old model, but they might have offered you documentation to save having to reverse engineer their config file.

If you can't get anywhere with that, I'll be happy to help with the MS2/Extra assembly language stuff. As Jean says, no floating point in this processor, but I see your scaler is very close to -642/4096, so not a big problem.

Have fun,

Rob.
patbarber
MS/Extra Newbie
Posts: 8
Joined: Mon Jan 08, 2018 1:55 pm

Re: Manipulating ADC6 values for an Oil Pressure Gauge

Post by patbarber »

Well, after ~8 Hrs of "learning", it seems as if I figured it out.
It turns out that you do not need to deliver all the math expressions in the get_adc function in assembly. I just wrote the expression incorrectly and the complier puked on it. :) Here is the initial expression I was trying to evaluate

Code: Select all

 ;channelName      =  class,   dataType,   offset,     "Units",     scale,       translate
    ;------------        -------  ---------   -------     --------       ------       ---------


     OilPressure                 = {0.0 + (100.0 - 0.0) * ((adc6 - 813.0 )/( 175.0 - 813.0 ))}, "PSI"
and here is the code efficient version:

Code: Select all

outpc.adc6=(int)(127-(15*ATD0DR6)/100)
You will notice that as Robs stated above, I had to work with integers which meant that I had to convert my scaling factor from 0.1567 to 1567 then multiply by the value in the ADC, then divide by 1000. Good approach, it got me some of the way there, but there are limitations on the size of the numbers which can be calculated. I found that none of the intermediate values can exceed 64535. Once I figured that out, it only took another 10-20 iterations to get it right :o . The bottom line is that it worked!

Here are some things that I learned:
* Integers -memory efficient but tricky
* Complier - It took me 6-7 hours to figure out how to get that Cygwin system working, primarily because
1. You CANNOT use the 64 bit version
2. you cannot load every "Devel" package into the system. It was over 10Gb of packages, took hours to download, load and ultimately delete
3. All I installed is the GNU version of Make and it "seems to work" Something is not quite right as the CLT look up tables in the INI file got all messed up. A challenge for another time.
* The DMP file is pretty cool... It is the Assembly code developed from the complier.
* I am not going to quit my day job.

Thanks for your help!
Patrick Barber
jsmcortina
Site Admin
Posts: 39587
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: Manipulating ADC6 values for an Oil Pressure Gauge

Post by jsmcortina »

patbarber wrote: I found that none of the intermediate values can exceed 64535.
You need to cast them to long (32bit on this system) or use UL or L as the suffix for numbers.
In C, you must have the input variable size large enough for the result. i.e. if you want a 32bit result, at least one of the inputs must be 32bit.
e.g. try this.

Code: Select all

outpc.adc6=(int)(127-((1536L*(long)ATD0DR6)/10000L)
James
I can repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
robs
Master MS/Extra'er
Posts: 564
Joined: Sun Jan 17, 2010 4:26 pm
Location: Sydney, Australia

Re: Manipulating ADC6 values for an Oil Pressure Gauge

Post by robs »

That *does* sound like a character building journey you've been on. Sorry I didn't respond sooner -- might have helped -- I look in here most days, but somehow missed it.

A couple of random thoughts -- rather than use Cygwin you might consider making a virtual machine using VirtualBox and installing Linux on it. All of that works pretty well and isn't a half way approach like Cygwin (nice though it is). I admit this might be another character building experience, but should make life easier if you come back to dabble in the source again.

C could have handled larger integers, but you need to tell it what to do. Something like:

outpc.adc6 = 127-((long)(1536L * ATD0DR6)/10000L);

should do the trick. The (long) tells the compiler to evaluate the following expression at 32-bit precision. That should hang on for the division at which point it'll be demoted back to 16-bit integer.

However, given that you're only expecting a number between 0 and 127 (and preferably a fair way from both) you hardly need all this extra accuracy. If you did want to improve your approach slightly you could use 127-(28*ATD0DR6)/134). That still fits in 16 bits and gives you 0.156716 rather than 0.1500 which is slightly closer to your "ideal" number.

I still suspect there was a way to do this with the dash config. Perhaps looking at what it does with TPS, which is scaled by 0.1 might give a hint. Or if they allow temperatures in Celsius, that would have scaling and offsetting.

Still, I was late to the party and you have it working, so fair enough. I'll not nag.

Have fun,

Rob.
jsmcortina
Site Admin
Posts: 39587
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: Manipulating ADC6 values for an Oil Pressure Gauge

Post by jsmcortina »

robs wrote:C could have handled larger integers, but you need to tell it what to do. Something like:

outpc.adc6 = 127-((long)(1536L * ATD0DR6)/10000L);

should do the trick. The (long) tells the compiler to evaluate the following expression at 32-bit precision.
Not quite. The cast must be applied to the inputs, not the output.

James
I can repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
robs
Master MS/Extra'er
Posts: 564
Joined: Sun Jan 17, 2010 4:26 pm
Location: Sydney, Australia

Re: Manipulating ADC6 values for an Oil Pressure Gauge

Post by robs »

Fair enough. I've always been a bit vague on C casting/promotion (and precedence for that matter), so I was lazy and hedged by saying "something like". Main point stands though: not much use carefully keeping 32-bits of precision when your final value will only be 7 bits.

Have fun,

Rob.
Post Reply