#define BIT_DECODER_2ND_DERIV 0 //The use of the 2nd derivative calculation is limited to certain decoders. This is set to either true or false in each decoders setup routine
#define BIT_DECODER_IS_SEQUENTIAL 1 //Whether or not the decoder supports sequential operation
#define BIT_DECODER_UNUSED1 2
#define BIT_DECODER_HAS_SECONDARY 3 //Whether or not the decoder supports fixed cranking timing
#define BIT_DECODER_HAS_FIXED_CRANKING 4
#define BIT_DECODER_VALID_TRIGGER 5 //Is set true when the last trigger (Primary or secondary) was valid (ie passed filters)
#define BIT_DECODER_TOOTH_ANG_CORRECT 6 //Whether or not the triggerToothAngle variable is currently accurate. Some patterns have times when the triggerToothAngle variable cannot be accurately set.
//220 bytes free
externvolatileuint8_tdecoderState;
/*
externvolatileboolvalidTrigger;//Is set true when the last trigger (Primary or secondary) was valid (ie passed filters)
externvolatilebooltriggerToothAngleIsCorrect;//Whether or not the triggerToothAngle variable is currently accurate. Some patterns have times when the triggerToothAngle variable cannot be accurately set.
externboolsecondDerivEnabled;//The use of the 2nd derivative calculation is limited to certain decoders. This is set to either true or false in each decoders setup routine
externbooldecoderIsSequential;//Whether or not the decoder supports sequential operation
externbooldecoderHasSecondary;//Whether or not the pattern uses a secondary input
externunsignedlongMAX_STALL_TIME;//The maximum time (in uS) that the system will continue to function before the engine is considered stalled/stopped. This is unique to each decoder, depending on the number of teeth etc. 500000 (half a second) is used as the default value, most decoders will be much less.
externvolatilebytetoothSystemCount;//Used for decoders such as Audi 135 where not every tooth is used for calculating crank angle. This variable stores the actual number of teeth, not the number being used to calculate crank angle
externvolatileunsignedlongtoothSystemLastToothTime;//As below, but used for decoders where not every tooth count is used for calculation
externvolatileunsignedlongtoothLastToothTime;//The time (micros()) that the last tooth was registered
externvolatileunsignedlongtoothLastSecToothTime;//The time (micros()) that the last tooth was registered on the secondary input
externvolatileunsignedlongtoothOneTime;//The time (micros()) that tooth 1 last triggered
externvolatileunsignedlongtoothOneMinusOneTime;//The 2nd to last time (micros()) that tooth 1 last triggered
externvolatileboolrevolutionOne;// For sequential operation, this tracks whether the current revolution is 1 or 2 (not 1)
externvolatileunsignedintsecondaryToothCount;//Used for identifying the current secondary (Usually cam) tooth for patterns with multiple secondary teeth
externvolatileunsignedlongsecondaryLastToothTime;//The time (micros()) that the last tooth was registered (Cam input)
externvolatileunsignedlongsecondaryLastToothTime1;//The time (micros()) that the last tooth was registered (Cam input)
externvolatileunsignedlongtriggerFilterTime;// The shortest time (in uS) that pulses will be accepted (Used for debounce filtering)
externvolatileunsignedlongtriggerSecFilterTime;// The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) for the secondary input
externunsignedinttriggerSecFilterTime_duration;// The shortest valid time (in uS) pulse DURATION
externvolatileuint16_ttriggerToothAngle;//The number of crank degrees that elapse per tooth
externbytecheckSyncToothCount;//How many teeth must've been seen on this revolution before we try to confirm sync (Useful for missing tooth type decoders)
externunsignedlongelapsedTime;
externunsignedlonglastCrankAngleCalc;
externint16_tlastToothCalcAdvance;//Invalid value here forces calculation of this on first main loop
externunsignedlonglastVVTtime;//The time between the vvt reference pulse and the last crank pulse
externint16_ttoothAngles[24];//An array for storing fixed tooth angles. Currently sized at 24 for the GM 24X decoder, but may grow later if there are other decoders that use this style