MissingTeeth.c File Reference

Missing teeth, mostly 36-1 and 60-2. More...

#include "inc/freeEMS.h"
#include "inc/interrupts.h"
#include "inc/DecoderInterface.h"
Include dependency graph for MissingTeeth.c:

Go to the source code of this file.

Functions

void PrimaryRPMISR (void)
void SecondaryRPMISR (void)
 Use the rising and falling edges...................

Detailed Description

Missing teeth, mostly 36-1 and 60-2.

Note:
Pseudo code that does not compile with zero warnings and errors MUST be commented out.
Author:
Philip Johnson

Definition in file MissingTeeth.c.


Function Documentation

void PrimaryRPMISR ( void   ) 

Primary RPM ISR

Todo:
TODO Docs here!

Todo:
TODO possibly add code to make sure we are in divide mode, if not error out
Todo:
TODO fill in or remove the else

Definition at line 47 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.

00047                          {
00048     static LongTime thisHighLowTime = { 0 };
00049     static LongTime lastHighLowTime = { 0 };
00050     static LongTime lowTime = { 0 };
00051     static LongTime lastPeriod = { 0 };
00052     static LongTime lastTimeStamp = { 0 };
00053     static unsigned int count = 0;
00054 
00055     /* Clear the interrupt flag for this input compare channel */
00056     TFLG = 0x01;
00057 
00058     /* Save all relevant available data here */
00059     unsigned short codeStartTimeStamp = TCNT; /* Save the current timer count */
00060     unsigned short edgeTimeStamp = TC0; /* Save the edge time stamp */
00061     unsigned char PTITCurrentState = PTIT; /* Save the values on port T regardless of the state of DDRT */
00062     //  unsigned short PORTS_BACurrentState = PORTS_BA; /* Save ignition output state */
00063 
00064     /* Calculate the latency in ticks */
00065     ISRLatencyVars.primaryInputLatency = codeStartTimeStamp - edgeTimeStamp;
00066 
00067     LongTime thisTimeStamp;
00068     /* Install the low word */
00069     thisTimeStamp.timeShorts[1] = edgeTimeStamp;
00070     /* Find out what our timer value means and put it in the high word */
00071     if (TFLGOF && !(edgeTimeStamp & 0x8000)) { /* see 10.3.5 paragraph 4 of 68hc11 ref manual for details */
00072         thisTimeStamp.timeShorts[0] = timerExtensionClock + 1;
00073     } else {
00074         thisTimeStamp.timeShorts[0] = timerExtensionClock;
00075     }
00076 
00077     /* How many ticks between transitions? */
00078     LongTime thisPeriod;
00079     if (thisTimeStamp.timeLong > lastTimeStamp.timeLong) {
00080         thisPeriod.timeLong = thisTimeStamp.timeLong - lastTimeStamp.timeLong;
00081     } else {
00082         thisPeriod.timeLong = thisTimeStamp.timeLong + (0xFFFFFFFF
00083                 - lastTimeStamp.timeLong);
00084     }
00085     lastTimeStamp.timeLong = thisTimeStamp.timeLong;
00086 
00087     /* Set up edges as per config */
00088     unsigned char risingEdge = PTITCurrentState & 0x01;
00089 
00090     if (lastPeriod.timeLong != 0) {
00091         if (risingEdge) {
00092             thisHighLowTime.timeLong = thisPeriod.timeLong + lowTime.timeLong;
00093             //Find the missing tooth
00094             if (count == 0 || count == 70) {
00095                 if (thisHighLowTime.timeLong > (lastHighLowTime.timeLong + (lastHighLowTime.timeLong>>1)) &&
00096                         thisHighLowTime.timeLong < ((lastHighLowTime.timeLong<<1) + (lastHighLowTime.timeLong>>1))) {
00097                     // We have sync
00098                     PORTP |= 0x80;
00099                     count = 1;
00100                 } else {
00101                     //We have lost sync
00102                     count = 0;
00103                     PORTP &= 0x7F;
00104                 }
00105             }else if (count == 2 || (count%2 == 0 &&
00106                     thisHighLowTime.timeLong > (lastHighLowTime.timeLong>>1) &&
00107                     thisHighLowTime.timeLong < (lastHighLowTime.timeLong<<1) )) {
00108                 count++;
00109             } else {
00110                 //We have lost sync
00111                 count = 0;
00112                 PORTP &= 0x7F;
00113             }
00114 
00115             /* Echo input condition on J7 */
00116             PORTJ |= 0x80;
00117             // increment crank pulses TODO this needs to be wrapped in tooth period and width checking
00118             lastHighLowTime.timeLong = thisHighLowTime.timeLong;
00119             primaryPulsesPerSecondaryPulse++;
00120             RuntimeVars.primaryInputLeadingRuntime = TCNT - codeStartTimeStamp;
00121         } else {
00122             if (count%2 == 1) {
00123                 count++;
00124             } else {
00125                 //We have lost sync
00126                 count = 0;
00127                 PORTP &= 0x7F;
00128             }
00129             /* Echo input condition on J7 */
00130             PORTJ &= 0x7F;
00131             RuntimeVars.primaryInputTrailingRuntime = TCNT - codeStartTimeStamp;
00132             lowTime.timeLong = thisPeriod.timeLong;
00133         }
00134     }
00135     lastPeriod.timeLong = thisPeriod.timeLong;
00136     Counters.primaryTeethSeen++;
00137 }

