FreeEMS  0.2.0-SNAPSHOT-282-g9efc524
Macros | Functions | Variables
R18A1-13CrankWith5Cam.c File Reference

Decoder for the Honda R18A1 I4 engine. More...

#include "../inc/freeEMS.h"
#include "../inc/utils.h"
#include "../inc/interrupts.h"
#include "../inc/decoderInterface.h"
Include dependency graph for R18A1-13CrankWith5Cam.c:

Go to the source code of this file.

Macros

#define DECODER_MAX_CODE_TIME   150
#define NUMBER_OF_REAL_EVENTS   26
#define NUMBER_OF_VIRTUAL_EVENTS   26
#define DECODER_IMPLEMENTATION_C
#define FIRST_GAP   ANGLE(10)
#define E0   ANGLE( 0)
#define E1   ANGLE( 30)
#define E2   ANGLE( 60)
#define E3   ANGLE( 90)
#define E4   ANGLE(120)
#define E5   ANGLE(150)
#define E6   ANGLE(180)
#define E7   ANGLE(210)
#define E8   ANGLE(240)
#define E9   ANGLE(270)
#define E10   ANGLE(300)
#define E11   ANGLE(330)
#define E12   (E11 + FIRST_GAP)
#define E13   ANGLE(360)
#define E14   ANGLE(390)
#define E15   ANGLE(420)
#define E16   ANGLE(450)
#define E17   ANGLE(480)
#define E18   ANGLE(510)
#define E19   ANGLE(540)
#define E20   ANGLE(570)
#define E21   ANGLE(600)
#define E22   ANGLE(630)
#define E23   ANGLE(660)
#define E24   ANGLE(690)
#define E25   (E24 + FIRST_GAP)

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 [] = {E0, E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12, E13, E14, E15, E16, E17, E18, E19, E20, E21, E22, E23, E24, E25}
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,1,1}

Detailed Description

Decoder for the Honda R18A1 I4 engine.

http://pastebin.com/QMdhE55v

Definition in file R18A1-13CrankWith5Cam.c.

Macro Definition Documentation

#define DECODER_MAX_CODE_TIME   150

Definition at line 38 of file R18A1-13CrankWith5Cam.c.

#define NUMBER_OF_REAL_EVENTS   26

Definition at line 39 of file R18A1-13CrankWith5Cam.c.

#define NUMBER_OF_VIRTUAL_EVENTS   26

Definition at line 40 of file R18A1-13CrankWith5Cam.c.

#define DECODER_IMPLEMENTATION_C

Definition at line 41 of file R18A1-13CrankWith5Cam.c.

#define FIRST_GAP   ANGLE(10)

Definition at line 52 of file R18A1-13CrankWith5Cam.c.

#define E0   ANGLE( 0)

Definition at line 54 of file R18A1-13CrankWith5Cam.c.

#define E1   ANGLE( 30)

Definition at line 55 of file R18A1-13CrankWith5Cam.c.

#define E2   ANGLE( 60)

Definition at line 56 of file R18A1-13CrankWith5Cam.c.

#define E3   ANGLE( 90)

Definition at line 57 of file R18A1-13CrankWith5Cam.c.

#define E4   ANGLE(120)

Definition at line 58 of file R18A1-13CrankWith5Cam.c.

#define E5   ANGLE(150)

Definition at line 59 of file R18A1-13CrankWith5Cam.c.

#define E6   ANGLE(180)

Definition at line 60 of file R18A1-13CrankWith5Cam.c.

#define E7   ANGLE(210)

Definition at line 61 of file R18A1-13CrankWith5Cam.c.

#define E8   ANGLE(240)

Definition at line 62 of file R18A1-13CrankWith5Cam.c.

#define E9   ANGLE(270)

Definition at line 63 of file R18A1-13CrankWith5Cam.c.

#define E10   ANGLE(300)

Definition at line 64 of file R18A1-13CrankWith5Cam.c.

#define E11   ANGLE(330)

Definition at line 65 of file R18A1-13CrankWith5Cam.c.

#define E12   (E11 + FIRST_GAP)

Definition at line 66 of file R18A1-13CrankWith5Cam.c.

#define E13   ANGLE(360)

Definition at line 67 of file R18A1-13CrankWith5Cam.c.

#define E14   ANGLE(390)

Definition at line 68 of file R18A1-13CrankWith5Cam.c.

#define E15   ANGLE(420)

Definition at line 69 of file R18A1-13CrankWith5Cam.c.

#define E16   ANGLE(450)

Definition at line 70 of file R18A1-13CrankWith5Cam.c.

#define E17   ANGLE(480)

Definition at line 71 of file R18A1-13CrankWith5Cam.c.

#define E18   ANGLE(510)

Definition at line 72 of file R18A1-13CrankWith5Cam.c.

#define E19   ANGLE(540)

Definition at line 73 of file R18A1-13CrankWith5Cam.c.

#define E20   ANGLE(570)

Definition at line 74 of file R18A1-13CrankWith5Cam.c.

#define E21   ANGLE(600)

Definition at line 75 of file R18A1-13CrankWith5Cam.c.

#define E22   ANGLE(630)

Definition at line 76 of file R18A1-13CrankWith5Cam.c.

#define E23   ANGLE(660)

Definition at line 77 of file R18A1-13CrankWith5Cam.c.

#define E24   ANGLE(690)

