FreeEMS  0.2.0-SNAPSHOT-285-g028e24c
Macros | Functions | Variables
JSeries-12CrankWith6-2Cam.c File Reference

Decoder for the Honda J Series V6 engine, using one cam wheel and the crank wheel. More...

#include "../inc/freeEMS.h"
#include "../inc/utils.h"
#include "../inc/interrupts.h"
#include "../inc/decoderInterface.h"
Include dependency graph for JSeries-12CrankWith6-2Cam.c:

Go to the source code of this file.

Macros

#define DECODER_MAX_CODE_TIME   150
#define NUMBER_OF_REAL_EVENTS   24
#define NUMBER_OF_VIRTUAL_EVENTS   24
#define DECODER_IMPLEMENTATION_C

Functions

void decoderInitPreliminary ()
void perDecoderReset ()
void PrimaryRPMISR ()
 RPM ISRs, IC timer for engine position and RPM.
void SecondaryRPMISR ()
 RPM ISRs, IC timer for engine position and RPM.

Variables

unsigned char camTeethSeen = 0
unsigned char previousCrankTeethSeen = 0
unsigned char crankTeethSinceLastCamTooth = 0
const unsigned short eventAngles []
const unsigned char eventValidForCrankSync [] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}

Detailed Description

Decoder for the Honda J Series V6 engine, using one cam wheel and the crank wheel.

Author
Peter Johnson

Definition in file JSeries-12CrankWith6-2Cam.c.

Macro Definition Documentation

#define DECODER_MAX_CODE_TIME   150

Definition at line 38 of file JSeries-12CrankWith6-2Cam.c.

#define NUMBER_OF_REAL_EVENTS   24

Definition at line 39 of file JSeries-12CrankWith6-2Cam.c.

#define NUMBER_OF_VIRTUAL_EVENTS   24

Definition at line 40 of file JSeries-12CrankWith6-2Cam.c.

#define DECODER_IMPLEMENTATION_C

Definition at line 41 of file JSeries-12CrankWith6-2Cam.c.

Function Documentation

void decoderInitPreliminary ( void  )
Todo:
TODO Perhaps use some of the space freed by shrinking all timing tables for this: /unsigned long wheelEventTimeStamps[numberOfWheelEvents]; // For logging wheel patterns as observed

Definition at line 60 of file JSeries-12CrankWith6-2Cam.c.

References TCTL4.

{
// Set PT0 and PT1 to only capture on rising edges
TCTL4 = 0x05;
}
void perDecoderReset ( void  )
void PrimaryRPMISR ( void  )

RPM ISRs, IC timer for engine position and RPM.

There are multiple copies of this interrupt handler, each is linked with the rest of the code once such that if there are N decoder implementations and/or variants, then there are N loadable binaries produced after a full build.

For details on any specific decoder implementation, see the documentation for that specific file.

Definition at line 72 of file JSeries-12CrankWith6-2Cam.c.

References decoderSetting::accelerationInputEventTimeTolerance, ADCBuffers, BIT0, CALC_FUEL_IGN, CAM_SYNC, Clocks, coreStatusA, COUNT_OF_EVENTS_IMPOSSIBLY_HIGH_NOISE, Counters, KeyUserDebug::currentEvent, DEBUG_TURN_PIN_OFF, DEBUG_TURN_PIN_ON, decoderSetting::decelerationInputEventTimeTolerance, DECODER_BENCHMARKS, KeyUserDebug::decoderFlags, fixedConfig2::decoderSettings, edgeTimeStamp, eventAngles, fixedConfigs2, KeyUserDebug::inputEventTimeTolerance, KeyUserDebugs, LAST_PERIOD_VALID, LAST_TIMESTAMP_VALID, lastPrimaryEventTimeStamp, lastPrimaryTicksPerDegree, NBIT0, numberOfRealEvents, PORTB, PRIMARY_EVENT_ARRIVED_TOO_EARLY, PRIMARY_EVENT_ARRIVED_TOO_LATE, KeyUserDebug::primaryTeethSeen, PTIT, resetToNonRunningState(), sampleEachADC(), Counter::syncedADCreadings, TC0, TFLG, TFLGOF, ticks_per_degree_multiplier, ticksPerDegreeRecord, LongTime::timeLong, Clock::timeoutADCreadingClock, timerExtensionClock, LongTime::timeShorts, and timeStamp.

