- Tue Jan 15, 2019 4:41 pm
#31281
Hi guys,
I'm new to speeduino though have spent a fair while on megasquirt and done a small amount of arduino code before... I'm currently looking at coding in the Rover 36-1-1-1-1 trigger pattern code - detail here - and I think I've got it working fairly robustly (it's entirely possible I'm totally off the mark with it, but it seems to work from an Ardustim!).
Couple of things to note first - I've not yet twigged how to modify the .ini and other required code to make it a selectable option in tunerstudio, and pointers on this would be very helpful! This is why at the moment I've got it down as the subaru 36-2-2-2 code, as this is the decoder that's most similar to what i want so was a sensible base, obviously needs changed in the long run...
If anyone's able to give it a quick skim and give me any pointers (especially on how to make it a separate option!) that would be great.
So far in testing with a stim it seems robust, has sensible error checking for missing tooth found in the wrong place or tooth found where missing tooth expected etc, will be aiming to test it on the car as soon as I can... The RPM reading is a little off on cranking as it tries to work out rpm per-tooth, but that's not really an issue, and certainly something that could be sorted quickly and easily with a getrpm function similar to the missing tooth one, just with more exceptions for the four missing teeth.
Oh and if anyone can tell me what the ' triggerSetEndTeeth' function actually does that would be great - I expect that is something I'll need to change at some point but at the moment I've no idea what it actually does...
I'm new to speeduino though have spent a fair while on megasquirt and done a small amount of arduino code before... I'm currently looking at coding in the Rover 36-1-1-1-1 trigger pattern code - detail here - and I think I've got it working fairly robustly (it's entirely possible I'm totally off the mark with it, but it seems to work from an Ardustim!).
Couple of things to note first - I've not yet twigged how to modify the .ini and other required code to make it a selectable option in tunerstudio, and pointers on this would be very helpful! This is why at the moment I've got it down as the subaru 36-2-2-2 code, as this is the decoder that's most similar to what i want so was a sensible base, obviously needs changed in the long run...
If anyone's able to give it a quick skim and give me any pointers (especially on how to make it a separate option!) that would be great.
So far in testing with a stim it seems robust, has sensible error checking for missing tooth found in the wrong place or tooth found where missing tooth expected etc, will be aiming to test it on the car as soon as I can... The RPM reading is a little off on cranking as it tries to work out rpm per-tooth, but that's not really an issue, and certainly something that could be sorted quickly and easily with a getrpm function similar to the missing tooth one, just with more exceptions for the four missing teeth.
Oh and if anyone can tell me what the ' triggerSetEndTeeth' function actually does that would be great - I expect that is something I'll need to change at some point but at the moment I've no idea what it actually does...
Code: Select all
void triggerSetup_ThirtySixMinus222()
{
triggerToothAngle = 10; //The number of degrees that passes from tooth to tooth
triggerActualTeeth = 32; //The number of physical teeth on the wheel. Doing this here saves us a calculation each time in the interrupt
triggerFilterTime = (int)(1000000 / (MAX_RPM / 60 * configPage4.triggerTeeth)); //Trigger filter time is the shortest possible time (in uS) that there can be between crank teeth (ie at max RPM). Any pulses that occur faster than this time will be disgarded as noise
secondDerivEnabled = false;
decoderIsSequential = false;
checkSyncToothCount = (configPage4.triggerTeeth) >> 1; //50% of the total teeth.
toothLastMinusOneToothTime = 0;
toothCurrentCount = 0;
toothOneTime = 0;
toothOneMinusOneTime = 0;
sinceMiss=4;
MAX_STALL_TIME = (3333UL * triggerToothAngle * 2 ); //Minimum 50rpm. (3333uS is the time per degree at 50rpm)
}
void triggerPri_ThirtySixMinus222()
{
curTime = micros();
curGap = curTime - toothLastToothTime;
if ( curGap >= triggerFilterTime ) //Pulses should never be less than triggerFilterTime, so if they are it means a false trigger. (A 36-1 wheel at 8000pm will have triggers approx. every 200uS)
{
toothCurrentCount++; //Increment the tooth counter
sinceMiss++; //Increment teeth since missing tooth counter
addToothLogEntry(curGap);
//Begin the missing tooth detection
//If the time between the current tooth and the last is greater than 1.5x the time between the last tooth and the tooth before that, we make the assertion that we must be at the first tooth after a gap
{ targetGap = (3 * (toothLastToothTime - toothLastMinusOneToothTime)) >> 1; } //Multiply by 1.5 (Checks for a gap 2x greater than the last one)
if( (toothLastToothTime == 0) || (toothLastMinusOneToothTime == 0) ) { curGap = 0; }
if ( (curGap > targetGap) )
{
if( (currentStatus.hasSync == false) || (toothCurrentCount == 14)|| (toothCurrentCount == 17)|| (toothCurrentCount == 32)|| (toothCurrentCount == 36))
//checks that missing tooth is in the right place (or sync has not yet been found)
{
{
if(sinceMiss == 3)
{
//This occurs when where at the first tooth after the two missing teeth with three teeth between them
toothCurrentCount = 1;
revolutionOne = !revolutionOne; //Flip sequential revolution tracker
toothOneMinusOneTime = toothOneTime;
toothOneTime = curTime;
currentStatus.startRevolutions++; //Counter
currentStatus.hasSync = true;
}
else
{
//We've seen a missing tooth, but it's not the specific one we're looking for for sync
toothCurrentCount++; //Accurately reflect the actual tooth count, including the skipped ones
}
triggerToothAngleIsCorrect = false; //The tooth angle is double at this point
triggerFilterTime = 0; //This is used to prevent a condition where serious intermitent signals (Eg someone furiously plugging the sensor wire in and out) can leave the filter in an unrecoverable state
sinceMiss = 0; //Resets the counter
}
}
else //enters this if missing tooth found at the wrong time
{
currentStatus.hasSync = false;
currentStatus.syncLossCounter++;
}
}
else //enters this code if a normal tooth is found, checks it is not where a missing tooth was expected, if currently in sync
{
if ((currentStatus.hasSync == true) &&( (toothCurrentCount == 14)|| (toothCurrentCount == 17)|| (toothCurrentCount == 32)|| (toothCurrentCount == 36)))
{
currentStatus.hasSync = false;
currentStatus.syncLossCounter++;
}
//Filter can only be recalc'd for the regular teeth, not the missing one.
setFilter(curGap);
triggerToothAngleIsCorrect = true;
}
toothLastMinusOneToothTime = toothLastToothTime;
toothLastToothTime = curTime;
//EXPERIMENTAL!
if(configPage2.perToothIgn == true)
{
uint16_t crankAngle = ( (toothCurrentCount-1) * triggerToothAngle ) + configPage4.triggerAngle;
checkPerToothTiming(crankAngle, toothCurrentCount);
}
}
}
void triggerSec_ThirtySixMinus222()
{
//NOT USED - This pattern uses the missing tooth version of this function
}
int getCrankAngle_ThirtySixMinus222()
{
//NOT USED - This pattern uses the missing tooth version of this function
return 0;
}
void triggerSetEndTeeth_ThirtySixMinus222() //no idea what this means, guess I should work it out at some point
{
if(currentStatus.advance < 10) { ignition1EndTooth = 36; }
else if(currentStatus.advance < 20) { ignition1EndTooth = 35; }
else if(currentStatus.advance < 30) { ignition1EndTooth = 34; }
else { ignition1EndTooth = 31; }
if(currentStatus.advance < 30) { ignition2EndTooth = 16; }
else { ignition2EndTooth = 13; }
lastToothCalcAdvance = currentStatus.advance;
}