speeduino/speeduino/decoders.h

85 lines
5.0 KiB
C
Raw Normal View History

2016-10-25 16:21:46 -07:00
#ifndef DECODERS_H
#define DECODERS_H
2017-04-20 23:33:24 -07:00
#if defined(CORE_AVR)
2017-06-15 15:45:39 -07:00
#define READ_PRI_TRIGGER() ((*triggerPri_pin_port & triggerPri_pin_mask) ? true : false)
#define READ_SEC_TRIGGER() ((*triggerSec_pin_port & triggerSec_pin_mask) ? true : false)
2018-07-21 07:17:08 -07:00
#else
2017-04-20 23:33:24 -07:00
#define READ_PRI_TRIGGER() digitalRead(pinTrigger)
#define READ_SEC_TRIGGER() digitalRead(pinTrigger2)
#endif
static inline void addToothLogEntry(unsigned long);
static inline uint16_t stdGetRPM(uint16_t degreesOver);
static inline void setFilter(unsigned long);
static inline int crankingGetRPM(byte);
static inline void doPerToothTiming(uint16_t crankAngle);
2016-10-25 16:21:46 -07:00
void triggerSetup_missingTooth();
void triggerPri_missingTooth();
void triggerSec_missingTooth();
2017-06-15 15:45:39 -07:00
uint16_t getRPM_missingTooth();
int getCrankAngle_missingTooth();
2016-10-25 16:21:46 -07:00
void triggerSetup_DualWheel();
void triggerPri_DualWheel();
void triggerSec_DualWheel();
2017-06-15 15:45:39 -07:00
uint16_t getRPM_DualWheel();
int getCrankAngle_DualWheel();
2016-10-25 16:21:46 -07:00
unsigned long MAX_STALL_TIME = 500000UL; //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.
2016-10-25 16:21:46 -07:00
2015-05-16 04:06:54 -07:00
volatile unsigned long curTime;
volatile unsigned long curGap;
2015-09-07 23:46:42 -07:00
volatile unsigned long curTime2;
volatile unsigned long curGap2;
volatile unsigned long lastGap;
volatile unsigned long targetGap;
2015-05-16 04:06:54 -07:00
volatile int toothCurrentCount = 0; //The current number of teeth (Onec sync has been achieved, this can never actually be 0
2015-12-14 21:06:42 -08:00
volatile byte toothSystemCount = 0; //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
volatile unsigned long toothSystemLastToothTime = 0; //As below, but used for decoders where not every tooth count is used for calculation
2015-05-16 04:06:54 -07:00
volatile unsigned long toothLastToothTime = 0; //The time (micros()) that the last tooth was registered
2015-09-07 23:46:42 -07:00
volatile unsigned long toothLastSecToothTime = 0; //The time (micros()) that the last tooth was registered on the secondary input
2015-05-16 04:06:54 -07:00
volatile unsigned long toothLastMinusOneToothTime = 0; //The time (micros()) that the tooth before the last tooth was registered
#ifndef SMALL_FLASH_MODE
volatile unsigned long toothLastMinusOneSecToothTime = 0; //The time (micros()) that the tooth before the last tooth was registered on secondary input
volatile unsigned long targetGap2;
#endif
2015-05-16 04:06:54 -07:00
volatile unsigned long toothOneTime = 0; //The time (micros()) that tooth 1 last triggered
volatile unsigned long toothOneMinusOneTime = 0; //The 2nd to last time (micros()) that tooth 1 last triggered
volatile bool revolutionOne = 0; // For sequential operation, this tracks whether the current revolution is 1 or 2 (not 1)
2015-05-16 04:06:54 -07:00
volatile unsigned int secondaryToothCount; //Used for identifying the current secondary (Usually cam) tooth for patterns with multiple secondary teeth
2015-07-12 03:34:59 -07:00
volatile unsigned long secondaryLastToothTime = 0; //The time (micros()) that the last tooth was registered (Cam input)
volatile unsigned long secondaryLastToothTime1 = 0; //The time (micros()) that the last tooth was registered (Cam input)
2015-07-12 03:34:59 -07:00
2015-05-16 04:06:54 -07:00
volatile int triggerActualTeeth;
2015-09-13 04:16:30 -07:00
volatile unsigned long triggerFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering)
2017-06-15 15:45:39 -07:00
unsigned long triggerSecFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) for the secondary input
unsigned int triggerSecFilterTime_duration; // The shortest valid time (in uS) pulse DURATION
2018-01-03 01:48:35 -08:00
volatile uint16_t triggerToothAngle; //The number of crank degrees that elapse per tooth
volatile bool triggerToothAngleIsCorrect = false; //Whether or not the triggerToothAngle variable is currently accurate. Some patterns have times when the triggerToothAngle variable cannot be accurately set.
bool secondDerivEnabled; //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
bool decoderIsSequential; //Whether or not the decoder supports sequential operation
bool decoderIsLowRes = false; //Is set true, certain extra calculations are performed for better timing accuracy
bool decoderHasFixedCrankingTiming = false; //Whether or not the decoder supports fixed cranking timing
2016-11-07 22:04:34 -08:00
byte checkSyncToothCount; //How many teeth must've been seen on this revolution before we try to confirm sync (Useful for missing tooth type decoders)
unsigned long elapsedTime;
unsigned long lastCrankAngleCalc;
2015-07-12 03:34:59 -07:00
int16_t ignition1EndTooth = 0;
int16_t ignition2EndTooth = 0;
int16_t ignition3EndTooth = 0;
int16_t ignition4EndTooth = 0;
int16_t toothAngles[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
2015-07-12 21:22:05 -07:00
2015-07-12 03:34:59 -07:00
//Used for identifying long and short pulses on the 4G63 (And possibly other) trigger patterns
#define LONG 0;
#define SHORT 1;
2018-06-25 19:17:43 -07:00
#define CRANK_SPEED 0
#define CAM_SPEED 1
2016-10-25 16:21:46 -07:00
#endif