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{
29
30 if (delta<0)
31 {
32 if (schedule.Status != PENDING)
33 {
34 while(delta < 0) { delta += CRANK_ANGLE_MAX_INJ; }
35 }
36 else
37 {
38 delta = 0;
39 }
40 }
42}
43
51
59
61{
63 if (delta < 0)
64 {
66 {
67 // Must be >0
69 }
70 else
71 {
72 return 0U;
73 }
74 }
75
77}
78
80{
82 if( angle < 0) { return angle + CRANK_ANGLE_MAX_IGN; }
83 return angle;
84}
85
94
95#define MIN_CYCLES_FOR_ENDCOMPARE 6
96
98{
99 if( isRunning(schedule) ) {
101 }
102 else if(currentStatus.startRevolutions > UINT32_C(MIN_CYCLES_FOR_ENDCOMPARE)) {
104 schedule.endScheduleSetByDecoder = true;
105 } else {
106 // Nothing to do
107 }
108}
integerPID_ideal boostPID & currentStatus
Definition auxiliaries.cpp:81
#define uS_TO_TIMER_COMPARE(uS1)
Definition board_avr2560.h:127
uint32_t angleToTimeMicroSecPerDegree(uint16_t angle)
Definition crankMaths.cpp:36
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:102
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:103
static TIntegral readSerialIntegralTimeout(void)
Reads an integral type, timing out if necessary.
Definition comms.cpp:173
page_iterator_t advance(const page_iterator_t &it)
Definition pages.cpp:449
static uint16_t _adjustToIgnChannel(int angle, int channelInjDegrees)
Definition schedule_calcs.hpp:79
static void calculateIgnitionAngle(const uint16_t dwellAngle, const uint16_t channelIgnDegrees, int8_t advance, int *pEndAngle, int *pStartAngle)
Definition schedule_calcs.hpp:44
static void calculateIgnitionTrailingRotary(uint16_t dwellAngle, int rotarySplitDegrees, int leadIgnitionAngle, int *pEndAngle, int *pStartAngle)
Definition schedule_calcs.hpp:52
static uint32_t calculateIgnitionTimeout(const IgnitionSchedule &schedule, int startAngle, int channelIgnDegrees, int crankAngle)
Definition schedule_calcs.hpp:86
#define MIN_CYCLES_FOR_ENDCOMPARE
Definition schedule_calcs.hpp:95
static uint16_t calculateInjectorStartAngle(uint16_t pwDegrees, int16_t injChannelDegrees, uint16_t injAngle)
Definition schedule_calcs.hpp:9
static void adjustCrankAngle(IgnitionSchedule &schedule, int endAngle, int crankAngle)
Definition schedule_calcs.hpp:97
static uint32_t _calculateIgnitionTimeout(const IgnitionSchedule &schedule, int16_t startAngle, int16_t crankAngle)
Definition schedule_calcs.hpp:60
static uint32_t calculateInjectorTimeout(const FuelSchedule &schedule, int openAngle, int crankAngle)
Definition schedule_calcs.hpp:26
static bool isRunning(const Schedule &schedule)
Is the schedule action currently running?
Definition scheduler.h:190
@ PENDING
Definition scheduler.h:124
Definition scheduler.h:245
Definition scheduler.h:219
#define SET_COMPARE(compare, value)
Definition timers.h:24