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
19 while (startAngle<pwDegrees) { startAngle = startAngle + (uint16_t)CRANK_ANGLE_MAX_INJ; } // Avoid underflow
20 startAngle = startAngle - pwDegrees; // startAngle guaranteed to be >=0.
21 while (startAngle>(uint16_t)CRANK_ANGLE_MAX_INJ) { startAngle = startAngle - (uint16_t)CRANK_ANGLE_MAX_INJ; } // Clamp to 0<=startAngle<=CRANK_ANGLE_MAX_INJ
22
23 return startAngle;
24}
25
27{
30
32 else if ( (schedule.Status == RUNNING) || (schedule.Status == OFF))
33 {
34 while(delta < 0) { delta += CRANK_ANGLE_MAX_INJ; }
36 }
37
38 return tempTimeout;
39}
40
48
56
58{
60 if (delta < 0)
61 {
62 if ((schedule.Status == RUNNING) && (delta>-CRANK_ANGLE_MAX_IGN))
63 {
64 // Msut be >0
66 }
67 else
68 {
69 return 0U;
70 }
71 }
72
74}
75
77{
79 if( angle < 0) { return angle + CRANK_ANGLE_MAX_IGN; }
80 return angle;
81}
82
91
92#define MIN_CYCLES_FOR_ENDCOMPARE 6
93
95{
96 if( (schedule.Status == RUNNING) ) {
98 }
99 else if(currentStatus.startRevolutions > MIN_CYCLES_FOR_ENDCOMPARE) {
101 schedule.endScheduleSetByDecoder = true;
102 }
103}
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:129
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:130
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 uint16_t _adjustToIgnChannel(int angle, int channelInjDegrees)
Definition schedule_calcs.hpp:76
static void calculateIgnitionAngle(const uint16_t dwellAngle, const uint16_t channelIgnDegrees, int8_t advance, int *pEndAngle, int *pStartAngle)
Definition schedule_calcs.hpp:41
void adjustCrankAngle(IgnitionSchedule &schedule, int endAngle, int crankAngle)
Definition schedule_calcs.hpp:94
static void calculateIgnitionTrailingRotary(uint16_t dwellAngle, int rotarySplitDegrees, int leadIgnitionAngle, int *pEndAngle, int *pStartAngle)
Definition schedule_calcs.hpp:49
static uint32_t calculateIgnitionTimeout(const IgnitionSchedule &schedule, int startAngle, int channelIgnDegrees, int crankAngle)
Definition schedule_calcs.hpp:83
#define MIN_CYCLES_FOR_ENDCOMPARE
Definition schedule_calcs.hpp:92
static uint16_t calculateInjectorStartAngle(uint16_t pwDegrees, int16_t injChannelDegrees, uint16_t injAngle)
Definition schedule_calcs.hpp:9
static uint32_t _calculateIgnitionTimeout(const IgnitionSchedule &schedule, int16_t startAngle, int16_t crankAngle)
Definition schedule_calcs.hpp:57
static uint32_t calculateInjectorTimeout(const FuelSchedule &schedule, int openAngle, int crankAngle)
Definition schedule_calcs.hpp:26
@ RUNNING
Definition scheduler.h:111
@ OFF
Definition scheduler.h:111
Definition scheduler.h:174
Definition scheduler.h:115
#define SET_COMPARE(compare, value)
Definition timers.h:24