Mitsi/Mazda 4and1 CAS Decoder

For discussing and developing different RPM/Position decoders using our superior modular architecture! One thread per pattern, please.
Post Reply
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Mitsi/Mazda 4and1 CAS Decoder

Post by Fred »

This was/is the first decoder with a full feature set used in FreeEMS. This is the decoder that briefly ran my truck before the rod folded in half from the load.

The documentation and logic for this decoder are currently all in the comments in the source file. I would like that to continue to be the case, but very much tidied up and in a good state for doxygen doc generation.

I won't duplicate those docs here at this point, though I will link once they are up on a doxygen page.

I will give a TODO for the decoder, though:
  • Refactor RPM/Position code to use 1/10th degree resolution variables for event angles.
  • Update the angles in the code to be accurate and final. "DSM" diagram shows 70 degree slots, but I measured about 68.7 degrees or so, and we're currently using 69. This needs careful analysis of both the optical and hall effect variants such that the code can be built twice with different arrays if the sensors behave subtly differently.
  • Move RPM and ADC var readings to leading and/or trailing (configurable) edge of outer signal ONLY. Leaving in place the initial sync RPM calc and sample for quick starting.
  • Make the noise detection code configurable in a generic way, and perhaps make it proportional to the angle being measured, where smaller angle = smaller allowable variation. Possibly only do noise detection between outer events. Perhaps use a flash only array to hold the tolerances such that they can be configured on an individual basis per event.
  • Vastly improve the doxygen documentation to release quality.
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
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: Mitsi/Mazda 4and1 CAS Decoder

Post by Fred »

Just ripped all of this out of the source file because it was making reading it a pain, kept here as well as in the git history, for reference, will link to this thread instead:

Code: Select all


Outer           Inner
30 signal    295
60                65 signal
30 signal
60
30 signal
60
30 signal
60

Outer:
0
on
30
off
90
on
120
off
180
on
210
off
270
on
300
off
360/0

Inner:
0
off
295
on
360/0

Inner:
off
261
on
326
off

Crank (double all cam angles):

Outer:
0
on
60
off
180
on
240
off
360
on
420
off
540
on
600
off
720/0

Inner (disk):
0
off
590
on
720/0

Inner (actual):
off
522
on
652
off

figures for inner above are wrong due to offset LEDs in CAS body!!!! Find offset value and adjust these figures. Note this in docs re disk pattern and actual pattern.

