Speeduino
Loading...
Searching...
No Matches
schedule_calcs.hpp
Go to the documentation of this file.
1// Note that all functions with an underscore prefix are NOT part
2// of the public API. They are only here so we can inline them.
3
4#include "scheduler.h"
5#include "crankMaths.h"
6#include "maths.h"
7#include "timers.h"
8
10{
11 // 0<=injAngle<=720°
12 // 0<=injChannelDegrees<=720°
13 // 0<pwDegrees<=??? (could be many crank rotations in the worst case!)
14 // 45<=CRANK_ANGLE_MAX_INJ<=720
15 // (CRANK_ANGLE_MAX_INJ can be as small as 360/nCylinders. E.g. 45° for 8 cylinder)
16
18 // Avoid underflow
20 // Guaranteed to be >=0.
22 // Clamp to 0<=startAngle<=CRANK_ANGLE_MAX_INJ
24
25 return startAngle;
26}
27
30 if (delta<0)
31 {
32 if ((schedule.Status == RUNNING) && (delta>-CRANK_ANGLE_MAX_INJ))
33 {
34 // Guaranteed to be >0
36 }
37 else
38 {
39 return 0;
40 }
41 }
42
44}
45
46static inline int _adjustToInjChannel(int angle, int channelInjDegrees) {
48 if( angle < 0) { return angle + CRANK_ANGLE_MAX_INJ; }
49 return angle;
50}
51
59
67
75
78 if (delta<0)
79 {
80 if ((schedule.Status == RUNNING) && (delta>-CRANK_ANGLE_MAX_IGN))
81 {
82 // Msut be >0
84 }
85 else
86 {
87 return 0;
88 }
89 }
91}
92
95 if( angle < 0) { return angle + CRANK_ANGLE_MAX_IGN; }
96 return angle;
97}
98
106
107#define MIN_CYCLES_FOR_ENDCOMPARE 6
108
110 if( (schedule.Status == RUNNING) ) {
112 }
113 else if(currentStatus.startRevolutions > MIN_CYCLES_FOR_ENDCOMPARE) {
115 schedule.endScheduleSetByDecoder = true;
116 }
117}
integerPID_ideal boostPID & currentStatus
Definition auxiliaries.cpp:77
uint32_t angleToTimeMicroSecPerDegree(uint16_t angle)
Definition crankMaths.cpp:35
static int16_t ignitionLimits(int16_t angle)
Makes one pass at nudging the angle to within [0,CRANK_ANGLE_MAX_IGN].
Definition crankMaths.h:13
int CRANK_ANGLE_MAX_IGN
Definition globals.cpp:133
int CRANK_ANGLE_MAX_INJ
The number of crank degrees that the system track over. Typically 720 divided by the number of squirt...
Definition globals.cpp:134
static uint32_t rshift(uint32_t a)
Bitwise right shift - generic, unoptimized, case.
Definition bit_shifts.h:349
page_iterator_t advance(const page_iterator_t &it)
Definition pages.cpp:450
static uint32_t calculateInjectorTimeout(const FuelSchedule &schedule, int channelInjDegrees, int openAngle, int crankAngle)
Definition schedule_calcs.hpp:52
static uint16_t _adjustToIgnChannel(int angle, int channelInjDegrees)
Definition schedule_calcs.hpp:93
static void calculateIgnitionAngle(const uint16_t dwellAngle, const uint16_t channelIgnDegrees, int8_t advance, int *pEndAngle, int *pStartAngle)
Definition schedule_calcs.hpp:60
void adjustCrankAngle(IgnitionSchedule &schedule, int endAngle, int crankAngle)
Definition schedule_calcs.hpp:109
static void calculateIgnitionTrailingRotary(uint16_t dwellAngle, int rotarySplitDegrees, int leadIgnitionAngle, int *pEndAngle, int *pStartAngle)
Definition schedule_calcs.hpp:68
static uint32_t calculateIgnitionTimeout(const IgnitionSchedule &schedule, int startAngle, int channelIgnDegrees, int crankAngle)
Definition schedule_calcs.hpp:99
#define MIN_CYCLES_FOR_ENDCOMPARE
Definition schedule_calcs.hpp:107
static uint16_t calculateInjectorStartAngle(uint16_t pwDegrees, int16_t injChannelDegrees, uint16_t injAngle)
Definition schedule_calcs.hpp:9
static uint32_t _calculateInjectorTimeout(const FuelSchedule &schedule, uint16_t openAngle, uint16_t crankAngle)
Definition schedule_calcs.hpp:28
static uint32_t _calculateIgnitionTimeout(const IgnitionSchedule &schedule, int16_t startAngle, int16_t crankAngle)
Definition schedule_calcs.hpp:76
static int _adjustToInjChannel(int angle, int channelInjDegrees)
Definition schedule_calcs.hpp:46
@ RUNNING
Definition scheduler.h:110
Definition scheduler.h:167
Definition scheduler.h:114
#define SET_COMPARE(compare, value)
Definition timers.h:24