#include "inc/freeEMS.h"
#include "inc/interrupts.h"
Go to the source code of this file.
Functions | |
void | PrimaryRPMISR (void) |
void | SecondaryRPMISR (void) |
Use the rising and falling edges................... |
Definition in file MissingTeeth.c.
void PrimaryRPMISR | ( | void | ) |
Primary RPM ISR
Definition at line 46 of file MissingTeeth.c.
References Counters, ISRLatencyVars, PORTJ, PORTP, ISRLatencyVar::primaryInputLatency, RuntimeVar::primaryInputLeadingRuntime, RuntimeVar::primaryInputTrailingRuntime, primaryPulsesPerSecondaryPulse, Counter::primaryTeethSeen, PTIT, RuntimeVars, TC0, TCNT, TFLG, TFLGOF, LongTime::timeLong, timerExtensionClock, and LongTime::timeShorts.
00046 { 00047 static LongTime thisHighLowTime = { 0 }; 00048 static LongTime lastHighLowTime = { 0 }; 00049 static LongTime lowTime = { 0 }; 00050 static LongTime lastPeriod = { 0 }; 00051 static LongTime lastTimeStamp = { 0 }; 00052 static unsigned int count = 0; 00053 00054 /* Clear the interrupt flag for this input compare channel */ 00055 TFLG = 0x01; 00056 00057 /* Save all relevant available data here */ 00058 unsigned short codeStartTimeStamp = TCNT; /* Save the current timer count */ 00059 unsigned short edgeTimeStamp = TC0; /* Save the edge time stamp */ 00060 unsigned char PTITCurrentState = PTIT; /* Save the values on port T regardless of the state of DDRT */ 00061 // unsigned short PORTS_BACurrentState = PORTS_BA; /* Save ignition output state */ 00062 00063 /* Calculate the latency in ticks */ 00064 ISRLatencyVars.primaryInputLatency = codeStartTimeStamp - edgeTimeStamp; 00065 00066 LongTime thisTimeStamp; 00067 /* Install the low word */ 00068 thisTimeStamp.timeShorts[1] = edgeTimeStamp; 00069 /* Find out what our timer value means and put it in the high word */ 00070 if (TFLGOF && !(edgeTimeStamp & 0x8000)) { /* see 10.3.5 paragraph 4 of 68hc11 ref manual for details */ 00071 thisTimeStamp.timeShorts[0] = timerExtensionClock + 1; 00072 } else { 00073 thisTimeStamp.timeShorts[0] = timerExtensionClock; 00074 } 00075 00076 /* How many ticks between transitions? */ 00077 LongTime thisPeriod; 00078 if (thisTimeStamp.timeLong > lastTimeStamp.timeLong) { 00079 thisPeriod.timeLong = thisTimeStamp.timeLong - lastTimeStamp.timeLong; 00080 } else { 00081 thisPeriod.timeLong = thisTimeStamp.timeLong + (0xFFFFFFFF 00082 - lastTimeStamp.timeLong); 00083 } 00084 lastTimeStamp.timeLong = thisTimeStamp.timeLong; 00085 00086 /* Set up edges as per config */ 00087 unsigned char risingEdge = PTITCurrentState & 0x01; 00088 00089 if (lastPeriod.timeLong != 0) { 00090 if (risingEdge) { 00091 thisHighLowTime.timeLong = thisPeriod.timeLong + lowTime.timeLong; 00092 //Find the missing tooth 00093 if (count == 0 || count == 70) { 00094 if (thisHighLowTime.timeLong > (lastHighLowTime.timeLong + (lastHighLowTime.timeLong>>1)) && 00095 thisHighLowTime.timeLong < ((lastHighLowTime.timeLong<<1) + (lastHighLowTime.timeLong>>1))) { 00096 // We have sync 00097 PORTP |= 0x80; 00098 count = 1; 00099 } else { 00100 //We have lost sync 00101 count = 0; 00102 PORTP &= 0x7F; 00103 } 00104 }else if (count == 2 || (count%2 == 0 && 00105 thisHighLowTime.timeLong > (lastHighLowTime.timeLong>>1) && 00106 thisHighLowTime.timeLong < (lastHighLowTime.timeLong<<1) )) { 00107 count++; 00108 } else { 00109 //We have lost sync 00110 count = 0; 00111 PORTP &= 0x7F; 00112 } 00113 00114 /* Echo input condition on J7 */ 00115 PORTJ |= 0x80; 00116 // increment crank pulses TODO this needs to be wrapped in tooth period and width checking 00117 lastHighLowTime.timeLong = thisHighLowTime.timeLong; 00118 primaryPulsesPerSecondaryPulse++; 00119 RuntimeVars.primaryInputLeadingRuntime = TCNT - codeStartTimeStamp; 00120 } else { 00121 if (count%2 == 1) { 00122 count++; 00123 } else { 00124 //We have lost sync 00125 count = 0; 00126 PORTP &= 0x7F; 00127 } 00128 /* Echo input condition on J7 */ 00129 PORTJ &= 0x7F; 00130 RuntimeVars.primaryInputTrailingRuntime = TCNT - codeStartTimeStamp; 00131 lowTime.timeLong = thisPeriod.timeLong; 00132 } 00133 } 00134 lastPeriod.timeLong = thisPeriod.timeLong; 00135 Counters.primaryTeethSeen++; 00136 }
void SecondaryRPMISR | ( | void | ) |
Use the rising and falling edges...................
Secondary RPM ISR
Definition at line 143 of file MissingTeeth.c.
References fixedConfig1::coreSettingsA, Counters, fixedConfigs1, ISRLatencyVars, PORTJ, PTIT, RuntimeVars, SECONDARY_POLARITY, ISRLatencyVar::secondaryInputLatency, RuntimeVar::secondaryInputLeadingRuntime, RuntimeVar::secondaryInputTrailingRuntime, Counter::secondaryTeethSeen, TC1, TCNT, TFLG, TFLGOF, timerExtensionClock, and LongTime::timeShorts.
00143 { 00144 /* Clear the interrupt flag for this input compare channel */ 00145 TFLG = 0x02; 00146 00147 /* Save all relevant available data here */ 00148 unsigned short codeStartTimeStamp = TCNT; /* Save the current timer count */ 00149 unsigned short edgeTimeStamp = TC1; /* Save the timestamp */ 00150 unsigned char PTITCurrentState = PTIT; /* Save the values on port T regardless of the state of DDRT */ 00151 // unsigned short PORTS_BACurrentState = PORTS_BA; /* Save ignition output state */ 00152 00153 /* Calculate the latency in ticks */ 00154 ISRLatencyVars.secondaryInputLatency = codeStartTimeStamp - edgeTimeStamp; 00155 00156 // TODO discard narrow ones! test for tooth width and tooth period 00157 00158 /* Set up edges as per config */ 00159 unsigned char risingEdge; 00160 if (fixedConfigs1.coreSettingsA & SECONDARY_POLARITY) { 00161 risingEdge = PTITCurrentState & 0x02; 00162 } else { 00163 risingEdge = !(PTITCurrentState & 0x02); 00164 } 00165 00166 if (risingEdge) { 00167 // echo input condition 00168 PORTJ |= 0x40; 00169 00170 LongTime timeStamp; 00171 00172 /* Install the low word */ 00173 timeStamp.timeShorts[1] = edgeTimeStamp; 00174 /* Find out what our timer value means and put it in the high word */ 00175 if (TFLGOF && !(edgeTimeStamp & 0x8000)) { /* see 10.3.5 paragraph 4 of 68hc11 ref manual for details */ 00176 timeStamp.timeShorts[0] = timerExtensionClock + 1; 00177 } else { 00178 timeStamp.timeShorts[0] = timerExtensionClock; 00179 } 00180 00181 RuntimeVars.secondaryInputLeadingRuntime = TCNT - codeStartTimeStamp; 00182 } else { 00183 PORTJ &= 0xBF; 00184 RuntimeVars.secondaryInputTrailingRuntime = TCNT - codeStartTimeStamp; 00185 } 00186 00187 Counters.secondaryTeethSeen++; 00188 }