Thursday 10 May 2012

2012 Starting again

So, where have I been??

Mostly I have been trying to sort out a garage.  Lots of clearing away shrubs and soil.  Rebuilding walls, planning the building and struggling with the council and their contrived rules.

It looks like the planning permission has gone through so hopefully I should be able to get a garage built before next winter.


Back to my car.
For the longest time I have had problems starting my engine. The issue was that the crank on my engine is lightened to the extreme, and so when cranking the compression effect slows and speeds the cranking rate.  The consequence of this is that the tooth spacings are not equal.  The effect of this when cranking is that the long tooth isn't detected reliably.

The algorithm (in ms2extra) requires the missing tooth (nominally 2x a normal tooth gap) to be 1.5x the tooth before it, and the tooth after the long tooth to be less than 3/4 of the length of the missing tooth.

This is too stringent, which is crap for me.

So, I changed the code slightly.

Now the long tooth has to be >1.5x the tooth before, but the teeth after only have to be 7/8 of the long tooth.  The big risk with this type of code is that if we sync on the wrong tooth then we could end up getting serious detonation and possible engine destruction.

To protect against this I have added additional checks, in this case the 3 teeth after the long tooth all have to be less than 7/8 of the long tooth.


Anyway, here is the code (mostly so I can find it when I next need it!)
ms2_extra_ign_in.c


    /************ missing tooth wheel & missing and 2nd trigger wheel mode *************/
