Speeduino
Loading...
Searching...
No Matches
Classes | Macros | Enumerations | Functions | Variables
scheduler.h File Reference
#include "globals.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  IgnitionSchedule
 
struct  FuelSchedule
 

Macros

#define USE_IGN_REFRESH
 
#define IGNITION_REFRESH_THRESHOLD   30
 
#define DWELL_AVERAGE_ALPHA   30
 
#define DWELL_AVERAGE(input)   LOW_PASS_FILTER((input), DWELL_AVERAGE_ALPHA, currentStatus.actualDwell)
 

Enumerations

enum  ScheduleStatus { OFF , PENDING , STAGED , RUNNING }
 

Functions

void initialiseSchedulers (void)
 
void beginInjectorPriming (void)
 
void disablePendingFuelSchedule (byte channel)
 
void disablePendingIgnSchedule (byte channel)
 
void refreshIgnitionSchedule1 (unsigned long timeToEnd)
 
void _setIgnitionScheduleRunning (IgnitionSchedule &schedule, unsigned long timeout, unsigned long duration)
 
void _setIgnitionScheduleNext (IgnitionSchedule &schedule, unsigned long timeout, unsigned long duration)
 
void setIgnitionSchedule (IgnitionSchedule &schedule, unsigned long timeout, unsigned long duration)
 
void _setFuelScheduleRunning (FuelSchedule &schedule, unsigned long timeout, unsigned long duration)
 
void _setFuelScheduleNext (FuelSchedule &schedule, unsigned long timeout, unsigned long duration)
 
void setFuelSchedule (FuelSchedule &schedule, unsigned long timeout, unsigned long duration)
 

Variables

FuelSchedule fuelSchedule1
 
FuelSchedule fuelSchedule2
 
FuelSchedule fuelSchedule3
 
FuelSchedule fuelSchedule4
 
IgnitionSchedule ignitionSchedule1
 
IgnitionSchedule ignitionSchedule2
 
IgnitionSchedule ignitionSchedule3
 
IgnitionSchedule ignitionSchedule4
 
IgnitionSchedule ignitionSchedule5
 

Detailed Description

Injector and Ignition (on/off) scheduling (structs).

This scheduler is designed to maintain 2 schedules for use by the fuel and ignition systems. It functions by waiting for the overflow vectors from each of the timers in use to overflow, which triggers an interrupt.

Technical

Currently I am prescaling the 16-bit timers to 256 for injection and 64 for ignition. This means that the counter increments every 16us (injection) / 4uS (ignition) and will overflow every 1048576uS.

Max Period = (Prescale)*(1/Frequency)*(2^17)

For more details see https://playground.arduino.cc/Code/Timer1/ (OLD: http://playground.arduino.cc/code/timer1 ). This means that the precision of the scheduler is:

Features

This differs from most other schedulers in that its calls are non-recurring (ie when you schedule an event at a certain time and once it has occurred, it will not reoccur unless you explicitly ask/re-register for it). Each timer can have only 1 callback associated with it at any given time. If you call the setCallback function a 2nd time, the original schedule will be overwritten and not occur.

Timer identification

Arduino timers usage for injection and ignition schedules:

Timers 3,4 and 5 are 16-bit timers (ie count to 65536). See page 136 of the processors datasheet: http://www.atmel.com/Images/doc2549.pdf .

256 prescale gives tick every 16uS. 256 prescale gives overflow every 1048576uS (This means maximum wait time is 1.0485 seconds).

Macro Definition Documentation

◆ DWELL_AVERAGE

#define DWELL_AVERAGE (   input)    LOW_PASS_FILTER((input), DWELL_AVERAGE_ALPHA, currentStatus.actualDwell)

◆ DWELL_AVERAGE_ALPHA

#define DWELL_AVERAGE_ALPHA   30

◆ IGNITION_REFRESH_THRESHOLD

#define IGNITION_REFRESH_THRESHOLD   30

◆ USE_IGN_REFRESH

#define USE_IGN_REFRESH

Enumeration Type Documentation

◆ ScheduleStatus

Schedule statuses.

  • OFF - Schedule turned off and there is no scheduled plan
  • PENDING - There's a scheduled plan, but is has not started to run yet
  • STAGED - (???, Not used)
  • RUNNING - Schedule is currently running
Enumerator
OFF 
PENDING 
STAGED 
RUNNING 

Function Documentation

◆ _setFuelScheduleNext()

void _setFuelScheduleNext ( FuelSchedule schedule,
unsigned long  timeout,
unsigned long  duration 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _setFuelScheduleRunning()

void _setFuelScheduleRunning ( FuelSchedule schedule,
unsigned long  timeout,
unsigned long  duration 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _setIgnitionScheduleNext()

void _setIgnitionScheduleNext ( IgnitionSchedule schedule,
unsigned long  timeout,
unsigned long  duration 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _setIgnitionScheduleRunning()

void _setIgnitionScheduleRunning ( IgnitionSchedule schedule,
unsigned long  timeout,
unsigned long  duration 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginInjectorPriming()

void beginInjectorPriming ( void  )

Perform the injector priming pulses. Set these to run at an arbitrary time in the future (100us). The prime pulse value is in ms*10, so need to multiple by 100 to get to uS

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disablePendingFuelSchedule()

void disablePendingFuelSchedule ( byte  channel)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disablePendingIgnSchedule()

void disablePendingIgnSchedule ( byte  channel)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialiseSchedulers()

void initialiseSchedulers ( void  )

< The number of crank degrees until cylinder 1 is at TDC (This is obviously 0 for virtually ALL engines, but there's some weird ones)

< The number of crank degrees until cylinder 2 (and 5/6/7/8) is at TDC

< The number of crank degrees until cylinder 2 (and 5/6/7/8) is at TDC

< The number of crank degrees until cylinder 2 (and 5/6/7/8) is at TDC

< The number of crank degrees until cylinder 1 is at TDC (This is obviously 0 for virtually ALL engines, but there's some weird ones)

< The number of crank degrees until cylinder 2 (and 5/6/7/8) is at TDC

< The number of crank degrees until cylinder 3 (and 5/6/7/8) is at TDC

< The number of crank degrees until cylinder 4 (and 5/6/7/8) is at TDC

Here is the call graph for this function:
Here is the caller graph for this function:

◆ refreshIgnitionSchedule1()

void refreshIgnitionSchedule1 ( unsigned long  timeToEnd)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFuelSchedule()

void setFuelSchedule ( FuelSchedule schedule,
unsigned long  timeout,
unsigned long  duration 
)
inline
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setIgnitionSchedule()

void setIgnitionSchedule ( IgnitionSchedule schedule,
unsigned long  timeout,
unsigned long  duration 
)
inline
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ fuelSchedule1

FuelSchedule fuelSchedule1
extern

◆ fuelSchedule2

FuelSchedule fuelSchedule2
extern

◆ fuelSchedule3

FuelSchedule fuelSchedule3
extern

◆ fuelSchedule4

FuelSchedule fuelSchedule4
extern

◆ ignitionSchedule1

IgnitionSchedule ignitionSchedule1
extern

◆ ignitionSchedule2

IgnitionSchedule ignitionSchedule2
extern

◆ ignitionSchedule3

IgnitionSchedule ignitionSchedule3
extern

◆ ignitionSchedule4

IgnitionSchedule ignitionSchedule4
extern

◆ ignitionSchedule5

IgnitionSchedule ignitionSchedule5
extern