00001 /* FreeEMS - the open source engine management system 00002 00003 Copyright 2009 Fred Cooke 00004 00005 This file is part of the FreeEMS project. 00006 00007 FreeEMS software is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 FreeEMS software is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with any FreeEMS software. If not, see http://www.gnu.org/licenses/ 00019 00020 We ask that if you make any changes to this file you email them upstream to 00021 us at admin(at)diyefi(dot)org or, even better, fork the code on github.com! 00022 00023 Thank you for choosing FreeEMS to run your engine! */ 00024 00025 00041 #define LT1_360_8_C 00042 #include "inc/freeEMS.h" 00043 #include "inc/interrupts.h" 00044 #include "inc/LT1-360-8.h" 00045 00046 00051 void LT1PTInit(void){ 00052 /* set pt1 to capture on rising and falling */ 00053 00054 } 00055 00056 00057 /* set overflow to 8 so that it will fire an interrupt on every 8th tooth, basically making it a 45tooth CAS */ 00062 void PrimaryRPMISR(void){ 00063 /* Clear the interrupt flag for this input compare channel */ 00064 TFLG = 0x01; 00065 00066 /* Save all relevant available data here */ 00067 // unsigned short codeStartTimeStamp = TCNT; /* Save the current timer count */ 00068 // unsigned short edgeTimeStamp = TC0; /* Save the edge time stamp */ 00069 unsigned char PTITCurrentState = PTIT; /* Save the values on port T regardless of the state of DDRT */ 00070 // unsigned short PORTS_BACurrentState = PORTS_BA; /* Save ignition output state */ 00071 00072 // unsigned char risingEdge; /* in LT1s case risingEdge means signal is high */ 00073 // if(fixedConfigs1.coreSettingsA & PRIMARY_POLARITY){ 00074 // risingEdge = PTITCurrentState & 0x01; 00075 // }else{ 00076 // risingEdge = !(PTITCurrentState & 0x01); 00077 // } 00078 00079 PORTJ |= 0x80; /* Echo input condition on J7 */ 00080 if(!isSynced){ /* If the CAS is not in sync get window counts so SecondaryRPMISR can set position */ 00081 if (PTITCurrentState & 0x02){ 00082 PrimaryTeethDuringHigh++; /* if low resolution signal is high count number of pulses */ 00083 }else{ 00084 PrimaryTeethDuringLow++; /* if low resolution signal is low count number of pulses */ 00085 } 00086 }else{ /* The CAS is synced and we need to update our 360/5=72 tooth wheel */ 00088 } 00089 } 00090 00091 00098 void SecondaryRPMISR(void){ 00099 /* Clear the interrupt flag for this input compare channel */ 00100 TFLG = 0x02; 00101 00102 /* Save all relevant available data here */ 00103 // unsigned short codeStartTimeStamp = TCNT; /* Save the current timer count */ 00104 // unsigned short edgeTimeStamp = TC1; /* Save the timestamp */ 00105 unsigned char PTITCurrentState = PTIT; /* Save the values on port T regardless of the state of DDRT */ 00106 // unsigned short PORTS_BACurrentState = PORTS_BA; /* Save ignition output state */ 00107 00108 PORTJ |= 0x40; /* echo input condition */ 00109 if (!isSynced){ /* If the CAS is not in sync get window counts and set virtual CAS position */ 00110 if (PTITCurrentState & 0x02){ /* if signal is high that means we can count the lows */ 00111 switch (PrimaryTeethDuringLow){ 00112 case 23: /* wheel is at 0 deg TDC #1, set our virtual CAS to tooth 0 of 72 */ 00113 { 00114 00115 break; 00116 } 00117 case 38: /* wheel is at 90 deg TDC #4, set our virtual CAS to tooth 18 of 72 */ 00118 { 00119 00120 break; 00121 } 00122 case 33: /* wheel is at 180 deg TDC #6 set our virtual CAS to tooth 36 of 72 */ 00123 { 00124 00125 break; 00126 } 00127 case 28: /* wheel is at 270 deg TDC #7 set our virtual CAS to tooth 54 of 72 */ 00128 { 00129 00130 break; 00131 } 00132 default : 00133 { 00134 Counters.crankSyncLosses++; /* use crankSyncLosses variable to store number of invalid count cases while attempting to sync*/ 00135 break; 00136 } 00137 PrimaryTeethDuringLow = 0; /* In any case reset counter */ 00138 } 00139 }else{ /* if the signal is low that means we can count the highs */ 00140 switch (PrimaryTeethDuringHigh){ 00141 case 7: /* wheel is at 52 deg, 7 deg ATDC #8 set our virtual CAS to tooth 10.4 of 72 */ 00142 { 00143 00144 break; 00145 } 00146 case 12: /* wheel is at 147 deg, 12 deg ATDC #3 set our virtual CAS to tooth 29.4 of 72 */ 00147 { 00148 00149 break; 00150 } 00151 case 17: /* wheel is at 242 deg, 17 deg ATDC #5 set our virtual CAS to tooth 48.4 of 72 */ 00152 { 00153 00154 break; 00155 } 00156 case 22: /* wheel is at 337 deg, 22 deg ATDC #2 set our virtual CAS to tooth 67.4 of 72 */ 00157 { 00158 00159 break; 00160 } 00161 default : 00162 { 00163 Counters.crankSyncLosses++; /* use crankSyncLosses variable to store number of invalid/default count cases while attempting to sync*/ 00164 break; 00165 } 00166 00167 } 00168 PrimaryTeethDuringHigh = 0; /* In any case reset counter */ 00169 } 00170 }else{ /* System is synced so use adjusted count numbers to check sync */ 00172 } 00173 } 00174 // Counter.primaryTeethAfterSecondaryRise = 0; 00175 // Counter.primaryTeethAfterSecondaryFall = 0; 00176 00177 // unsigned char risingEdge; 00178 // if(fixedConfigs1.coreSettingsA & SECONDARY_POLARITY){ 00179 // risingEdge = PTITCurrentState & 0x02; 00180 // }else{ 00181 // risingEdge = !(PTITCurrentState & 0x02); 00182 // } 00183 00188 void changeAccumulatorMode(char mode){ 00189 if (mode == 0){ /* disable accumulator counter, so an ISR is fired on all 360 teeth */ 00190 PACTL = 0x00; /* disable PAEN and PBOIV */ 00191 }else{ /* enable accumulator so an ISR is only fired on every "8th tooth of the 360x track" */ 00192 // TIOS = TIOS & "0xCC0x83" WTF!?LOL!! 0x80; /* PT7 input */ 00193 // TCTL1 = TCTL1 & "0xCC0x83" WTF!?LOL!! 0xC0; /* Disconnect IC/OC logic from PT7 */ 00194 TIOS = TIOS & 0x80; /* PT7 input */ 00195 TCTL1 = TCTL1 & 0xC0; /* Disconnect IC/OC logic from PT7 */ 00197 // PACNT = 0x0005 ; /* set to overflow every 5 inputs on PT7 making our 360 tooth wheel act like a 72 tooth wheel */ 00198 PACTL = 0x52; /* Enable PA in count mode, rising edge and interrupt on overflow 01010010 */ 00199 } 00200 }