SPKMODE4:
    if ((flash4.spk_config & 0xc) == 0x8) {
        goto SPKMODE4B;
    }
    /* this is the "find missing" step */
    // look for missing tooth (subtract last tooth time from this tooth
    // count taking overflow into account, and then multiply previous
    // tooth time by 1.5 and see


    if (firstsync_iter == 0) {
        /* Here we will look for missing */


        temp1 = tooth_diff_last + (tooth_diff_last >> 1);


        if (tooth_diff_this > temp1) {
            firstsync_iter = 1;
        }
        return;
    } else if (firstsync_iter == 1) {
        /* tooth after what we thought was missing, lets make sure this one is short
         * on the first sync, we miss tooth #1, but that's ok as long as we catch it next time
         * split this into 2 operations so compiler doesn't call subroutine
         */
        temp1 = (tooth_diff_last >> 1); /* 1/2 of last value */
        temp1 = temp1 >> 1; /* 1/4th of last value */
        temp1 = temp1 >> 1; /* 1/8th of last value MDR ADDED */


        //temp1 = tooth_diff_last - temp1; /* 3/4ths of last value */
        temp1 = tooth_diff_last - temp1; /* 7/8ths of last value MDR ADDED */


        if (tooth_diff_this >= temp1) {
            /* this wasn't really the missing tooth... */
            firstsync_iter = 0;
            return;
        }


        firstsync_iter = 2;
        /* flagbyte4 |= flagbyte4_found_miss; DONT THINK WE WANT THIS YET */
        set_count = 1;
    } else if (firstsync_iter == 2) {
/*Check the next tooth as well so as to be sure */
/* tooth after what we thought was missing, lets make sure this one is short
* on the first sync, we miss tooth #1, but that's ok as long as we catch it next time
* split this into 2 operations so compiler doesn't call subroutine
*/
temp1 = (tooth_diff_last_1 >> 1); /* 1/2 of last value */
temp1 = temp1 >> 1; /* 1/4th of last value */
temp1 = temp1 >> 1; /* 1/8th of last value MDR ADDED */


temp1 = tooth_diff_last_1 - temp1; /* 7/8ths of long tooth MDR ADDED */


if (tooth_diff_this >= temp1) {
   /* this wasn't really the missing tooth... */
   firstsync_iter = 0;
   return;
}


firstsync_iter = 3;
/* flagbyte4 |= flagbyte4_found_miss; */
        set_count = 2;  /* Guessed that this should be 2,  needs checking */
   } else if (firstsync_iter == 3) {
/*Check the next tooth as well so as to be sure */
/* tooth after what we thought was missing, lets make sure this one is short
    * on the first sync, we miss tooth #1, but that's ok as long as we catch it next time
* split this into 2 operations so compiler doesn't call subroutine
*/
temp1 = (tooth_diff_last_2 >> 1); /* 1/2 of last value */
temp1 = temp1 >> 1; /* 1/4th of last value */
temp1 = temp1 >> 1; /* 1/8th of last value MDR ADDED */


temp1 = tooth_diff_last_2 - temp1; /* 7/8ths of long tooth MDR ADDED */


if (tooth_diff_this >= temp1) {
  /* this wasn't really the missing tooth... */
  firstsync_iter = 0;
  return;
}


  firstsync_iter = 4;
  flagbyte4 |= flagbyte4_found_miss;
       set_count = 3;  /* Guessed that this should be 3,  needs checking */
    } else if (firstsync_iter == 4) {
        if (tooth_no == 0) { // this should not happen, so reset
            outpc.syncreason = 1;
            ign_reset();  // note that this sequence of setting reason, resetting ign and incrementing counter is
            return;
    }




            if ((tooth_no == last_tooth) ||
                (((flash4.spk_config & 0xc) == 0xc) && (tooth_no == mid_last_tooth))) {
                /* this means we should have the last tooth here, so check for missing */
                temp1 = tooth_diff_last + (tooth_diff_last >> 1); /* 1.5 * last tooth */


                if (tooth_diff_this <= temp1) {
               firstsync_iter = 0;
                    flagbyte4 &= ~flagbyte4_found_miss;
                    outpc.syncreason = 2;
                    ign_reset();
                    return;
                }


                flagbyte4 |= flagbyte4_found_miss;
                set_count = 0;
            }
        }


        if (tooth_no == 1) {
            /* check to make sure this tooth is < 3/4th's of last tooth*/
            temp1 = (tooth_diff_last >> 1);
            temp1 = temp1 >> 1;
            temp1 = temp1 >> 1; /* Make it 7/8th's not 3/4 MDR ADDED */
            temp1 = tooth_diff_last - temp1;
            if (tooth_diff_this >= temp1) {
                /* lost sync */
                firstsync_iter = 0;
                outpc.syncreason = 5;  /* First tooth failure labelled as 5 */
                ign_reset();
                return;
            }
        }


        if (tooth_no == 2) {
           /* check to make sure this tooth is < 3/4th's of last tooth */
           temp1 = (tooth_diff_last_1 >> 1);
           temp1 = temp1 >> 1;
           temp1 = temp1 >> 1; /* Make it 7/8th's not 3/4 MDR ADDED */
           temp1 = tooth_diff_last_1 - temp1;
           if (tooth_diff_this >= temp1) {
               /* lost sync */
               firstsync_iter = 0;
               outpc.syncreason = 6; /* Check this and label as 6 MDR ADDED */
               ign_reset();
               return;
           }
        }


        if (tooth_no == 3) {
           /* check to make sure this tooth is < 7/8th's of last tooth  */
           temp1 = (tooth_diff_last_2 >> 1);
           temp1 = temp1 >> 1;
           temp1 = temp1 >> 1; /* Make it 7/8th's not 3/4 MDR ADDED */
           temp1 = tooth_diff_last_2 - temp1;
           if (tooth_diff_this >= temp1) {
               /* lost sync */
               firstsync_iter = 0;
               outpc.syncreason = 7; /* Check this and label as 6 MDR ADDED */
               ign_reset();
               return;
           }
        }


    if (flagbyte4 & flagbyte4_found_miss) {


        flagbyte4 &= ~flagbyte4_found_miss;


// found the missing tooth
if ((flash4.spk_config & 0xc) == 0xc) {
   if (!(flagbyte1 & flagbyte1_trig2active) && !(synch & SYNC_SYNCED)) {
goto common_wheel;
   }
}


        synch |= SYNC_SYNCED;


        if (synch & SYNC_FIRST) {
            syncfirst();
        }


        outpc.status1 |= status1_syncok; /* have sync */


if ((flash4.spk_config & 0xc) != 0xc) {
   tooth_no = set_count;
} else {
   if (flagbyte1 & flagbyte1_trig2active) {
tooth_no = set_count;
flagbyte1 &= ~flagbyte1_trig2active;
   } else {
tooth_no += flash4.No_Miss_Teeth;
   }
}
    }
    goto common_wheel;
 
The great thing is that the engine now start "on the button", first time everytime.  I am very excited as it takes my car from being a liability to an actual car.


No comments:

Post a Comment