Definition at line 78 of file R18A1-13CrankWith5Cam.c.

#define E25   (E24 + FIRST_GAP)

Definition at line 79 of file R18A1-13CrankWith5Cam.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 93 of file R18A1-13CrankWith5Cam.c.

References TCTL4, TIE, and TIOS.

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

Definition at line 98 of file R18A1-13CrankWith5Cam.c.

References BIT2, camTeethSeen, crankTeethSinceLastCamTooth, previousCrankTeethSeen, and TCTL4.

{
// Re-enable secondary interrupt so we can sync again!
TCTL4 |= BIT2;
}
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 108 of file R18A1-13CrankWith5Cam.c.

References decoderSetting::accelerationInputEventTimeTolerance, ADCBuffers, BIT0, CALC_FUEL_IGN, CAM_SYNC, CLEAR_BENCH_TEST_ON, Clocks, coreStatusA, CoreVars, Counters, KeyUserDebug::currentEvent, DEBUG_TURN_PIN_OFF, DEBUG_TURN_PIN_ON, decoderSetting::decelerationInputEventTimeTolerance, DECODER_BENCHMARKS, KeyUserDebug::decoderFlags, decoderMaxCodeTime, fixedConfig2::decoderSettings, edgeTimeStamp, eventAngles, fixedConfigs2, KeyUserDebug::inputEventTimeTolerance, KeyUserDebugs, LAST_PERIOD_VALID, LAST_TIMESTAMP_VALID, lastPrimaryEventTimeStamp, lastPrimaryTicksPerDegree, NBIT0, numberOfRealEvents, outputEventDelayFinalPeriod, outputEventInputEventNumbers, outputEventPulseWidthsMath, PORTB, PRIMARY_EVENT_ARRIVED_TOO_EARLY, PRIMARY_EVENT_ARRIVED_TOO_LATE, KeyUserDebug::primaryTeethSeen, PTIT, resetToNonRunningState(), CoreVar::RPM, sampleEachADC(), schedulePortTPin(), SHORTMAX, Counter::syncedADCreadings, TC0, TEST_MODE_DODGY_MISSING_TOOTH, TEST_MODE_ITERATIONS, TEST_MODE_REVOLUTIONS, TEST_MODE_TIME_UNITS_HOURS, TEST_MODE_TIME_UNITS_MINUTES, TEST_MODE_TIME_UNITS_SECONDS, testEventsPerCycle, testMode, testNumberOfCycles, testNumberOfMissing, testTicksPerEvent, TFLG, TFLGOF, ticks_per_degree_multiplier, ticksPerDegreeRecord, TIE, LongTime::timeLong, Clock::timeoutADCreadingClock, timerExtensionClock, LongTime::timeShorts, timeStamp, totalEventAngleRange, and KeyUserDebug::zsp7.

{
/* 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 long thisInterEventPeriod = 0;
thisInterEventPeriod = thisEventTimeStamp - lastPrimaryEventTimeStamp;
KeyUserDebugs.zsp7 = (unsigned short)thisInterEventPeriod; // Could truncate if under ~100rpm TODO DEBUG REMOVE
}
unsigned short thisTicksPerDegree = 0;
unsigned char lastEvent = KeyUserDebugs.currentEvent;
}
unsigned short thisAngle = 0;
thisAngle = eventAngles[KeyUserDebugs.currentEvent] + totalEventAngleRange - eventAngles[lastEvent] ; // Optimisable... leave readable for now! :-p J/K learn from this...
}else{
}
thisTicksPerDegree = (unsigned short)((ticks_per_degree_multiplier * thisInterEventPeriod) / thisAngle); // with current scale range for 60/12000rpm is largest ticks per degree = 3472, smallest = 17 with largish error
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
}
}
}
lastPrimaryTicksPerDegree = thisTicksPerDegree;
}
/*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();
}
// 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 205 of file R18A1-13CrankWith5Cam.c.

References BIT0, BIT1, 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, edgeTimeStamp, KeyUserDebugs, LAST_TIMESTAMP_VALID, lastSecondaryEventTimeStamp, NBIT0, NBIT1, NBIT2, numberOfRealEvents, OK_TO_SCHEDULE, PORTB, previousCrankTeethSeen, KeyUserDebug::primaryTeethSeen, resetToNonRunningState(), KeyUserDebug::secondaryTeethSeen, SET_SYNC_LEVEL_TO, STATE_MISMATCH_IN_SECONDARY_RPM_ISR, TC1, TCTL4, TFLG, TFLGOF, LongTime::timeLong, timerExtensionClock, LongTime::timeShorts, and timeStamp.

Here is the call graph for this function:

Variable Documentation

unsigned char camTeethSeen = 0

Definition at line 48 of file R18A1-13CrankWith5Cam.c.

unsigned char previousCrankTeethSeen = 0

Definition at line 49 of file R18A1-13CrankWith5Cam.c.

unsigned char crankTeethSinceLastCamTooth = 0

Definition at line 50 of file R18A1-13CrankWith5Cam.c.

const unsigned short eventAngles[] = {E0, E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12, E13, E14, E15, E16, E17, E18, E19, E20, E21, E22, E23, E24, E25}

Definition at line 90 of file R18A1-13CrankWith5Cam.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,1,1}

Definition at line 91 of file R18A1-13CrankWith5Cam.c.