void SecondaryRPMISR ( void   ) 

Use the rising and falling edges...................

Secondary RPM ISR

Todo:
TODO Docs here!

Todo:
TODO fill in or remove the else

Definition at line 144 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.

00144                            {
00145     /* Clear the interrupt flag for this input compare channel */
00146     TFLG = 0x02;
00147 
00148     /* Save all relevant available data here */
00149     unsigned short codeStartTimeStamp = TCNT; /* Save the current timer count */
00150     unsigned short edgeTimeStamp = TC1; /* Save the timestamp */
00151     unsigned char PTITCurrentState = PTIT; /* Save the values on port T regardless of the state of DDRT */
00152     //  unsigned short PORTS_BACurrentState = PORTS_BA; /* Save ignition output state */
00153 
00154     /* Calculate the latency in ticks */
00155     ISRLatencyVars.secondaryInputLatency = codeStartTimeStamp - edgeTimeStamp;
00156 
00157     // TODO discard narrow ones! test for tooth width and tooth period
00158 
00159     /* Set up edges as per config */
00160     unsigned char risingEdge;
00161     if (fixedConfigs1.coreSettingsA & SECONDARY_POLARITY) {
00162         risingEdge = PTITCurrentState & 0x02;
00163     } else {
00164         risingEdge = !(PTITCurrentState & 0x02);
00165     }
00166 
00167     if (risingEdge) {
00168         // echo input condition
00169         PORTJ |= 0x40;
00170 
00171         LongTime timeStamp;
00172 
00173         /* Install the low word */
00174         timeStamp.timeShorts[1] = edgeTimeStamp;
00175         /* Find out what our timer value means and put it in the high word */
00176         if (TFLGOF && !(edgeTimeStamp & 0x8000)) { /* see 10.3.5 paragraph 4 of 68hc11 ref manual for details */
00177             timeStamp.timeShorts[0] = timerExtensionClock + 1;
00178         } else {
00179             timeStamp.timeShorts[0] = timerExtensionClock;
00180         }
00181 
00182         RuntimeVars.secondaryInputLeadingRuntime = TCNT - codeStartTimeStamp;
00183     } else {
00184         PORTJ &= 0xBF;
00185         RuntimeVars.secondaryInputTrailingRuntime = TCNT - codeStartTimeStamp;
00186     }
00187 
00188     Counters.secondaryTeethSeen++;
00189 }

Generated on Sat Oct 16 21:29:19 2010 for FreeEMS by  doxygen 1.6.3