34 cam degrees or slightly less (inner degrees earlier than on disk.

use hash define and let the compiler take care of the math so that its easier to change.

Logic:

const unsigned short eventCrankAngles[] = {0, 60, 180, 240, 360, 420, 522, 540, 600, 652}
measured values with compression effect = {0, 73, 184, 257, 367, 436, 530, 545, 612, 671}
                            differences = {0, 13,  14,  17,   7,  16,   8,   5,  12,  19}
the above needs verify on init to ensure order is sequential!
unsigned char array pinEventNumbers[6] = {} // 6 pins, which even should they go on? 255/0xFF = not fired. populated by scheduler in main loop
^ only good enough in short term, in longer term, could expect same pin to fire on multiple events in a cycle...

event number, pin number

if(synced){

if inner fires, increment, then event should be  6th or 9th (zero index)
if outer fires, increment, then event should be 0th - 5th, 7th, 8th. If 9th make equal 0th, not 10th

only outer needs check for 9th > 0th, inner will catch based on not 6th/9th/rising/falling.

for either:

take last period, and last angle gap, calc ticks per degree or similar, generate limits, compare measured with limits, drop sync if wrong.

else if(not synced){ look for logic as per below:

ten transitional events total per engine cycle:

5 provide sync:

if inner = off to on, position = 522 degrees
if inner = on to off, position = 652 degrees

if outer = on to off AND inner = on, then position = 600
if outer = off to on AND inner = on, then position = 540
if outer = off to on AND is third while inner = off, then position = 360

information of no use for obtaining sync:

outer on to off and is third while inner = already synced by definition
other four outer events are not identifiable as anything specific and therefore cant sync

Loss of sync:

Lose sync if time between one event and next is not within allowable range, or if ordering of inner/outer events is not correct.
Possibility of ignoring narrow pulses in order to be noise tolerant, but this comes with risk.

Summary:

Sync obtainable for 292 degrees of crank rotation and not for remaining 428 degrees

worst case is 428 degrees of rotation before sync/injection/ignition, average case is 214 degrees rotation, best case is instant sync.

temporary pin sched code:

for(pin 0 - 5){
	if(pinEventNumbers[pin] == event){
		firePin(pin, delayFromEventInTicks);
	}
}

Checking tooth timing! :

record time stamps from all events outside of IF conditions, and before sync,
and set flag saying that stamp is valid such that when the first sync point is
found we MIGHT be able to get an RPM instantly and verify the second event
timing when it arrives, rather than one later. This concept could be extended
to record the previous two, but not yet...

record time stamps, set stamp valid flags
record periods, set period valid flags
once synced, compare recorded data with expected history, drop sync if not, so will never get sync if noisy, great!


WARNING: THESE CONTAIN COMPRESSION EFFECTS!!!


Visual version courtesy of hacked OLV:

http://stuff.fredcooke.com/high.res.4and1.cas.la.trace.png

Binary log of format (Start, flags, payloadID(2), PTIT, checksum, Stop, Stop) :

http://stuff.fredcooke.com/portT.min.1.la


Real readings from truck cranking test:

14213 - start of first outer slot (goes low at CPU, goes high outside)
14262 - end of first outer slot (goes high at CPU, goes low outside)
14337 - start of second outer slot (goes low at CPU, goes high outside)
14386 - end of second outer slot (goes high at CPU, goes low outside)
14460 - start of third outer slot (goes low at CPU, goes high outside)
14507 - end of third outer slot (goes high at CPU, goes low outside)
14570 - start of inner slot (goes low at CPU, goes high outside)
14580 - start of fourth outer slot (goes low at CPU, goes high outside)
14625 - end of fourth outer slot (goes high at CPU, goes low outside)
14665 - end of inner slot (goes high at CPU, goes low outside)
14698 - start of first outer on next cycle�.

remove 14k from each:

213 - start of first outer slot (goes low at CPU, goes high outside)
262 - end of first outer slot (goes high at CPU, goes low outside)
337 - start of second outer slot (goes low at CPU, goes high outside)
386 - end of second outer slot (goes high at CPU, goes low outside)
460 - start of third outer slot (goes low at CPU, goes high outside)
507 - end of third outer slot (goes high at CPU, goes low outside)
570 - start of inner slot (goes low at CPU, goes high outside)
580 - start of fourth outer slot (goes low at CPU, goes high outside)
625 - end of fourth outer slot (goes high at CPU, goes low outside)
665 - end of inner slot (goes high at CPU, goes low outside)
698 - start of first outer on next cycle�.

remove 213 from each:

0 - start of first outer slot (goes low at CPU, goes high outside)
49 end of first outer slot (goes high at CPU, goes low outside)
124 start of second outer slot (goes low at CPU, goes high outside)
173 end of second outer slot (goes high at CPU, goes low outside)
247 start of third outer slot (goes low at CPU, goes high outside)
294 end of third outer slot (goes high at CPU, goes low outside)
357 start of inner slot (goes low at CPU, goes high outside)
367 start of fourth outer slot (goes low at CPU, goes high outside)
412 end of fourth outer slot (goes high at CPU, goes low outside)
452 end of inner slot (goes high at CPU, goes low outside)
485 start of first outer on next cycle�.

scale for degrees: (720/485) * num = degrees

0 - start of first outer slot (goes low at CPU, goes high outside)
72.742268 end of first outer slot (goes high at CPU, goes low outside)
184.082474 start of second outer slot (goes low at CPU, goes high outside)
256.824742 end of second outer slot (goes high at CPU, goes low outside)
366.680412 start of third outer slot (goes low at CPU, goes high outside)
436.453608 end of third outer slot (goes high at CPU, goes low outside)
529.979381 start of inner slot (goes low at CPU, goes high outside)
544.824742 start of fourth outer slot (goes low at CPU, goes high outside)
611.628866 end of fourth outer slot (goes high at CPU, goes low outside)
671.010309 end of inner slot (goes high at CPU, goes low outside)
720/0 start of first outer on next cycle�.

Broken into widths:

Outer:
72.742268 first outer slot (low at CPU, high outside)
111.340206 solid between first and second outer slots (high at CPU, low outside)
72.742268 second outer slot (low at CPU, high outside)
109.85567 solid between second and third outer slots (high at CPU, low outside)
69.773196 third outer slot (low at CPU, high outside)
108.371134 solid between third and fourth outer slots (high at CPU, low outside)
66.804124 fourth outer slot (low at CPU, high outside)
108.371134 solid between fourth and first outer slots (high at CPU, low outside)

Inner:
141.030928 inner slot (low at CPU, high outside)
578.969072 solid that isn't the inner slot (high at CPU, low outside)

Offsets:
93.525773 end of third outer slot to start of inner slot (no state)
14.845361 start of inner slot to start of fourth outer slot (no state)
59.381443 end of fourth outer slot to end of inner slot (no state)
48.989691 end of inner slot to start of first outer slot (no state)

Latest WITHOUT compression effects, but still with variations from engine friction etc etc...

logic.test.flat.battery.5.log.la

17363 = 0
17463 = 1
17633 = 2
17739 = 3
17900 = 4
18001 = 5
18144 = 6
18166 = 7
18266 = 8
18346 = 9
18425 = 0

100 - 0 - 1 slot
170 - 1 - 2 solid
106 - 2 - 3 slot
161 - 3 - 4 solid
101 - 4 - 5 slot
165 - 5 - 7 solid
100 - 7 - 8 slot
159 - 8 - 0 solid

rolling with 101.75 and 163.75

101.75/1062 = 0.0958097928
 * 720 = 68.9830508

163.75/1062 = 0.154190207
 * 720 = 111.016949

rounds to 69 / 111
close to 70/110


143 - 5 - 6 end outer start inner
  22 - 6 - 7 start inner start outer
  80 - 8 - 9 end outer end inner
  79 - 9 - 0 end inner start outer

202 - 6 - 9 - inner slot
860 - 9 - 6 = inner solid

202/1062 = 136.949153
860/1062 = 583.050847
137/583
140/580?

total period = 1062

0
100
270
376
537
638
803
903
1062

From file http://stuff.fredcooke.com/logic.test.flat.battery.5.log.la

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
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: Mitsi/Mazda 4and1 CAS Decoder

Post by Fred »

Timing diagram for this decoder.

Image
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!
Post Reply