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

Go to the source code of this file.

Classes

struct  Schedule
 A schedule for a single output channel. More...
 
struct  IgnitionSchedule
 An ignition schedule. More...
 
struct  FuelSchedule
 

Enumerations

enum  ScheduleStatus { OFF = 0b00000000U , PENDING = 0b00000001U , RUNNING = 0b00000010U , RUNNING_WITHNEXT = 0b00000100U }
 The current state of a schedule. More...
 

Functions

void initialiseFuelSchedulers (void)
 Initialize all schedulers to the OFF state.
 
void startFuelSchedulers (void)
 Start the timers that drive schedulers

 
void stopFuelSchedulers (void)
 Stop the timers that drive schedulers

 
void beginInjectorPriming (void)
 Start fuel system priming the fuel.
 
void nullCallback (void)
 A scheduler callback that does nothing.
 
static bool isRunning (const Schedule &schedule)
 Is the schedule running? I.e. the action has started, but not finished. E.g. injector is open.
 
void setCallbacks (Schedule &schedule, Schedule::callback pStartCallback, Schedule::callback pEndCallback) noexcept
 Set the schedule callbacks. I.e the functions called when the action needs to start & stop.
 
void setSchedule (Schedule &schedule, uint32_t delay, uint16_t duration, bool allowQueuedSchedule)
 Set the schedule action to run for a certain duration in the future.
 
void moveToNextState (IgnitionSchedule &schedule) noexcept
 Shared ignition schedule timer ISR implementation. Should be called by the actual ignition timer ISRs (as timed interrupts) when either the start time or the duration time are reached. See Schedule finite state machine.
 
static void setFuelSchedule (FuelSchedule &schedule, uint32_t delay, uint16_t duration)
 Set the fuel schedule action (open & close an injector) to run for a certain duration in the future.
 
void moveToNextState (FuelSchedule &schedule) noexcept
 Shared fuel schedule timer ISR implementation. Should be called by the actual timer ISRs (as timed interrupts) when either the start time or the duration time are reached. See Schedule finite state machine.
 
void changeHalfToFullSync (const config2 &page2, statuses &current)
 
void changeFullToHalfSync (const config2 &page2, const config4 &page4, statuses &current)
 

Variables

FuelSchedule fuelSchedule1
 
FuelSchedule fuelSchedule2
 
FuelSchedule fuelSchedule3
 
FuelSchedule fuelSchedule4
 

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).

Enumeration Type Documentation

◆ ScheduleStatus

The current state of a schedule.

Enumerator
OFF 

Not running

PENDING 

The delay phase of the schedule is active

RUNNING 

The schedule action is running

RUNNING_WITHNEXT 

The schedule is running, with a next schedule queued up

Function Documentation

◆ beginInjectorPriming()

void beginInjectorPriming ( void  )

Start fuel system priming the fuel.

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:

◆ initialiseFuelSchedulers()

void initialiseFuelSchedulers ( void  )

Initialize all schedulers to the OFF state.

< 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:

◆ isRunning()

static bool isRunning ( const Schedule schedule)
inlinestatic

Is the schedule running? I.e. the action has started, but not finished. E.g. injector is open.

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

◆ nullCallback()

void nullCallback ( void  )

A scheduler callback that does nothing.

Here is the caller graph for this function:

◆ setCallbacks()

void setCallbacks ( Schedule schedule,
Schedule::callback  pStartCallback,
Schedule::callback  pEndCallback 
)
noexcept

Set the schedule callbacks. I.e the functions called when the action needs to start & stop.

Parameters
scheduleSchedule to modify
pStartCallbackThe new start callback - called when the schedule switches to RUNNING status
pEndCallbackThe new end callback - called when the schedule switches from RUNNING to OFF status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFuelSchedule()

static void setFuelSchedule ( FuelSchedule schedule,
uint32_t  delay,
uint16_t  duration 
)
inlinestatic

Set the fuel schedule action (open & close an injector) to run for a certain duration in the future.

Parameters
scheduleSchedule to modify
delayDelay until the injector opens (µS)
durationInjector open time (µS)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSchedule()

void setSchedule ( Schedule schedule,
uint32_t  delay,
uint16_t  duration,
bool  allowQueuedSchedule 
)

Set the schedule action to run for a certain duration in the future.

Parameters
scheduleSchedule to modify
delayDelay until the action starts (µS)
durationAction duration (µS)
allowQueuedScheduletrue to allow a schedule to be queued up if one is currently running; false otherwise
Here is the call graph for this function:
Here is the caller graph for this function:

◆ startFuelSchedulers()

void startFuelSchedulers ( void  )

Start the timers that drive schedulers

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

◆ stopFuelSchedulers()

void stopFuelSchedulers ( void  )

Stop the timers that drive schedulers

Here is the call graph for this function:

Variable Documentation

◆ fuelSchedule1

FuelSchedule fuelSchedule1
extern

◆ fuelSchedule2

FuelSchedule fuelSchedule2
extern

◆ fuelSchedule3

FuelSchedule fuelSchedule3
extern

◆ fuelSchedule4

FuelSchedule fuelSchedule4
extern