speeduino/speeduino/idle.h

80 lines
2.6 KiB
C
Raw Normal View History

#ifndef IDLE_H
#define IDLE_H
2016-04-06 20:28:13 -07:00
#include "globals.h"
Reduce 3d table memory usage (>500 bytes) (#662) * Use table_row_iterator_t to adjust ignitionTable * Separate 2d & 3d table code, abstract page to table iterator conversion. This is just moving code around in preparation for future changes. * Reduce table RAM (.bss) usage Generate a separate type for each possible 3d axis & size combination. This turns what was runtime information into compile time data. * Save 1 byte per table. Use a flag value (INT16_MAX) instead of a separate boolean flag * File renaming table_iterator -> table3d_iterator.h table3d.h -> table3d_interpolate.h table3d.cpp -> table3d_interpolate.cpp table3d_types.h -> table3d.h * Optimize page.cpp: reduce code clutter, maintain performance * Reduce flash usage * Encapsulate table metadata * Performance - hoist if statement * Replace function with macro * Use a packed enum as a type identifier Use a packed enum as a type identifier Slimmer data types * Use table iterators for random access to table values and axis. * Centralize write buffer check * Encapsulate 16-bit reference concept * Performance: make table iterators proper classes This allows us to chain calls on temporaries - not possible with regular function calls. * Performance: encapsulate EEPROM update & address increment * Save flash - don't duplicate function * Performance: directly invalidate table cache * Separate out iterator reversal * Separate out entity mapping & per-byte access Much faster, smaller code footprint & easier to understand * Code quality fixes * Separate out axis metadata * Doxygen comments * Separate int16_ref into separate file * Separate out table axies & values into separate types No need for metadata types & more localised code. E.g. creating iterators is now alongside the data over which they iterate. * Doxygen
2021-11-17 16:30:29 -08:00
#include "table2d.h"
#include BOARD_H //Note that this is not a real file, it is defined in globals.h.
2016-04-06 20:28:13 -07:00
#define IAC_ALGORITHM_NONE 0
#define IAC_ALGORITHM_ONOFF 1
#define IAC_ALGORITHM_PWM_OL 2
#define IAC_ALGORITHM_PWM_CL 3
#define IAC_ALGORITHM_STEP_OL 4
#define IAC_ALGORITHM_STEP_CL 5
Closed loop idle improve (#481) * Squashed commit of the following: commit c73f316fa5bf8c929a8fef5736f4a40045ea992f Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Wed Nov 25 21:53:45 2020 +0100 cleanup and fix merge issues commit 57f1e8c6c73bcfb699b18ac51a2ec646be822f55 Merge: 04478ca 131673d Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Wed Nov 25 18:59:58 2020 +0100 Merge branch 'Closedloop_idle_improvements' into ClosedLoopIdleImprovement commit 131673dc60417cbc773b0763d2f93e917c83325f Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Sun Nov 22 21:54:03 2020 +0100 more fiddeling with idle control commit e4406166cde91552027a0dfb7958d6894098f066 Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Sun Nov 22 20:36:24 2020 +0100 More fiddeling with idle control commit 45822003d41e021e3ed93e8e14ce05479ddfd17b Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Sat Nov 21 14:59:32 2020 +0100 fix initial value commit ff8fadae7844bd8e5934ee0f311fbf5e0842ec29 Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Thu Nov 19 23:14:14 2020 +0100 add TPS limit to prevent integeral windup. commit 7683b2e65569787b1c94eae6f4847cdadd394402 Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Thu Nov 19 22:40:53 2020 +0100 cleanup idle.h commit da55ee9dbd76d65608bfb5b950bc948a498b9599 Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Thu Nov 19 22:36:18 2020 +0100 Further improvement simplifying code for closedloop PID control with feedforward. make PWM output work Tinkering new Idle control working on closedloop idle Initial work on improving closed loop Idle control * reset platformio.ini Co-authored-by: Tjeerd <tjeerdie@users.noreply.github.com>
2020-12-01 13:37:58 -08:00
#define IAC_ALGORITHM_PWM_OLCL 6 //Openloop plus closedloop IAC control
2021-12-08 13:52:56 -08:00
#define IAC_ALGORITHM_STEP_OLCL 7 //Openloop plus closedloop IAC control
2022-01-04 04:23:15 -08:00
#define IDLE_PIN_LOW() *idle_pin_port &= ~(idle_pin_mask)
#define IDLE_PIN_HIGH() *idle_pin_port |= (idle_pin_mask)
#define IDLE2_PIN_LOW() *idle2_pin_port &= ~(idle2_pin_mask)
#define IDLE2_PIN_HIGH() *idle2_pin_port |= (idle2_pin_mask)
2022-01-04 04:23:15 -08:00
#define STEPPER_FORWARD 0
#define STEPPER_BACKWARD 1
#define STEPPER_POWER_WHEN_ACTIVE 0
2015-08-20 06:21:27 -07:00
#define IDLE_TABLE_SIZE 10
2015-05-29 00:33:00 -07:00
enum StepperStatus {SOFF, STEPPING, COOLING}; //The 2 statuses that a stepper can have. STEPPING means that a high pulse is currently being sent and will need to be turned off at some point.
2015-05-29 00:33:00 -07:00
struct StepperIdle
{
int curIdleStep; //Tracks the current location of the stepper
int targetIdleStep; //What the targeted step is
2017-02-28 19:42:24 -08:00
volatile StepperStatus stepperStatus;
volatile unsigned long stepStartTime;
byte lessAirDirection;
byte moreAirDirection;
2015-05-29 00:33:00 -07:00
};
2015-08-20 06:21:27 -07:00
struct table2D iacPWMTable;
struct table2D iacStepTable;
//Open loop tables specifically for cranking
struct table2D iacCrankStepsTable;
struct table2D iacCrankDutyTable;
2015-08-20 21:14:47 -07:00
struct StepperIdle idleStepper;
2015-08-20 06:21:27 -07:00
bool idleOn; //Simply tracks whether idle was on last time around
byte idleInitComplete = 99; //Tracks which idle method was initialised. 99 is a method that will never exist
2019-12-01 19:47:30 -08:00
unsigned int iacStepTime_uS;
2019-12-14 14:57:22 -08:00
unsigned int iacCoolTime_uS;
2016-12-11 04:23:54 -08:00
unsigned int completedHomeSteps;
2015-05-29 00:33:00 -07:00
volatile PORT_TYPE *idle_pin_port;
2019-03-03 14:15:57 -08:00
volatile PINMASK_TYPE idle_pin_mask;
volatile PORT_TYPE *idle2_pin_port;
2019-03-03 14:15:57 -08:00
volatile PINMASK_TYPE idle2_pin_mask;
volatile PORT_TYPE *idleUpOutput_pin_port;
volatile PINMASK_TYPE idleUpOutput_pin_mask;
2015-09-25 17:12:59 -07:00
volatile bool idle_pwm_state;
2021-12-08 13:52:56 -08:00
bool lastDFCOValue;
2015-09-25 17:12:59 -07:00
unsigned int idle_pwm_max_count; //Used for variable PWM frequency
2015-09-29 16:27:37 -07:00
volatile unsigned int idle_pwm_cur_value;
long idle_pid_target_value;
Closed loop idle improve (#481) * Squashed commit of the following: commit c73f316fa5bf8c929a8fef5736f4a40045ea992f Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Wed Nov 25 21:53:45 2020 +0100 cleanup and fix merge issues commit 57f1e8c6c73bcfb699b18ac51a2ec646be822f55 Merge: 04478ca 131673d Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Wed Nov 25 18:59:58 2020 +0100 Merge branch 'Closedloop_idle_improvements' into ClosedLoopIdleImprovement commit 131673dc60417cbc773b0763d2f93e917c83325f Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Sun Nov 22 21:54:03 2020 +0100 more fiddeling with idle control commit e4406166cde91552027a0dfb7958d6894098f066 Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Sun Nov 22 20:36:24 2020 +0100 More fiddeling with idle control commit 45822003d41e021e3ed93e8e14ce05479ddfd17b Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Sat Nov 21 14:59:32 2020 +0100 fix initial value commit ff8fadae7844bd8e5934ee0f311fbf5e0842ec29 Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Thu Nov 19 23:14:14 2020 +0100 add TPS limit to prevent integeral windup. commit 7683b2e65569787b1c94eae6f4847cdadd394402 Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Thu Nov 19 22:40:53 2020 +0100 cleanup idle.h commit da55ee9dbd76d65608bfb5b950bc948a498b9599 Author: Tjeerd <tjeerdie@users.noreply.github.com> Date: Thu Nov 19 22:36:18 2020 +0100 Further improvement simplifying code for closedloop PID control with feedforward. make PWM output work Tinkering new Idle control working on closedloop idle Initial work on improving closed loop Idle control * reset platformio.ini Co-authored-by: Tjeerd <tjeerdie@users.noreply.github.com>
2020-12-01 13:37:58 -08:00
long FeedForwardTerm;
2020-07-29 16:15:24 -07:00
unsigned long idle_pwm_target_value;
2016-04-06 20:28:13 -07:00
long idle_cl_target_rpm;
byte idleCounter; //Used for tracking the number of calls to the idle control function
uint8_t idleTaper;
2015-09-25 17:12:59 -07:00
byte idleUpOutputHIGH = HIGH; // Used to invert the idle Up Output
byte idleUpOutputLOW = LOW; // Used to invert the idle Up Output
void initialiseIdle(bool forcehoming);
2022-11-05 15:43:29 -07:00
void idleControl(void);
void initialiseIdleUpOutput(void);
void disableIdle(void);
void idleInterrupt(void);
#endif