{
/* Clear the interrupt flag for this input compare channel */
TFLG = 0x01;
/* Save all relevant available data here */
unsigned short edgeTimeStamp = TC0; /* Save the edge time stamp */
unsigned char PTITCurrentState = PTIT; /* Save the values on port T regardless of the state of DDRT */
// Prevent main from clearing values before sync is obtained!
/* Install the low word */
timeStamp.timeShorts[1] = edgeTimeStamp;
/* Find out what our timer value means and put it in the high word */
if(TFLGOF && !(edgeTimeStamp & 0x8000)){ /* see 10.3.5 paragraph 4 of 68hc11 ref manual for details */
timeStamp.timeShorts[0] = timerExtensionClock + 1;
}else{
}
unsigned long thisEventTimeStamp = timeStamp.timeLong;
unsigned short thisTicksPerDegree = 0;
unsigned long thisInterEventPeriod = thisEventTimeStamp - lastPrimaryEventTimeStamp;
thisTicksPerDegree = (unsigned short)((ticks_per_degree_multiplier * thisInterEventPeriod) / eventAngles[1]);
}
}else{
}
return;
}// Can never be greater than without a code error or genuine noise issue, so give it a miss as we can not guarantee where we are now.
unsigned short ratioBetweenThisAndLast = (unsigned short)(((unsigned long)lastPrimaryTicksPerDegree * 1000) / thisTicksPerDegree);
KeyUserDebugs.inputEventTimeTolerance = ratioBetweenThisAndLast;
return;
return;
}else{
if(PTITCurrentState & 0x02){
// TODO Calculate RPM from last primaryLeadingEdgeTimeStamp
}else{
// TODO Calculate RPM from last primaryTrailingEdgeTimeStamp
}
}
}/*else*/ if(KeyUserDebugs.decoderFlags & LAST_TIMESTAMP_VALID){ // TODO temp for testing just do rpm this way, fill above out later.
*ticksPerDegreeRecord = thisTicksPerDegree;
// Set flag to say calc required
// Reset the clock for reading timeout
}
SCHEDULE_ECT_OUTPUTS();
}
OUTPUT_COARSE_BBS();
// do these always at first, and use them with a single 30 degree angle for the first cut
lastPrimaryTicksPerDegree = thisTicksPerDegree;
}
// Always
lastPrimaryEventTimeStamp = thisEventTimeStamp;
}

Here is the call graph for this function:

void SecondaryRPMISR ( void  )

RPM ISRs, IC timer for engine position and RPM.

There are multiple copies of this interrupt handler, each is linked with the rest of the code once such that if there are N decoder implementations and/or variants, then there are N loadable binaries produced after a full build.For details on any specific decoder implementation, see the documentation for that specific file.

Definition at line 160 of file JSeries-12CrankWith6-2Cam.c.

References BIT0, BUG_REACHED_UNREACHABLE_CODE, CAM_SYNC, camTeethSeen, COUNT_OF_EVENTS_IMPOSSIBLY_HIGH_NOISE, COUNT_OF_EVENTS_IMPOSSIBLY_LOW_NOISE, crankTeethSinceLastCamTooth, KeyUserDebug::currentEvent, DEBUG_TURN_PIN_OFF, DEBUG_TURN_PIN_ON, DECODER_BENCHMARKS, KeyUserDebug::decoderFlags, KeyUserDebugs, NBIT0, OK_TO_SCHEDULE, PORTB, previousCrankTeethSeen, KeyUserDebug::primaryTeethSeen, resetToNonRunningState(), KeyUserDebug::secondaryTeethSeen, SET_SYNC_LEVEL_TO, and TFLG.

{
/* Clear the interrupt flag for this input compare channel */
TFLG = 0x02;
// check crankTeethSinceLastCamTooth to see if it's 4 or 12 and if not either of those, lose sync.
return;
}else{
return;
}
}
}
if(camTeethSeen == 0){
}else if(camTeethSeen == 1){
if(crankTeethSinceLastCamTooth == 12){ // 12 Crank teeth in the 2 missing Cam teeth
}else if(crankTeethSinceLastCamTooth != 4){ // 4 Crank teeth in 1 Cam tooth
}else{
}
} // Else fall through and wait for a 12
}else if(camTeethSeen == 2){
}else{
}
} // Else fall through and wait for a 12
}else if(camTeethSeen == 3){
}else{
}
}else{
SET_SYNC_LEVEL_TO(CAM_SYNC); // Set the sync on the eventAngle[12] 360 degrees
}
}else if(camTeethSeen == 4){ // Guaranteed to have already synced
// If this crank teeth seen wasn't a valid number, it would have never made it here, having returned in the block near the top of the ISR
SET_SYNC_LEVEL_TO(CAM_SYNC); // Add sync confirmation point
}else{
}
}
}

Here is the call graph for this function:

Variable Documentation

unsigned char camTeethSeen = 0

Definition at line 48 of file JSeries-12CrankWith6-2Cam.c.

Referenced by perDecoderReset(), and SecondaryRPMISR().

unsigned char previousCrankTeethSeen = 0

Definition at line 49 of file JSeries-12CrankWith6-2Cam.c.

Referenced by perDecoderReset(), and SecondaryRPMISR().

unsigned char crankTeethSinceLastCamTooth = 0

Definition at line 50 of file JSeries-12CrankWith6-2Cam.c.

Referenced by perDecoderReset(), and SecondaryRPMISR().

const unsigned short eventAngles[]
Initial value:
{ANGLE( 0), ANGLE( 30), ANGLE( 60), ANGLE( 90),
ANGLE(120), ANGLE(150), ANGLE(180), ANGLE(210),
ANGLE(240), ANGLE(270), ANGLE(300), ANGLE(330),
ANGLE(360), ANGLE(390), ANGLE(420), ANGLE(450),
ANGLE(480), ANGLE(510), ANGLE(540), ANGLE(570),
ANGLE(600), ANGLE(630), ANGLE(660), ANGLE(690)}

Definition at line 52 of file JSeries-12CrankWith6-2Cam.c.

const unsigned char eventValidForCrankSync[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}

Definition at line 58 of file JSeries-12CrankWith6-2Cam.c.