2016-10-06 23:34:27 -07:00
# ifndef AUX_H
# define AUX_H
2015-09-26 16:14:29 -07:00
2019-01-18 02:15:27 -08:00
# include BOARD_H //Note that this is not a real file, it is defined in globals.h.
2023-04-23 17:30:51 -07:00
# if defined(CORE_AVR)
# include <util/atomic.h>
# endif
2022-11-05 15:43:29 -07:00
void initialiseAuxPWM ( void ) ;
void boostControl ( void ) ;
void boostDisable ( void ) ;
void boostByGear ( void ) ;
void vvtControl ( void ) ;
void initialiseFan ( void ) ;
void initialiseAirCon ( void ) ;
void nitrousControl ( void ) ;
void fanControl ( void ) ;
void airConControl ( void ) ;
bool READ_AIRCON_REQUEST ( void ) ;
void wmiControl ( void ) ;
2019-11-12 22:25:59 -08:00
# define SIMPLE_BOOST_P 1
# define SIMPLE_BOOST_I 1
# define SIMPLE_BOOST_D 1
2023-04-23 17:30:51 -07:00
# if(defined(CORE_TEENSY) || defined(CORE_STM32))
2023-05-16 22:39:34 -07:00
# define BOOST_PIN_LOW() (digitalWrite(pinBoost, LOW))
# define BOOST_PIN_HIGH() (digitalWrite(pinBoost, HIGH))
# define VVT1_PIN_LOW() (digitalWrite(pinVVT_1, LOW))
# define VVT1_PIN_HIGH() (digitalWrite(pinVVT_1, HIGH))
# define VVT2_PIN_LOW() (digitalWrite(pinVVT_2, LOW))
# define VVT2_PIN_HIGH() (digitalWrite(pinVVT_2, HIGH))
# define FAN_PIN_LOW() (digitalWrite(pinFan, LOW))
# define FAN_PIN_HIGH() (digitalWrite(pinFan, HIGH))
2022-08-30 23:19:09 -07:00
# define N2O_STAGE1_PIN_LOW() (digitalWrite(configPage10.n2o_stage1_pin, LOW))
# define N2O_STAGE1_PIN_HIGH() (digitalWrite(configPage10.n2o_stage1_pin, HIGH))
# define N2O_STAGE2_PIN_LOW() (digitalWrite(configPage10.n2o_stage2_pin, LOW))
# define N2O_STAGE2_PIN_HIGH() (digitalWrite(configPage10.n2o_stage2_pin, HIGH))
Air Conditioning Control - Feature Implementation (#665)
* 19.09.2021
* Final testing of AC Control, some idle features fixed
AC control feature added, better than the existing idle-up feature (which can still be used for other things, e.g. electrical load detection). Air conditioning is locked out with coolant temp, RPM high/low, and high TPS. So the A/C automatically cuts out when driving hard.
Idle step now works correctly with closed loop PWM, open loop PWM, and closed+open loop PWM. Untested with stepper motor, but no reason it shouldn't work.
* Fixed mistakenly incremented page sizes
* Initial changes as per HWright9
-Renamed engineRunSeconds to acAfterEngineStartDelay
-Formatted large if statements better
-Fixed acStartDelay overflow bug
-Improved readability of logic
* Final fixes as per HWright9's feedback
-Add high/low RPM lockout delay, similar to the high TPM lockout delay
-General tidy-up
* Added stand-alone fan, moved config data in EEPROM
-Added additional configurable stand-alone A/C fan output, for when there is dedicated cooling fan for the A/C compressor. This is independent of the engine cooling fan logic.
-Moved config storage in EEPROM to configPage9, as noisymime's SD card logging has used the (previously unused) bytes I had used in configPage13.
-Minor bug fix - rename Aux in 1-16 to Aux in 0-15
* Revert to current master branch - as of master commit 97f8ef795a514c9a5693e85be6cdb8bdee8ef2c5
* A/C Control Re-Integrated from AC-Control-Clean-3 (@Corey-Harding). Tested & ready to merge.
Additionally, added @HazuTo25's lines into the update() routine to configure default A/C settings.
* Changed updates.ino to just set A/C to disabled
* Fix change reverted by mistake - master merge commit 73badbce8ca171faa8c58575947917829adfc1ba
* Fix remaining mistakes from previous master merge
* Remove test statements left in by mistake
* define unusedBits
* Remove test statements left in by mistake
* Increase timing granularity to 0.1s
* idleUpRPMAdder
* Remove another line put in by mistake by auto merge
* idleUpRPMFixes
* Update speeduino.ino
* Tweak A/C idle up descriptions
* Tweak A/C TS descriptors again
* Fixed alignment bug that turned page 15 config values into gobbledegook.
This had the symptom of the A/C request never triggering, because when a pin was assigned in TS (e.g. I did 27), a completely different pin would be read from config15 (in my case 22 - connecting the button to pin 22 would work in this case, even though TS was set to 27).
* Fix bit count - should be 6 to match ini file
* Increase minimum RPM lockout granularity
* Change granularity of A/C minimum RPM lockout to 10 RPM; Inline some functions for readability
* Add static inline function prototypes to auxiliaries.h as per the style guide.
* Fixed page 15 merge errors
* Style changes to suit new pinIsUsed() checks in setPinMappings()
* Add PWM Fan Control Minimum Clamp Value when A/C Compressor Engaged
* Fix comment
* Fix bug with stand-alone fan initialisation
Pin was unable to be used in prog. I/O even if fan was disabled, because it was always initialised as an output even if it was disabled. Fixed in this commit.
* Correction to Fahrenheit temperature scaling
* Move A/C updates to correct next release
Co-authored-by: shiznit304 <62686180+shiznit304@users.noreply.github.com>
Co-authored-by: Josh Stewart <josh@noisymime.org>
2022-09-06 17:23:01 -07:00
# define AIRCON_PIN_LOW() (digitalWrite(pinAirConComp, LOW))
# define AIRCON_PIN_HIGH() (digitalWrite(pinAirConComp, HIGH))
# define AIRCON_FAN_PIN_LOW() (digitalWrite(pinAirConFan, LOW))
# define AIRCON_FAN_PIN_HIGH() (digitalWrite(pinAirConFan, HIGH))
2023-04-23 17:30:51 -07:00
# define FUEL_PUMP_ON() (digitalWrite(pinFuelPump, HIGH))
# define FUEL_PUMP_OFF() (digitalWrite(pinFuelPump, LOW))
2023-11-23 13:07:47 -08:00
# define AIRCON_ON() { (((configPage15.airConCompPol==1)) ? AIRCON_PIN_LOW() : AIRCON_PIN_HIGH()); BIT_SET(currentStatus.airConStatus, BIT_AIRCON_COMPRESSOR); }
# define AIRCON_OFF() { (((configPage15.airConCompPol==1)) ? AIRCON_PIN_HIGH() : AIRCON_PIN_LOW()); BIT_CLEAR(currentStatus.airConStatus, BIT_AIRCON_COMPRESSOR); }
# define AIRCON_FAN_ON() { (((configPage15.airConFanPol==1)) ? AIRCON_FAN_PIN_LOW() : AIRCON_FAN_PIN_HIGH()); BIT_SET(currentStatus.airConStatus, BIT_AIRCON_FAN); }
# define AIRCON_FAN_OFF() { (((configPage15.airConFanPol==1)) ? AIRCON_FAN_PIN_HIGH() : AIRCON_FAN_PIN_LOW()); BIT_CLEAR(currentStatus.airConStatus, BIT_AIRCON_FAN); }
2023-04-23 17:30:51 -07:00
# define FAN_ON() { ((configPage6.fanInv) ? FAN_PIN_LOW() : FAN_PIN_HIGH()); }
# define FAN_OFF() { ((configPage6.fanInv) ? FAN_PIN_HIGH() : FAN_PIN_LOW()); }
2022-08-30 23:19:09 -07:00
# else
2023-04-23 17:30:51 -07:00
# define BOOST_PIN_LOW() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *boost_pin_port &= ~(boost_pin_mask); }
# define BOOST_PIN_HIGH() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *boost_pin_port |= (boost_pin_mask); }
# define VVT1_PIN_LOW() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *vvt1_pin_port &= ~(vvt1_pin_mask); }
# define VVT1_PIN_HIGH() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *vvt1_pin_port |= (vvt1_pin_mask); }
# define VVT2_PIN_LOW() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *vvt2_pin_port &= ~(vvt2_pin_mask); }
# define VVT2_PIN_HIGH() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *vvt2_pin_port |= (vvt2_pin_mask); }
# define N2O_STAGE1_PIN_LOW() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *n2o_stage1_pin_port &= ~(n2o_stage1_pin_mask); }
# define N2O_STAGE1_PIN_HIGH() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *n2o_stage1_pin_port |= (n2o_stage1_pin_mask); }
# define N2O_STAGE2_PIN_LOW() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *n2o_stage2_pin_port &= ~(n2o_stage2_pin_mask); }
# define N2O_STAGE2_PIN_HIGH() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *n2o_stage2_pin_port |= (n2o_stage2_pin_mask); }
# define FUEL_PUMP_ON() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *pump_pin_port |= (pump_pin_mask); }
# define FUEL_PUMP_OFF() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { *pump_pin_port &= ~(pump_pin_mask); }
//Note the below macros cannot use ATOMIC_BLOCK(ATOMIC_RESTORESTATE) as they are called from within ternary operators. The ATOMIC_BLOCK wrapped is instead placed around the ternary call below
# define FAN_PIN_LOW() *fan_pin_port &= ~(fan_pin_mask)
# define FAN_PIN_HIGH() *fan_pin_port |= (fan_pin_mask)
# define AIRCON_PIN_LOW() *aircon_comp_pin_port &= ~(aircon_comp_pin_mask)
# define AIRCON_PIN_HIGH() *aircon_comp_pin_port |= (aircon_comp_pin_mask)
Air Conditioning Control - Feature Implementation (#665)
* 19.09.2021
* Final testing of AC Control, some idle features fixed
AC control feature added, better than the existing idle-up feature (which can still be used for other things, e.g. electrical load detection). Air conditioning is locked out with coolant temp, RPM high/low, and high TPS. So the A/C automatically cuts out when driving hard.
Idle step now works correctly with closed loop PWM, open loop PWM, and closed+open loop PWM. Untested with stepper motor, but no reason it shouldn't work.
* Fixed mistakenly incremented page sizes
* Initial changes as per HWright9
-Renamed engineRunSeconds to acAfterEngineStartDelay
-Formatted large if statements better
-Fixed acStartDelay overflow bug
-Improved readability of logic
* Final fixes as per HWright9's feedback
-Add high/low RPM lockout delay, similar to the high TPM lockout delay
-General tidy-up
* Added stand-alone fan, moved config data in EEPROM
-Added additional configurable stand-alone A/C fan output, for when there is dedicated cooling fan for the A/C compressor. This is independent of the engine cooling fan logic.
-Moved config storage in EEPROM to configPage9, as noisymime's SD card logging has used the (previously unused) bytes I had used in configPage13.
-Minor bug fix - rename Aux in 1-16 to Aux in 0-15
* Revert to current master branch - as of master commit 97f8ef795a514c9a5693e85be6cdb8bdee8ef2c5
* A/C Control Re-Integrated from AC-Control-Clean-3 (@Corey-Harding). Tested & ready to merge.
Additionally, added @HazuTo25's lines into the update() routine to configure default A/C settings.
* Changed updates.ino to just set A/C to disabled
* Fix change reverted by mistake - master merge commit 73badbce8ca171faa8c58575947917829adfc1ba
* Fix remaining mistakes from previous master merge
* Remove test statements left in by mistake
* define unusedBits
* Remove test statements left in by mistake
* Increase timing granularity to 0.1s
* idleUpRPMAdder
* Remove another line put in by mistake by auto merge
* idleUpRPMFixes
* Update speeduino.ino
* Tweak A/C idle up descriptions
* Tweak A/C TS descriptors again
* Fixed alignment bug that turned page 15 config values into gobbledegook.
This had the symptom of the A/C request never triggering, because when a pin was assigned in TS (e.g. I did 27), a completely different pin would be read from config15 (in my case 22 - connecting the button to pin 22 would work in this case, even though TS was set to 27).
* Fix bit count - should be 6 to match ini file
* Increase minimum RPM lockout granularity
* Change granularity of A/C minimum RPM lockout to 10 RPM; Inline some functions for readability
* Add static inline function prototypes to auxiliaries.h as per the style guide.
* Fixed page 15 merge errors
* Style changes to suit new pinIsUsed() checks in setPinMappings()
* Add PWM Fan Control Minimum Clamp Value when A/C Compressor Engaged
* Fix comment
* Fix bug with stand-alone fan initialisation
Pin was unable to be used in prog. I/O even if fan was disabled, because it was always initialised as an output even if it was disabled. Fixed in this commit.
* Correction to Fahrenheit temperature scaling
* Move A/C updates to correct next release
Co-authored-by: shiznit304 <62686180+shiznit304@users.noreply.github.com>
Co-authored-by: Josh Stewart <josh@noisymime.org>
2022-09-06 17:23:01 -07:00
# define AIRCON_FAN_PIN_LOW() *aircon_fan_pin_port &= ~(aircon_fan_pin_mask)
# define AIRCON_FAN_PIN_HIGH() *aircon_fan_pin_port |= (aircon_fan_pin_mask)
2022-08-30 23:19:09 -07:00
2023-11-23 13:07:47 -08:00
# define AIRCON_ON() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { ((((configPage15.airConCompPol)==1)) ? AIRCON_PIN_LOW() : AIRCON_PIN_HIGH()); BIT_SET(currentStatus.airConStatus, BIT_AIRCON_COMPRESSOR); }
# define AIRCON_OFF() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { ((((configPage15.airConCompPol)==1)) ? AIRCON_PIN_HIGH() : AIRCON_PIN_LOW()); BIT_CLEAR(currentStatus.airConStatus, BIT_AIRCON_COMPRESSOR); }
# define AIRCON_FAN_ON() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { ((((configPage15.airConFanPol)==1)) ? AIRCON_FAN_PIN_LOW() : AIRCON_FAN_PIN_HIGH()); BIT_SET(currentStatus.airConStatus, BIT_AIRCON_FAN); }
# define AIRCON_FAN_OFF() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { ((((configPage15.airConFanPol)==1)) ? AIRCON_FAN_PIN_HIGH() : AIRCON_FAN_PIN_LOW()); BIT_CLEAR(currentStatus.airConStatus, BIT_AIRCON_FAN); }
2023-04-23 17:30:51 -07:00
# define FAN_ON() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { ((configPage6.fanInv) ? FAN_PIN_LOW() : FAN_PIN_HIGH()); }
# define FAN_OFF() ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { ((configPage6.fanInv) ? FAN_PIN_HIGH() : FAN_PIN_LOW()); }
2022-08-30 23:19:09 -07:00
# endif
2018-07-01 03:37:57 -07:00
# define READ_N2O_ARM_PIN() ((*n2o_arming_pin_port & n2o_arming_pin_mask) ? true : false)
Air Conditioning Control - Feature Implementation (#665)
* 19.09.2021
* Final testing of AC Control, some idle features fixed
AC control feature added, better than the existing idle-up feature (which can still be used for other things, e.g. electrical load detection). Air conditioning is locked out with coolant temp, RPM high/low, and high TPS. So the A/C automatically cuts out when driving hard.
Idle step now works correctly with closed loop PWM, open loop PWM, and closed+open loop PWM. Untested with stepper motor, but no reason it shouldn't work.
* Fixed mistakenly incremented page sizes
* Initial changes as per HWright9
-Renamed engineRunSeconds to acAfterEngineStartDelay
-Formatted large if statements better
-Fixed acStartDelay overflow bug
-Improved readability of logic
* Final fixes as per HWright9's feedback
-Add high/low RPM lockout delay, similar to the high TPM lockout delay
-General tidy-up
* Added stand-alone fan, moved config data in EEPROM
-Added additional configurable stand-alone A/C fan output, for when there is dedicated cooling fan for the A/C compressor. This is independent of the engine cooling fan logic.
-Moved config storage in EEPROM to configPage9, as noisymime's SD card logging has used the (previously unused) bytes I had used in configPage13.
-Minor bug fix - rename Aux in 1-16 to Aux in 0-15
* Revert to current master branch - as of master commit 97f8ef795a514c9a5693e85be6cdb8bdee8ef2c5
* A/C Control Re-Integrated from AC-Control-Clean-3 (@Corey-Harding). Tested & ready to merge.
Additionally, added @HazuTo25's lines into the update() routine to configure default A/C settings.
* Changed updates.ino to just set A/C to disabled
* Fix change reverted by mistake - master merge commit 73badbce8ca171faa8c58575947917829adfc1ba
* Fix remaining mistakes from previous master merge
* Remove test statements left in by mistake
* define unusedBits
* Remove test statements left in by mistake
* Increase timing granularity to 0.1s
* idleUpRPMAdder
* Remove another line put in by mistake by auto merge
* idleUpRPMFixes
* Update speeduino.ino
* Tweak A/C idle up descriptions
* Tweak A/C TS descriptors again
* Fixed alignment bug that turned page 15 config values into gobbledegook.
This had the symptom of the A/C request never triggering, because when a pin was assigned in TS (e.g. I did 27), a completely different pin would be read from config15 (in my case 22 - connecting the button to pin 22 would work in this case, even though TS was set to 27).
* Fix bit count - should be 6 to match ini file
* Increase minimum RPM lockout granularity
* Change granularity of A/C minimum RPM lockout to 10 RPM; Inline some functions for readability
* Add static inline function prototypes to auxiliaries.h as per the style guide.
* Fixed page 15 merge errors
* Style changes to suit new pinIsUsed() checks in setPinMappings()
* Add PWM Fan Control Minimum Clamp Value when A/C Compressor Engaged
* Fix comment
* Fix bug with stand-alone fan initialisation
Pin was unable to be used in prog. I/O even if fan was disabled, because it was always initialised as an output even if it was disabled. Fixed in this commit.
* Correction to Fahrenheit temperature scaling
* Move A/C updates to correct next release
Co-authored-by: shiznit304 <62686180+shiznit304@users.noreply.github.com>
Co-authored-by: Josh Stewart <josh@noisymime.org>
2022-09-06 17:23:01 -07:00
2022-08-30 23:19:09 -07:00
# define VVT1_PIN_ON() VVT1_PIN_HIGH();
# define VVT1_PIN_OFF() VVT1_PIN_LOW();
# define VVT2_PIN_ON() VVT2_PIN_HIGH();
# define VVT2_PIN_OFF() VVT2_PIN_LOW();
2021-09-10 17:42:39 -07:00
# define VVT_TIME_DELAY_MULTIPLIER 50
2022-01-04 15:33:33 -08:00
# define WMI_TANK_IS_EMPTY() ((configPage10.wmiEmptyEnabled) ? ((configPage10.wmiEmptyPolarity) ? digitalRead(pinWMIEmpty) : !digitalRead(pinWMIEmpty)) : 1)
2020-07-21 18:27:21 -07:00
2023-10-06 00:10:20 -07:00
extern volatile PORT_TYPE * vvt1_pin_port ;
extern volatile PINMASK_TYPE vvt1_pin_mask ;
extern volatile PORT_TYPE * vvt2_pin_port ;
extern volatile PINMASK_TYPE vvt2_pin_mask ;
extern volatile PORT_TYPE * fan_pin_port ;
extern volatile PINMASK_TYPE fan_pin_mask ;
2021-11-23 17:18:41 -08:00
# if defined(PWM_FAN_AVAILABLE) //PWM fan not available on Arduino MEGA
2023-11-05 14:10:08 -08:00
extern uint16_t fan_pwm_max_count ; //Used for variable PWM frequency
2022-11-05 15:43:29 -07:00
void fanInterrupt ( void ) ;
2021-11-23 17:18:41 -08:00
# endif
2023-10-06 00:10:20 -07:00
2023-11-05 14:10:08 -08:00
extern uint16_t vvt_pwm_max_count ; //Used for variable PWM frequency
extern uint16_t boost_pwm_max_count ; //Used for variable PWM frequency
2021-04-20 23:33:19 -07:00
2022-11-05 15:43:29 -07:00
void boostInterrupt ( void ) ;
void vvtInterrupt ( void ) ;
2016-05-15 04:05:49 -07:00
Air Conditioning Control - Feature Implementation (#665)
* 19.09.2021
* Final testing of AC Control, some idle features fixed
AC control feature added, better than the existing idle-up feature (which can still be used for other things, e.g. electrical load detection). Air conditioning is locked out with coolant temp, RPM high/low, and high TPS. So the A/C automatically cuts out when driving hard.
Idle step now works correctly with closed loop PWM, open loop PWM, and closed+open loop PWM. Untested with stepper motor, but no reason it shouldn't work.
* Fixed mistakenly incremented page sizes
* Initial changes as per HWright9
-Renamed engineRunSeconds to acAfterEngineStartDelay
-Formatted large if statements better
-Fixed acStartDelay overflow bug
-Improved readability of logic
* Final fixes as per HWright9's feedback
-Add high/low RPM lockout delay, similar to the high TPM lockout delay
-General tidy-up
* Added stand-alone fan, moved config data in EEPROM
-Added additional configurable stand-alone A/C fan output, for when there is dedicated cooling fan for the A/C compressor. This is independent of the engine cooling fan logic.
-Moved config storage in EEPROM to configPage9, as noisymime's SD card logging has used the (previously unused) bytes I had used in configPage13.
-Minor bug fix - rename Aux in 1-16 to Aux in 0-15
* Revert to current master branch - as of master commit 97f8ef795a514c9a5693e85be6cdb8bdee8ef2c5
* A/C Control Re-Integrated from AC-Control-Clean-3 (@Corey-Harding). Tested & ready to merge.
Additionally, added @HazuTo25's lines into the update() routine to configure default A/C settings.
* Changed updates.ino to just set A/C to disabled
* Fix change reverted by mistake - master merge commit 73badbce8ca171faa8c58575947917829adfc1ba
* Fix remaining mistakes from previous master merge
* Remove test statements left in by mistake
* define unusedBits
* Remove test statements left in by mistake
* Increase timing granularity to 0.1s
* idleUpRPMAdder
* Remove another line put in by mistake by auto merge
* idleUpRPMFixes
* Update speeduino.ino
* Tweak A/C idle up descriptions
* Tweak A/C TS descriptors again
* Fixed alignment bug that turned page 15 config values into gobbledegook.
This had the symptom of the A/C request never triggering, because when a pin was assigned in TS (e.g. I did 27), a completely different pin would be read from config15 (in my case 22 - connecting the button to pin 22 would work in this case, even though TS was set to 27).
* Fix bit count - should be 6 to match ini file
* Increase minimum RPM lockout granularity
* Change granularity of A/C minimum RPM lockout to 10 RPM; Inline some functions for readability
* Add static inline function prototypes to auxiliaries.h as per the style guide.
* Fixed page 15 merge errors
* Style changes to suit new pinIsUsed() checks in setPinMappings()
* Add PWM Fan Control Minimum Clamp Value when A/C Compressor Engaged
* Fix comment
* Fix bug with stand-alone fan initialisation
Pin was unable to be used in prog. I/O even if fan was disabled, because it was always initialised as an output even if it was disabled. Fixed in this commit.
* Correction to Fahrenheit temperature scaling
* Move A/C updates to correct next release
Co-authored-by: shiznit304 <62686180+shiznit304@users.noreply.github.com>
Co-authored-by: Josh Stewart <josh@noisymime.org>
2022-09-06 17:23:01 -07:00
# endif