digitalWriteFast.h inplementation
This commit is contained in:
parent
6d8714e035
commit
18319259a0
|
@ -12,13 +12,13 @@ void initialiseFan()
|
|||
{
|
||||
if(configPage4.fanInv == 1) {fanHIGH = LOW, fanLOW = HIGH; }
|
||||
else {fanHIGH = HIGH, fanLOW = LOW;}
|
||||
digitalWrite(pinFan, fanLOW); //Initiallise program with the fan in the off state
|
||||
digitalWriteFast(pinFan, fanLOW); //Initiallise program with the fan in the off state
|
||||
}
|
||||
|
||||
void fanControl()
|
||||
{
|
||||
if (currentStatus.coolant >= (configPage4.fanSP - CALIBRATION_TEMPERATURE_OFFSET)) { digitalWrite(pinFan,fanHIGH); }
|
||||
else if (currentStatus.coolant <= (configPage4.fanSP - configPage4.fanHyster)) { digitalWrite(pinFan, fanLOW); }
|
||||
if (currentStatus.coolant >= (configPage4.fanSP - CALIBRATION_TEMPERATURE_OFFSET)) { digitalWriteFast(pinFan,fanHIGH); }
|
||||
else if (currentStatus.coolant <= (configPage4.fanSP - configPage4.fanHyster)) { digitalWriteFast(pinFan, fanLOW); }
|
||||
}
|
||||
|
||||
void initialiseAuxPWM()
|
||||
|
@ -47,7 +47,7 @@ void boostControl()
|
|||
{
|
||||
if(configPage3.boostEnabled)
|
||||
{
|
||||
if(currentStatus.MAP < 100) { TIMSK1 &= ~(1 << OCIE1A); digitalWrite(pinBoost, LOW); return; } //Set duty to 0 and turn off timer compare
|
||||
if(currentStatus.MAP < 100) { TIMSK1 &= ~(1 << OCIE1A); digitalWriteFast(pinBoost, LOW); return; } //Set duty to 0 and turn off timer compare
|
||||
boost_cl_target_boost = get3DTableValue(&boostTable, currentStatus.TPS, currentStatus.RPM) * 2; //Boost target table is in kpa and divided by 2
|
||||
boostPID.SetTunings(configPage3.boostKP, configPage3.boostKI, configPage3.boostKD);
|
||||
boostPID.Compute();
|
||||
|
|
|
@ -0,0 +1,357 @@
|
|||
/*
|
||||
Optimized digital functions for AVR microcontrollers
|
||||
by Watterott electronic (www.watterott.com)
|
||||
based on http://code.google.com/p/digitalwritefast
|
||||
*/
|
||||
|
||||
#ifndef __digitalWriteFast_h_
|
||||
#define __digitalWriteFast_h_ 1
|
||||
|
||||
// general macros/defines
|
||||
#ifndef BIT_READ
|
||||
# define BIT_READ(value, bit) ((value) & (1UL << (bit)))
|
||||
#endif
|
||||
#ifndef BIT_SET
|
||||
# define BIT_SET(value, bit) ((value) |= (1UL << (bit)))
|
||||
#endif
|
||||
#ifndef BIT_CLEAR
|
||||
# define BIT_CLEAR(value, bit) ((value) &= ~(1UL << (bit)))
|
||||
#endif
|
||||
#ifndef BIT_WRITE
|
||||
# define BIT_WRITE(value, bit, bitvalue) (bitvalue ? BIT_SET(value, bit) : BIT_CLEAR(value, bit))
|
||||
#endif
|
||||
|
||||
#ifndef SWAP
|
||||
#define SWAP(x,y) do{ (x)=(x)^(y); (y)=(x)^(y); (x)=(x)^(y); }while(0)
|
||||
#endif
|
||||
|
||||
#ifndef DEC
|
||||
# define DEC (10)
|
||||
#endif
|
||||
#ifndef HEX
|
||||
# define HEX (16)
|
||||
#endif
|
||||
#ifndef OCT
|
||||
# define OCT (8)
|
||||
#endif
|
||||
#ifndef BIN
|
||||
# define BIN (2)
|
||||
#endif
|
||||
|
||||
|
||||
// workarounds for ARM microcontrollers
|
||||
#if (!defined(__AVR__) || defined(ARDUINO_ARCH_SAM))
|
||||
#ifndef PROGMEM
|
||||
# define PROGMEM
|
||||
#endif
|
||||
#ifndef PGM_P
|
||||
# define PGM_P const char *
|
||||
#endif
|
||||
#ifndef PSTR
|
||||
# define PSTR(str) (str)
|
||||
#endif
|
||||
|
||||
#ifndef memcpy_P
|
||||
# define memcpy_P(dest, src, num) memcpy((dest), (src), (num))
|
||||
#endif
|
||||
#ifndef strcpy_P
|
||||
# define strcpy_P(dst, src) strcpy((dst), (src))
|
||||
#endif
|
||||
#ifndef strcat_P
|
||||
# define strcat_P(dst, src) strcat((dst), (src))
|
||||
#endif
|
||||
#ifndef strcmp_P
|
||||
# define strcmp_P(a, b) strcmp((a), (b))
|
||||
#endif
|
||||
#ifndef strcasecmp_P
|
||||
# define strcasecmp_P(a, b) strcasecmp((a), (b))
|
||||
#endif
|
||||
#ifndef strncmp_P
|
||||
# define strncmp_P(a, b, n) strncmp((a), (b), (n))
|
||||
#endif
|
||||
#ifndef strncasecmp_P
|
||||
# define strncasecmp_P(a, b, n) strncasecmp((a), (b), (n))
|
||||
#endif
|
||||
#ifndef strstr_P
|
||||
# define strstr_P(a, b) strstr((a), (b))
|
||||
#endif
|
||||
#ifndef strlen_P
|
||||
# define strlen_P(a) strlen((a))
|
||||
#endif
|
||||
#ifndef sprintf_P
|
||||
# define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifndef pgm_read_byte
|
||||
# define pgm_read_byte(addr) (*(const unsigned char *)(addr))
|
||||
#endif
|
||||
#ifndef pgm_read_word
|
||||
# define pgm_read_word(addr) (*(const unsigned short *)(addr))
|
||||
#endif
|
||||
#ifndef pgm_read_dword
|
||||
# define pgm_read_dword(addr) (*(const unsigned long *)(addr))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// digital functions
|
||||
//#ifndef digitalPinToPortReg
|
||||
#define SPI_SW_SS_PIN (10) //SS on Uno (for software SPI)
|
||||
#define SPI_SW_MOSI_PIN (11) //MOSI on Uno (for software SPI)
|
||||
#define SPI_SW_MISO_PIN (12) //MISO on Uno (for software SPI)
|
||||
#define SPI_SW_SCK_PIN (13) //SCK on Uno (for software SPI)
|
||||
|
||||
|
||||
// --- Arduino Due ---
|
||||
#if (defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__))
|
||||
|
||||
#define UART_RX_PIN (0)
|
||||
#define UART_TX_PIN (1)
|
||||
|
||||
#define I2C_SDA_PIN (20)
|
||||
#define I2C_SCL_PIN (21)
|
||||
|
||||
#define SPI_HW_SS_PIN (78) //SS0:77, SS1:87, SS2:86, SS3:78
|
||||
#define SPI_HW_MOSI_PIN (75) //75
|
||||
#define SPI_HW_MISO_PIN (74) //74
|
||||
#define SPI_HW_SCK_PIN (76) //76
|
||||
|
||||
|
||||
// --- Arduino Zero ---
|
||||
#elif (defined(ARDUINO_SAM_ZERO) || defined(__SAMD21G18A__))
|
||||
|
||||
#define UART_RX_PIN (0)
|
||||
#define UART_TX_PIN (1)
|
||||
|
||||
#define I2C_SDA_PIN (16)
|
||||
#define I2C_SCL_PIN (17)
|
||||
|
||||
#define SPI_HW_SS_PIN (14) //14
|
||||
#define SPI_HW_MOSI_PIN (21) //21
|
||||
#define SPI_HW_MISO_PIN (18) //18
|
||||
#define SPI_HW_SCK_PIN (20) //20
|
||||
|
||||
|
||||
// --- Arduino Mega ---
|
||||
#elif (defined(ARDUINO_AVR_MEGA) || \
|
||||
defined(ARDUINO_AVR_MEGA1280) || \
|
||||
defined(ARDUINO_AVR_MEGA2560) || \
|
||||
defined(__AVR_ATmega1280__) || \
|
||||
defined(__AVR_ATmega1281__) || \
|
||||
defined(__AVR_ATmega2560__) || \
|
||||
defined(__AVR_ATmega2561__))
|
||||
|
||||
#define UART_RX_PIN (0) //PE0
|
||||
#define UART_TX_PIN (1) //PE1
|
||||
|
||||
#define I2C_SDA_PIN (20)
|
||||
#define I2C_SCL_PIN (21)
|
||||
|
||||
#define SPI_HW_SS_PIN (53) //PB0
|
||||
#define SPI_HW_MOSI_PIN (51) //PB2
|
||||
#define SPI_HW_MISO_PIN (50) //PB3
|
||||
#define SPI_HW_SCK_PIN (52) //PB1
|
||||
|
||||
#define __digitalPinToPortReg(P) \
|
||||
(((P) >= 22 && (P) <= 29) ? &PORTA : \
|
||||
((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PORTB : \
|
||||
(((P) >= 30 && (P) <= 37) ? &PORTC : \
|
||||
((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PORTD : \
|
||||
((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PORTE : \
|
||||
(((P) >= 54 && (P) <= 61) ? &PORTF : \
|
||||
((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PORTG : \
|
||||
((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PORTH : \
|
||||
(((P) == 14 || (P) == 15) ? &PORTJ : \
|
||||
(((P) >= 62 && (P) <= 69) ? &PORTK : &PORTL))))))))))
|
||||
|
||||
#define __digitalPinToDDRReg(P) \
|
||||
(((P) >= 22 && (P) <= 29) ? &DDRA : \
|
||||
((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &DDRB : \
|
||||
(((P) >= 30 && (P) <= 37) ? &DDRC : \
|
||||
((((P) >= 18 && (P) <= 21) || (P) == 38) ? &DDRD : \
|
||||
((((P) >= 0 && (P) <= 3) || (P) == 5) ? &DDRE : \
|
||||
(((P) >= 54 && (P) <= 61) ? &DDRF : \
|
||||
((((P) >= 39 && (P) <= 41) || (P) == 4) ? &DDRG : \
|
||||
((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &DDRH : \
|
||||
(((P) == 14 || (P) == 15) ? &DDRJ : \
|
||||
(((P) >= 62 && (P) <= 69) ? &DDRK : &DDRL))))))))))
|
||||
|
||||
#define __digitalPinToPINReg(P) \
|
||||
(((P) >= 22 && (P) <= 29) ? &PINA : \
|
||||
((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PINB : \
|
||||
(((P) >= 30 && (P) <= 37) ? &PINC : \
|
||||
((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PIND : \
|
||||
((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PINE : \
|
||||
(((P) >= 54 && (P) <= 61) ? &PINF : \
|
||||
((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PING : \
|
||||
((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PINH : \
|
||||
(((P) == 14 || (P) == 15) ? &PINJ : \
|
||||
(((P) >= 62 && (P) <= 69) ? &PINK : &PINL))))))))))
|
||||
|
||||
#define __digitalPinToBit(P) \
|
||||
(((P) >= 7 && (P) <= 9) ? (P) - 3 : \
|
||||
(((P) >= 10 && (P) <= 13) ? (P) - 6 : \
|
||||
(((P) >= 22 && (P) <= 29) ? (P) - 22 : \
|
||||
(((P) >= 30 && (P) <= 37) ? 37 - (P) : \
|
||||
(((P) >= 39 && (P) <= 41) ? 41 - (P) : \
|
||||
(((P) >= 42 && (P) <= 49) ? 49 - (P) : \
|
||||
(((P) >= 50 && (P) <= 53) ? 53 - (P) : \
|
||||
(((P) >= 54 && (P) <= 61) ? (P) - 54 : \
|
||||
(((P) >= 62 && (P) <= 69) ? (P) - 62 : \
|
||||
(((P) == 0 || (P) == 15 || (P) == 17 || (P) == 21) ? 0 : \
|
||||
(((P) == 1 || (P) == 14 || (P) == 16 || (P) == 20) ? 1 : \
|
||||
(((P) == 19) ? 2 : \
|
||||
(((P) == 5 || (P) == 6 || (P) == 18) ? 3 : \
|
||||
(((P) == 2) ? 4 : \
|
||||
(((P) == 3 || (P) == 4) ? 5 : 7)))))))))))))))
|
||||
|
||||
|
||||
// --- Arduino 644 ---
|
||||
#elif (defined(__AVR_ATmega644__) || \
|
||||
defined(__AVR_ATmega644P__))
|
||||
|
||||
#define UART_RX_PIN (8) //PD0
|
||||
#define UART_TX_PIN (9) //PD1
|
||||
|
||||
#define I2C_SDA_PIN (17) //PC1
|
||||
#define I2C_SCL_PIN (16) //PC0
|
||||
|
||||
#define SPI_HW_SS_PIN (4) //PB4
|
||||
#define SPI_HW_MOSI_PIN (5) //PB5
|
||||
#define SPI_HW_MISO_PIN (6) //PB6
|
||||
#define SPI_HW_SCK_PIN (7) //PB7
|
||||
|
||||
#define __digitalPinToPortReg(P) \
|
||||
(((P) >= 0 && (P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : (((P) >= 16 && (P) <= 23) ? &PORTC : &PORTA)))
|
||||
#define __digitalPinToDDRReg(P) \
|
||||
(((P) >= 0 && (P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : (((P) >= 8 && (P) <= 15) ? &DDRC : &DDRA)))
|
||||
#define __digitalPinToPINReg(P) \
|
||||
(((P) >= 0 && (P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : (((P) >= 8 && (P) <= 15) ? &PINC : &PINA)))
|
||||
#define __digitalPinToBit(P) \
|
||||
(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (P) - 24)))
|
||||
|
||||
|
||||
// --- Arduino Leonardo ---
|
||||
#elif (defined(ARDUINO_AVR_LEONARDO) || \
|
||||
defined(__AVR_ATmega16U4__) || \
|
||||
defined(__AVR_ATmega32U4__))
|
||||
|
||||
#define UART_RX_PIN (0) //PD2
|
||||
#define UART_TX_PIN (1) //PD3
|
||||
|
||||
#define I2C_SDA_PIN (2) //PD1
|
||||
#define I2C_SCL_PIN (3) //PD0
|
||||
|
||||
#define SPI_HW_SS_PIN (17) //PB0
|
||||
#define SPI_HW_MOSI_PIN (16) //PB2
|
||||
#define SPI_HW_MISO_PIN (14) //PB3
|
||||
#define SPI_HW_SCK_PIN (15) //PB1
|
||||
|
||||
#define __digitalPinToPortReg(P) \
|
||||
((((P) >= 0 && (P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PORTD : (((P) == 5 || (P) == 13) ? &PORTC : (((P) >= 18 && (P) <= 23)) ? &PORTF : (((P) == 7) ? &PORTE : &PORTB)))
|
||||
#define __digitalPinToDDRReg(P) \
|
||||
((((P) >= 0 && (P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &DDRD : (((P) == 5 || (P) == 13) ? &DDRC : (((P) >= 18 && (P) <= 23)) ? &DDRF : (((P) == 7) ? &DDRE : &DDRB)))
|
||||
#define __digitalPinToPINReg(P) \
|
||||
((((P) >= 0 && (P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PIND : (((P) == 5 || (P) == 13) ? &PINC : (((P) >= 18 && (P) <= 23)) ? &PINF : (((P) == 7) ? &PINE : &PINB)))
|
||||
#define __digitalPinToBit(P) \
|
||||
(((P) >= 8 && (P) <= 11) ? (P) - 4 : (((P) >= 18 && (P) <= 21) ? 25 - (P) : (((P) == 0) ? 2 : (((P) == 1) ? 3 : (((P) == 2) ? 1 : (((P) == 3) ? 0 : (((P) == 4) ? 4 : (((P) == 6) ? 7 : (((P) == 13) ? 7 : (((P) == 14) ? 3 : (((P) == 15) ? 1 : (((P) == 16) ? 2 : (((P) == 17) ? 0 : (((P) == 22) ? 1 : (((P) == 23) ? 0 : (((P) == 24) ? 4 : (((P) == 25) ? 7 : (((P) == 26) ? 4 : (((P) == 27) ? 5 : 6 )))))))))))))))))))
|
||||
|
||||
|
||||
// --- Arduino Uno ---
|
||||
#elif (defined(ARDUINO_AVR_UNO) || \
|
||||
defined(ARDUINO_AVR_DUEMILANOVE) || \
|
||||
defined(__AVR_ATmega328__) || \
|
||||
defined(__AVR_ATmega328P__) || \
|
||||
defined(__AVR_ATmega328PB__))
|
||||
|
||||
#define UART_RX_PIN (0) //PD0
|
||||
#define UART_TX_PIN (1) //PD1
|
||||
|
||||
#define I2C_SDA_PIN (18) //A4
|
||||
#define I2C_SCL_PIN (19) //A5
|
||||
|
||||
#define SPI_HW_SS_PIN (10) //PB0
|
||||
#define SPI_HW_MOSI_PIN (11) //PB2
|
||||
#define SPI_HW_MISO_PIN (12) //PB3
|
||||
#define SPI_HW_SCK_PIN (13) //PB1
|
||||
|
||||
#if defined(__AVR_ATmega328PB__)
|
||||
#define __digitalPinToPortReg(P) \
|
||||
(((P) >= 0 && (P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : (((P) >= 14 && (P) <= 19) ? &PORTC : &PORTE)))
|
||||
#define __digitalPinToDDRReg(P) \
|
||||
(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : (((P) >= 14 && (P) <= 19) ? &DDRC : &DDRE)))
|
||||
#define __digitalPinToPINReg(P) \
|
||||
(((P) >= 0 && (P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : (((P) >= 14 && (P) <= 19) ? &PINC : &PINE)))
|
||||
#define __digitalPinToBit(P) \
|
||||
(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (((P) >= 14 && (P) <= 19) ? (P) - 14 : (((P) >= 20 && (P) <= 21) ? (P) - 18 : (P) - 22))))
|
||||
#else
|
||||
#define __digitalPinToPortReg(P) \
|
||||
(((P) >= 0 && (P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : &PORTC))
|
||||
#define __digitalPinToDDRReg(P) \
|
||||
(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC))
|
||||
#define __digitalPinToPINReg(P) \
|
||||
(((P) >= 0 && (P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : &PINC))
|
||||
#define __digitalPinToBit(P) \
|
||||
(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (P) - 14))
|
||||
#endif
|
||||
|
||||
|
||||
// --- Other ---
|
||||
#else
|
||||
|
||||
#define I2C_SDA_PIN SDA
|
||||
#define I2C_SCL_PIN SCL
|
||||
|
||||
#define SPI_HW_SS_PIN SS
|
||||
#define SPI_HW_MOSI_PIN MOSI
|
||||
#define SPI_HW_MISO_PIN MISO
|
||||
#define SPI_HW_SCK_PIN SCK
|
||||
|
||||
|
||||
#endif
|
||||
//#endif //#ifndef digitalPinToPortReg
|
||||
|
||||
|
||||
#ifndef digitalWriteFast
|
||||
#if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR))
|
||||
#define digitalWriteFast(P, V) \
|
||||
if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \
|
||||
BIT_WRITE(*__digitalPinToPortReg(P), __digitalPinToBit(P), (V)); \
|
||||
} else { \
|
||||
digitalWrite((P), (V)); \
|
||||
}
|
||||
#else
|
||||
#define digitalWriteFast digitalWrite
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef pinModeFast
|
||||
#if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR))
|
||||
#define pinModeFast(P, V) \
|
||||
if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \
|
||||
BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \
|
||||
} else { \
|
||||
pinMode((P), (V)); \
|
||||
}
|
||||
#else
|
||||
#define pinModeFast pinMode
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef digitalReadFast
|
||||
#if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR))
|
||||
#define digitalReadFast(P) ( (int) __digitalReadFast((P)) )
|
||||
#define __digitalReadFast(P ) \
|
||||
(__builtin_constant_p(P) ) ? ( \
|
||||
( BIT_READ(*__digitalPinToPINReg(P), __digitalPinToBit(P))) ) : \
|
||||
digitalRead((P))
|
||||
#else
|
||||
#define digitalReadFast digitalRead
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif //__digitalWriteFast_h_
|
||||
|
32
idle.ino
32
idle.ino
|
@ -32,7 +32,7 @@ void initialiseIdle()
|
|||
//Case 1 is on/off idle control
|
||||
if (currentStatus.coolant < configPage4.iacFastTemp)
|
||||
{
|
||||
digitalWrite(pinIdle1, HIGH);
|
||||
digitalWriteFast(pinIdle1, HIGH);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -122,10 +122,10 @@ void idleControl()
|
|||
case 1: //Case 1 is on/off idle control
|
||||
if ( (currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET) < configPage4.iacFastTemp) //All temps are offset by 40 degrees
|
||||
{
|
||||
digitalWrite(pinIdle1, HIGH);
|
||||
digitalWriteFast(pinIdle1, HIGH);
|
||||
idleOn = true;
|
||||
}
|
||||
else if (idleOn) { digitalWrite(pinIdle1, LOW); idleOn = false; }
|
||||
else if (idleOn) { digitalWriteFast(pinIdle1, LOW); idleOn = false; }
|
||||
break;
|
||||
|
||||
case 2: //Case 2 is PWM open loop
|
||||
|
@ -141,7 +141,7 @@ void idleControl()
|
|||
{
|
||||
//Standard running
|
||||
currentStatus.idleDuty = table2D_getValue(&iacPWMTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); //All temps are offset by 40 degrees
|
||||
if( currentStatus.idleDuty == 0 ) { TIMSK4 &= ~(1 << OCIE4C); digitalWrite(pinIdle1, LOW); break; }
|
||||
if( currentStatus.idleDuty == 0 ) { TIMSK4 &= ~(1 << OCIE4C); digitalWriteFast(pinIdle1, LOW); break; }
|
||||
TIMSK4 |= (1 << OCIE4C); //Turn on the C compare unit (ie turn on the interrupt)
|
||||
idle_pwm_target_value = percentage(currentStatus.idleDuty, idle_pwm_max_count);
|
||||
idleOn = true;
|
||||
|
@ -154,7 +154,7 @@ void idleControl()
|
|||
//idlePID.SetTunings(configPage3.idleKP, configPage3.idleKI, configPage3.idleKD);
|
||||
|
||||
idlePID.Compute();
|
||||
if( idle_pwm_target_value == 0 ) { TIMSK4 &= ~(1 << OCIE4C); digitalWrite(pinIdle1, LOW); }
|
||||
if( idle_pwm_target_value == 0 ) { TIMSK4 &= ~(1 << OCIE4C); digitalWriteFast(pinIdle1, LOW); }
|
||||
else{ TIMSK4 |= (1 << OCIE4C); } //Turn on the C compare unit (ie turn on the interrupt)
|
||||
//idle_pwm_target_value = 104;
|
||||
break;
|
||||
|
@ -168,7 +168,7 @@ void idleControl()
|
|||
if(idleStepper.stepperStatus == STEPPING)
|
||||
{
|
||||
//Means we're currently in a step, but it needs to be turned off
|
||||
digitalWrite(pinStepperStep, LOW); //Turn off the step
|
||||
digitalWriteFast(pinStepperStep, LOW); //Turn off the step
|
||||
idleStepper.stepStartTime = micros();
|
||||
idleStepper.stepperStatus = COOLING; //'Cooling' is the time the stepper needs to sit in LOW state before the next step can be made
|
||||
return;
|
||||
|
@ -192,10 +192,10 @@ void idleControl()
|
|||
//Currently cranking. Use the cranking table
|
||||
idleStepper.targetIdleStep = table2D_getValue(&iacCrankStepsTable, (currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET)) * 3; //All temps are offset by 40 degrees. Step counts are divided by 3 in TS. Multiply back out here
|
||||
if ( idleStepper.targetIdleStep > (idleStepper.curIdleStep - configPage4.iacStepHyster) && idleStepper.targetIdleStep < (idleStepper.curIdleStep + configPage4.iacStepHyster) ) { return; } //Hysteris check
|
||||
else if(idleStepper.targetIdleStep < idleStepper.curIdleStep) { digitalWrite(pinStepperDir, STEPPER_BACKWARD); idleStepper.curIdleStep--; }//Sets stepper direction to backwards
|
||||
else if (idleStepper.targetIdleStep > idleStepper.curIdleStep) { digitalWrite(pinStepperDir, STEPPER_FORWARD); idleStepper.curIdleStep++; }//Sets stepper direction to forwards
|
||||
else if(idleStepper.targetIdleStep < idleStepper.curIdleStep) { digitalWriteFast(pinStepperDir, STEPPER_BACKWARD); idleStepper.curIdleStep--; }//Sets stepper direction to backwards
|
||||
else if (idleStepper.targetIdleStep > idleStepper.curIdleStep) { digitalWriteFast(pinStepperDir, STEPPER_FORWARD); idleStepper.curIdleStep++; }//Sets stepper direction to forwards
|
||||
|
||||
digitalWrite(pinStepperStep, HIGH);
|
||||
digitalWriteFast(pinStepperStep, HIGH);
|
||||
idleStepper.stepStartTime = micros();
|
||||
idleStepper.stepperStatus = STEPPING;
|
||||
idleOn = true;
|
||||
|
@ -205,10 +205,10 @@ void idleControl()
|
|||
//Standard running
|
||||
idleStepper.targetIdleStep = table2D_getValue(&iacStepTable, (currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET)) * 3; //All temps are offset by 40 degrees. Step counts are divided by 3 in TS. Multiply back out here
|
||||
if ( idleStepper.targetIdleStep > (idleStepper.curIdleStep - configPage4.iacStepHyster) && idleStepper.targetIdleStep < (idleStepper.curIdleStep + configPage4.iacStepHyster) ) { return; } //Hysteris check
|
||||
else if(idleStepper.targetIdleStep < idleStepper.curIdleStep) { digitalWrite(pinStepperDir, STEPPER_BACKWARD); idleStepper.curIdleStep--; }//Sets stepper direction to backwards
|
||||
else if (idleStepper.targetIdleStep > idleStepper.curIdleStep) { digitalWrite(pinStepperDir, STEPPER_FORWARD); idleStepper.curIdleStep++; }//Sets stepper direction to forwards
|
||||
else if(idleStepper.targetIdleStep < idleStepper.curIdleStep) { digitalWriteFast(pinStepperDir, STEPPER_BACKWARD); idleStepper.curIdleStep--; }//Sets stepper direction to backwards
|
||||
else if (idleStepper.targetIdleStep > idleStepper.curIdleStep) { digitalWriteFast(pinStepperDir, STEPPER_FORWARD); idleStepper.curIdleStep++; }//Sets stepper direction to forwards
|
||||
|
||||
digitalWrite(pinStepperStep, HIGH);
|
||||
digitalWriteFast(pinStepperStep, HIGH);
|
||||
idleStepper.stepStartTime = micros();
|
||||
idleStepper.stepperStatus = STEPPING;
|
||||
idleOn = true;
|
||||
|
@ -224,15 +224,15 @@ A simple function to home the stepper motor (If in use)
|
|||
void homeStepper()
|
||||
{
|
||||
//Need to 'home' the stepper on startup
|
||||
digitalWrite(pinStepperDir, STEPPER_BACKWARD); //Sets stepper direction to backwards
|
||||
digitalWriteFast(pinStepperDir, STEPPER_BACKWARD); //Sets stepper direction to backwards
|
||||
for(int x=0; x < (configPage4.iacStepHome * 3); x++) //Step counts are divided by 3 in TS. Multiply back out here
|
||||
{
|
||||
digitalWrite(pinStepperStep, HIGH);
|
||||
digitalWriteFast(pinStepperStep, HIGH);
|
||||
delayMicroseconds(iacStepTime);
|
||||
digitalWrite(pinStepperStep, LOW);
|
||||
digitalWriteFast(pinStepperStep, LOW);
|
||||
delayMicroseconds(iacStepTime);
|
||||
}
|
||||
digitalWrite(pinStepperDir, STEPPER_FORWARD);
|
||||
digitalWriteFast(pinStepperDir, STEPPER_FORWARD);
|
||||
idleStepper.curIdleStep = 0;
|
||||
idleStepper.targetIdleStep = 0;
|
||||
idleStepper.stepperStatus = SOFF;
|
||||
|
|
111
speeduino.ino
111
speeduino.ino
|
@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
//**************************************************************************************************
|
||||
|
||||
#include "globals.h"
|
||||
#include "digitalWriteFast.h"
|
||||
#include "utils.h"
|
||||
#include "table.h"
|
||||
#include "scheduler.h"
|
||||
|
@ -201,21 +202,21 @@ void setup()
|
|||
//Need to check early on whether the coil charging is inverted. If this is not set straight away it can cause an unwanted spark at bootup
|
||||
if(configPage2.IgInv == 1) { coilHIGH = LOW, coilLOW = HIGH; }
|
||||
else { coilHIGH = HIGH, coilLOW = LOW; }
|
||||
endCoil1Charge(); //digitalWrite(pinCoil1, coilLOW);
|
||||
endCoil2Charge(); //digitalWrite(pinCoil2, coilLOW);
|
||||
endCoil3Charge(); //digitalWrite(pinCoil3, coilLOW);
|
||||
endCoil4Charge(); //digitalWrite(pinCoil4, coilLOW);
|
||||
endCoil5Charge(); //digitalWrite(pinCoil5, coilLOW);
|
||||
endCoil1Charge(); //digitalWriteFast(pinCoil1, coilLOW);
|
||||
endCoil2Charge(); //digitalWriteFast(pinCoil2, coilLOW);
|
||||
endCoil3Charge(); //digitalWriteFast(pinCoil3, coilLOW);
|
||||
endCoil4Charge(); //digitalWriteFast(pinCoil4, coilLOW);
|
||||
endCoil5Charge(); //digitalWriteFast(pinCoil5, coilLOW);
|
||||
|
||||
//Similar for injectors, make sure they're turned off
|
||||
closeInjector1(); //digitalWrite(pinInjector1, HIGH);
|
||||
closeInjector2(); //digitalWrite(pinInjector2, HIGH);
|
||||
closeInjector3(); //digitalWrite(pinInjector3, HIGH);
|
||||
closeInjector4(); //digitalWrite(pinInjector4, HIGH);
|
||||
closeInjector5(); //digitalWrite(pinInjector5, HIGH);
|
||||
closeInjector1(); //digitalWriteFast(pinInjector1, HIGH);
|
||||
closeInjector2(); //digitalWriteFast(pinInjector2, HIGH);
|
||||
closeInjector3(); //digitalWriteFast(pinInjector3, HIGH);
|
||||
closeInjector4(); //digitalWriteFast(pinInjector4, HIGH);
|
||||
closeInjector5(); //digitalWriteFast(pinInjector5, HIGH);
|
||||
|
||||
//Set the tacho output default state
|
||||
digitalWrite(pinTachOut, HIGH);
|
||||
digitalWriteFast(pinTachOut, HIGH);
|
||||
|
||||
//Lookup the current MAP reading for barometric pressure
|
||||
readMAP();
|
||||
|
@ -284,10 +285,10 @@ void setup()
|
|||
triggerInterrupt2 = 2; break;
|
||||
|
||||
}
|
||||
pinMode(pinTrigger, INPUT);
|
||||
pinMode(pinTrigger2, INPUT);
|
||||
pinMode(pinTrigger3, INPUT);
|
||||
//digitalWrite(pinTrigger, HIGH);
|
||||
pinModeFast(pinTrigger, INPUT);
|
||||
pinModeFast(pinTrigger2, INPUT);
|
||||
pinModeFast(pinTrigger3, INPUT);
|
||||
//digitalWriteFast(pinTrigger, HIGH);
|
||||
|
||||
|
||||
//Set the trigger function based on the decoder in the config
|
||||
|
@ -754,7 +755,7 @@ void setup()
|
|||
}
|
||||
|
||||
//Begin priming the fuel pump. This is turned off in the low resolution, 1s interrupt in timers.ino
|
||||
digitalWrite(pinFuelPump, HIGH);
|
||||
digitalWriteFast(pinFuelPump, HIGH);
|
||||
fuelPumpOn = true;
|
||||
//Perform the 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
|
||||
setFuelSchedule1(openInjector1and4, 100, (unsigned long)(configPage1.primePulse * 100), closeInjector1and4);
|
||||
|
@ -797,7 +798,7 @@ void loop()
|
|||
{
|
||||
int lastRPM = currentStatus.RPM; //Need to record this for rpmDOT calculation
|
||||
currentStatus.RPM = currentStatus.longRPM = getRPM(); //Long RPM is included here
|
||||
if(fuelPumpOn == false) { digitalWrite(pinFuelPump, HIGH); fuelPumpOn = true; } //Check if the fuel pump is on and turn it on if it isn't.
|
||||
if(fuelPumpOn == false) { digitalWriteFast(pinFuelPump, HIGH); fuelPumpOn = true; } //Check if the fuel pump is on and turn it on if it isn't.
|
||||
currentStatus.rpmDOT = ldiv(1000000, (currentLoopTime - previousLoopTime)).quot * (currentStatus.RPM - lastRPM); //This is the RPM per second that the engine has accelerated/decelleratedin the last loop
|
||||
}
|
||||
else
|
||||
|
@ -815,9 +816,9 @@ void loop()
|
|||
currentStatus.rpmDOT = 0;
|
||||
ignitionOn = false;
|
||||
fuelOn = false;
|
||||
if (fpPrimed) { digitalWrite(pinFuelPump, LOW); } //Turn off the fuel pump, but only if the priming is complete
|
||||
if (fpPrimed) { digitalWriteFast(pinFuelPump, LOW); } //Turn off the fuel pump, but only if the priming is complete
|
||||
fuelPumpOn = false;
|
||||
TIMSK4 &= ~(1 << OCIE4C); digitalWrite(pinIdle1, LOW); //Turns off the idle control PWM. This REALLY needs to be cleaned up into a general PWM controller class
|
||||
TIMSK4 &= ~(1 << OCIE4C); digitalWriteFast(pinIdle1, LOW); //Turns off the idle control PWM. This REALLY needs to be cleaned up into a general PWM controller class
|
||||
}
|
||||
|
||||
//Uncomment the following for testing
|
||||
|
@ -837,8 +838,8 @@ void loop()
|
|||
|
||||
//Check for launching (clutch) can be done around here too
|
||||
bool launchTrigger;
|
||||
if(configPage3.launchHiLo) { launchTrigger = digitalRead(pinLaunch); }
|
||||
else { launchTrigger = !digitalRead(pinLaunch); }
|
||||
if(configPage3.launchHiLo) { launchTrigger = digitalReadFast(pinLaunch); }
|
||||
else { launchTrigger = !digitalReadFast(pinLaunch); }
|
||||
if (configPage3.launchEnabled && launchTrigger && (currentStatus.RPM > ((unsigned int)(configPage3.lnchSoftLim) * 100)) ) { currentStatus.launchingSoft = true; BIT_SET(currentStatus.spark, BIT_SPARK_SLAUNCH); } //SoftCut rev limit for 2-step launch control.
|
||||
else { currentStatus.launchingSoft = false; BIT_CLEAR(currentStatus.spark, BIT_SPARK_SLAUNCH); }
|
||||
if (configPage3.launchEnabled && launchTrigger && (currentStatus.RPM > ((unsigned int)(configPage3.lnchHardLim) * 100)) ) { currentStatus.launchingHard = true; BIT_SET(currentStatus.spark, BIT_SPARK_HLAUNCH); } //HardCut rev limit for 2-step launch control.
|
||||
|
@ -900,7 +901,7 @@ void loop()
|
|||
if( BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) )
|
||||
{
|
||||
BIT_CLEAR(currentStatus.engine, BIT_ENGINE_CRANK); //clears the engine cranking bit
|
||||
if(configPage2.ignBypassEnabled) { digitalWrite(pinIgnBypass, HIGH); }
|
||||
if(configPage2.ignBypassEnabled) { digitalWriteFast(pinIgnBypass, HIGH); }
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -908,7 +909,7 @@ void loop()
|
|||
BIT_SET(currentStatus.engine, BIT_ENGINE_CRANK);
|
||||
BIT_CLEAR(currentStatus.engine, BIT_ENGINE_RUN);
|
||||
currentStatus.runSecs = 0; //We're cranking (hopefully), so reset the engine run time to prompt ASE.
|
||||
if(configPage2.ignBypassEnabled) { digitalWrite(pinIgnBypass, LOW); }
|
||||
if(configPage2.ignBypassEnabled) { digitalWriteFast(pinIgnBypass, LOW); }
|
||||
}
|
||||
|
||||
//END SETTING STATUSES
|
||||
|
@ -1412,63 +1413,63 @@ void loop()
|
|||
|
||||
void openInjector1() { *inj1_pin_port |= (inj1_pin_mask); ; BIT_SET(currentStatus.squirt, BIT_SQUIRT_INJ1); }
|
||||
void closeInjector1() { *inj1_pin_port &= ~(inj1_pin_mask); BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_INJ1); }
|
||||
void beginCoil1Charge() { *ign1_pin_port |= (ign1_pin_mask); BIT_SET(currentStatus.spark, 0); digitalWrite(pinTachOut, LOW); }
|
||||
void beginCoil1Charge() { *ign1_pin_port |= (ign1_pin_mask); BIT_SET(currentStatus.spark, 0); digitalWriteFast(pinTachOut, LOW); }
|
||||
void endCoil1Charge() { *ign1_pin_port &= ~(ign1_pin_mask); BIT_CLEAR(currentStatus.spark, 0); }
|
||||
|
||||
void openInjector2() { *inj2_pin_port |= (inj2_pin_mask); ; BIT_SET(currentStatus.squirt, BIT_SQUIRT_INJ2); }
|
||||
void closeInjector2() { *inj2_pin_port &= ~(inj2_pin_mask); BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_INJ2); }
|
||||
void beginCoil2Charge() { *ign2_pin_port |= (ign2_pin_mask); BIT_SET(currentStatus.spark, 1); digitalWrite(pinTachOut, LOW); }
|
||||
void beginCoil2Charge() { *ign2_pin_port |= (ign2_pin_mask); BIT_SET(currentStatus.spark, 1); digitalWriteFast(pinTachOut, LOW); }
|
||||
void endCoil2Charge() { *ign2_pin_port &= ~(ign2_pin_mask); BIT_CLEAR(currentStatus.spark, 1);}
|
||||
|
||||
void openInjector3() { *inj3_pin_port |= (inj3_pin_mask); ; BIT_SET(currentStatus.squirt, BIT_SQUIRT_INJ3); }
|
||||
void closeInjector3() { *inj3_pin_port &= ~(inj3_pin_mask); BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_INJ3); }
|
||||
void beginCoil3Charge() { *ign3_pin_port |= (ign3_pin_mask); BIT_SET(currentStatus.spark, 2); digitalWrite(pinTachOut, LOW); }
|
||||
void beginCoil3Charge() { *ign3_pin_port |= (ign3_pin_mask); BIT_SET(currentStatus.spark, 2); digitalWriteFast(pinTachOut, LOW); }
|
||||
void endCoil3Charge() { *ign3_pin_port &= ~(ign3_pin_mask); BIT_CLEAR(currentStatus.spark, 2);}
|
||||
|
||||
void openInjector4() { *inj4_pin_port |= (inj4_pin_mask); ; BIT_SET(currentStatus.squirt, BIT_SQUIRT_INJ4); }
|
||||
void closeInjector4() { *inj4_pin_port &= ~(inj4_pin_mask); BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_INJ4); }
|
||||
void beginCoil4Charge() { *ign4_pin_port |= (ign4_pin_mask); BIT_SET(currentStatus.spark, 3); digitalWrite(pinTachOut, LOW); }
|
||||
void beginCoil4Charge() { *ign4_pin_port |= (ign4_pin_mask); BIT_SET(currentStatus.spark, 3); digitalWriteFast(pinTachOut, LOW); }
|
||||
void endCoil4Charge() { *ign4_pin_port &= ~(ign4_pin_mask); BIT_CLEAR(currentStatus.spark, 3);}
|
||||
|
||||
#else */
|
||||
inline void openInjector1() { digitalWrite(pinInjector1, HIGH); BIT_SET(currentStatus.squirt, BIT_SQUIRT_INJ1); }
|
||||
inline void closeInjector1() { digitalWrite(pinInjector1, LOW); BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_INJ1); }
|
||||
inline void beginCoil1Charge() { digitalWrite(pinCoil1, coilHIGH); digitalWrite(pinTachOut, LOW); }
|
||||
inline void endCoil1Charge() { digitalWrite(pinCoil1, coilLOW); }
|
||||
inline void openInjector1() { digitalWriteFast(pinInjector1, HIGH); BIT_SET(currentStatus.squirt, BIT_SQUIRT_INJ1); }
|
||||
inline void closeInjector1() { digitalWriteFast(pinInjector1, LOW); BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_INJ1); }
|
||||
inline void beginCoil1Charge() { digitalWriteFast(pinCoil1, coilHIGH); digitalWriteFast(pinTachOut, LOW); }
|
||||
inline void endCoil1Charge() { digitalWriteFast(pinCoil1, coilLOW); }
|
||||
|
||||
inline void openInjector2() { digitalWrite(pinInjector2, HIGH); BIT_SET(currentStatus.squirt, BIT_SQUIRT_INJ2); } //Sets the relevant pin HIGH and changes the current status bit for injector 2 (2nd bit of currentStatus.squirt)
|
||||
inline void closeInjector2() { digitalWrite(pinInjector2, LOW); BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_INJ2); }
|
||||
inline void beginCoil2Charge() { digitalWrite(pinCoil2, coilHIGH); digitalWrite(pinTachOut, LOW); }
|
||||
inline void endCoil2Charge() { digitalWrite(pinCoil2, coilLOW); }
|
||||
inline void openInjector2() { digitalWriteFast(pinInjector2, HIGH); BIT_SET(currentStatus.squirt, BIT_SQUIRT_INJ2); } //Sets the relevant pin HIGH and changes the current status bit for injector 2 (2nd bit of currentStatus.squirt)
|
||||
inline void closeInjector2() { digitalWriteFast(pinInjector2, LOW); BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_INJ2); }
|
||||
inline void beginCoil2Charge() { digitalWriteFast(pinCoil2, coilHIGH); digitalWriteFast(pinTachOut, LOW); }
|
||||
inline void endCoil2Charge() { digitalWriteFast(pinCoil2, coilLOW); }
|
||||
|
||||
inline void openInjector3() { digitalWrite(pinInjector3, HIGH); BIT_SET(currentStatus.squirt, BIT_SQUIRT_INJ3); } //Sets the relevant pin HIGH and changes the current status bit for injector 3 (3rd bit of currentStatus.squirt)
|
||||
inline void closeInjector3() { digitalWrite(pinInjector3, LOW); BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_INJ3); }
|
||||
inline void beginCoil3Charge() { digitalWrite(pinCoil3, coilHIGH); digitalWrite(pinTachOut, LOW); }
|
||||
inline void endCoil3Charge() { digitalWrite(pinCoil3, coilLOW); }
|
||||
inline void openInjector3() { digitalWriteFast(pinInjector3, HIGH); BIT_SET(currentStatus.squirt, BIT_SQUIRT_INJ3); } //Sets the relevant pin HIGH and changes the current status bit for injector 3 (3rd bit of currentStatus.squirt)
|
||||
inline void closeInjector3() { digitalWriteFast(pinInjector3, LOW); BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_INJ3); }
|
||||
inline void beginCoil3Charge() { digitalWriteFast(pinCoil3, coilHIGH); digitalWriteFast(pinTachOut, LOW); }
|
||||
inline void endCoil3Charge() { digitalWriteFast(pinCoil3, coilLOW); }
|
||||
|
||||
inline void openInjector4() { digitalWrite(pinInjector4, HIGH); BIT_SET(currentStatus.squirt, BIT_SQUIRT_INJ4); } //Sets the relevant pin HIGH and changes the current status bit for injector 4 (4th bit of currentStatus.squirt)
|
||||
inline void closeInjector4() { digitalWrite(pinInjector4, LOW); BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_INJ4); }
|
||||
inline void beginCoil4Charge() { digitalWrite(pinCoil4, coilHIGH); digitalWrite(pinTachOut, LOW); }
|
||||
inline void endCoil4Charge() { digitalWrite(pinCoil4, coilLOW); }
|
||||
inline void openInjector4() { digitalWriteFast(pinInjector4, HIGH); BIT_SET(currentStatus.squirt, BIT_SQUIRT_INJ4); } //Sets the relevant pin HIGH and changes the current status bit for injector 4 (4th bit of currentStatus.squirt)
|
||||
inline void closeInjector4() { digitalWriteFast(pinInjector4, LOW); BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_INJ4); }
|
||||
inline void beginCoil4Charge() { digitalWriteFast(pinCoil4, coilHIGH); digitalWriteFast(pinTachOut, LOW); }
|
||||
inline void endCoil4Charge() { digitalWriteFast(pinCoil4, coilLOW); }
|
||||
|
||||
inline void openInjector5() { digitalWrite(pinInjector5, HIGH); }
|
||||
inline void closeInjector5() { digitalWrite(pinInjector5, LOW); }
|
||||
inline void beginCoil5Charge() { digitalWrite(pinCoil5, coilHIGH); digitalWrite(pinTachOut, LOW); }
|
||||
inline void endCoil5Charge() { digitalWrite(pinCoil5, coilLOW); }
|
||||
inline void openInjector5() { digitalWriteFast(pinInjector5, HIGH); }
|
||||
inline void closeInjector5() { digitalWriteFast(pinInjector5, LOW); }
|
||||
inline void beginCoil5Charge() { digitalWriteFast(pinCoil5, coilHIGH); digitalWriteFast(pinTachOut, LOW); }
|
||||
inline void endCoil5Charge() { digitalWriteFast(pinCoil5, coilLOW); }
|
||||
|
||||
//#endif
|
||||
|
||||
|
||||
//Combination functions for semi-sequential injection
|
||||
void openInjector1and4() { digitalWrite(pinInjector1, HIGH); digitalWrite(pinInjector4, HIGH); BIT_SET(currentStatus.squirt, 0); }
|
||||
void closeInjector1and4() { digitalWrite(pinInjector1, LOW); digitalWrite(pinInjector4, LOW);BIT_CLEAR(currentStatus.squirt, 0); }
|
||||
void openInjector2and3() { digitalWrite(pinInjector2, HIGH); digitalWrite(pinInjector3, HIGH); BIT_SET(currentStatus.squirt, 1); }
|
||||
void closeInjector2and3() { digitalWrite(pinInjector2, LOW); digitalWrite(pinInjector3, LOW); BIT_CLEAR(currentStatus.squirt, 1); }
|
||||
void openInjector1and4() { digitalWriteFast(pinInjector1, HIGH); digitalWriteFast(pinInjector4, HIGH); BIT_SET(currentStatus.squirt, 0); }
|
||||
void closeInjector1and4() { digitalWriteFast(pinInjector1, LOW); digitalWriteFast(pinInjector4, LOW);BIT_CLEAR(currentStatus.squirt, 0); }
|
||||
void openInjector2and3() { digitalWriteFast(pinInjector2, HIGH); digitalWriteFast(pinInjector3, HIGH); BIT_SET(currentStatus.squirt, 1); }
|
||||
void closeInjector2and3() { digitalWriteFast(pinInjector2, LOW); digitalWriteFast(pinInjector3, LOW); BIT_CLEAR(currentStatus.squirt, 1); }
|
||||
|
||||
//As above but for ignition (Wasted COP mode)
|
||||
void beginCoil1and3Charge() { digitalWrite(pinCoil1, coilHIGH); digitalWrite(pinCoil3, coilHIGH); digitalWrite(pinTachOut, LOW); }
|
||||
void endCoil1and3Charge() { digitalWrite(pinCoil1, coilLOW); digitalWrite(pinCoil3, coilLOW); }
|
||||
void beginCoil2and4Charge() { digitalWrite(pinCoil2, coilHIGH); digitalWrite(pinCoil4, coilHIGH); digitalWrite(pinTachOut, LOW); }
|
||||
void endCoil2and4Charge() { digitalWrite(pinCoil2, coilLOW); digitalWrite(pinCoil4, coilLOW); }
|
||||
void beginCoil1and3Charge() { digitalWriteFast(pinCoil1, coilHIGH); digitalWriteFast(pinCoil3, coilHIGH); digitalWriteFast(pinTachOut, LOW); }
|
||||
void endCoil1and3Charge() { digitalWriteFast(pinCoil1, coilLOW); digitalWriteFast(pinCoil3, coilLOW); }
|
||||
void beginCoil2and4Charge() { digitalWriteFast(pinCoil2, coilHIGH); digitalWriteFast(pinCoil4, coilHIGH); digitalWriteFast(pinTachOut, LOW); }
|
||||
void endCoil2and4Charge() { digitalWriteFast(pinCoil2, coilLOW); digitalWriteFast(pinCoil4, coilLOW); }
|
||||
|
||||
void nullCallback() { return; }
|
||||
|
|
10
timers.ino
10
timers.ino
|
@ -47,10 +47,10 @@ void timer2Overflowinterrupt() //Most ARM chips can simply call a function
|
|||
targetOverdwellTime = micros() - (1000 * configPage2.dwellLimit); //Set a target time in the past that all coil charging must have begun after. If the coil charge began before this time, it's been running too long
|
||||
targetTachoPulseTime = micros() - (1500);
|
||||
//Check first whether each spark output is currently on. Only check it's dwell time if it is
|
||||
if(ignitionSchedule1.Status == RUNNING) { if(ignitionSchedule1.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil1Charge(); } if(ignitionSchedule1.startTime < targetTachoPulseTime) { digitalWrite(pinTachOut, HIGH); } }
|
||||
if(ignitionSchedule2.Status == RUNNING) { if(ignitionSchedule2.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil2Charge(); } if(ignitionSchedule2.startTime < targetTachoPulseTime) { digitalWrite(pinTachOut, HIGH); } }
|
||||
if(ignitionSchedule3.Status == RUNNING) { if(ignitionSchedule3.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil3Charge(); } if(ignitionSchedule3.startTime < targetTachoPulseTime) { digitalWrite(pinTachOut, HIGH); } }
|
||||
if(ignitionSchedule4.Status == RUNNING) { if(ignitionSchedule4.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil4Charge(); } if(ignitionSchedule4.startTime < targetTachoPulseTime) { digitalWrite(pinTachOut, HIGH); } }
|
||||
if(ignitionSchedule1.Status == RUNNING) { if(ignitionSchedule1.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil1Charge(); } if(ignitionSchedule1.startTime < targetTachoPulseTime) { digitalWriteFast(pinTachOut, HIGH); } }
|
||||
if(ignitionSchedule2.Status == RUNNING) { if(ignitionSchedule2.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil2Charge(); } if(ignitionSchedule2.startTime < targetTachoPulseTime) { digitalWriteFast(pinTachOut, HIGH); } }
|
||||
if(ignitionSchedule3.Status == RUNNING) { if(ignitionSchedule3.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil3Charge(); } if(ignitionSchedule3.startTime < targetTachoPulseTime) { digitalWriteFast(pinTachOut, HIGH); } }
|
||||
if(ignitionSchedule4.Status == RUNNING) { if(ignitionSchedule4.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil4Charge(); } if(ignitionSchedule4.startTime < targetTachoPulseTime) { digitalWriteFast(pinTachOut, HIGH); } }
|
||||
|
||||
//Loop executed every 250ms loop (1ms x 250 = 250ms)
|
||||
//Anything inside this if statement will run every 250ms.
|
||||
|
@ -92,7 +92,7 @@ void timer2Overflowinterrupt() //Most ARM chips can simply call a function
|
|||
if(currentStatus.secl >= configPage1.fpPrime)
|
||||
{
|
||||
fpPrimed = true; //Mark the priming as being completed
|
||||
if(currentStatus.RPM == 0) { digitalWrite(pinFuelPump, LOW); fuelPumpOn = false; } //If we reach here then the priming is complete, however only turn off the fuel pump if the engine isn't running
|
||||
if(currentStatus.RPM == 0) { digitalWriteFast(pinFuelPump, LOW); fuelPumpOn = false; } //If we reach here then the priming is complete, however only turn off the fuel pump if the engine isn't running
|
||||
}
|
||||
}
|
||||
//**************************************************************************************************************************************************
|
||||
|
|
67
utils.ino
67
utils.ino
|
@ -8,6 +8,7 @@ A full copy of the license may be found in the projects root directory
|
|||
/*
|
||||
Returns how much free dynamic memory exists (between heap and stack)
|
||||
*/
|
||||
#include "digitalWriteFast.h"
|
||||
#include "utils.h"
|
||||
|
||||
int freeRam ()
|
||||
|
@ -311,22 +312,22 @@ void setPinMapping(byte boardID)
|
|||
if(configPage1.tachoPin != 0) { pinTachOut = configPage1.tachoPin; }
|
||||
|
||||
//Finally, set the relevant pin modes for outputs
|
||||
pinMode(pinCoil1, OUTPUT);
|
||||
pinMode(pinCoil2, OUTPUT);
|
||||
pinMode(pinCoil3, OUTPUT);
|
||||
pinMode(pinCoil4, OUTPUT);
|
||||
pinMode(pinCoil5, OUTPUT);
|
||||
pinMode(pinInjector1, OUTPUT);
|
||||
pinMode(pinInjector2, OUTPUT);
|
||||
pinMode(pinInjector3, OUTPUT);
|
||||
pinMode(pinInjector4, OUTPUT);
|
||||
pinMode(pinInjector5, OUTPUT);
|
||||
pinMode(pinTachOut, OUTPUT);
|
||||
pinMode(pinIdle1, OUTPUT);
|
||||
pinMode(pinIdle2, OUTPUT);
|
||||
pinMode(pinFuelPump, OUTPUT);
|
||||
pinMode(pinIgnBypass, OUTPUT);
|
||||
pinMode(pinFan, OUTPUT);
|
||||
pinModeFast(pinCoil1, OUTPUT);
|
||||
pinModeFast(pinCoil2, OUTPUT);
|
||||
pinModeFast(pinCoil3, OUTPUT);
|
||||
pinModeFast(pinCoil4, OUTPUT);
|
||||
pinModeFast(pinCoil5, OUTPUT);
|
||||
pinModeFast(pinInjector1, OUTPUT);
|
||||
pinModeFast(pinInjector2, OUTPUT);
|
||||
pinModeFast(pinInjector3, OUTPUT);
|
||||
pinModeFast(pinInjector4, OUTPUT);
|
||||
pinModeFast(pinInjector5, OUTPUT);
|
||||
pinModeFast(pinTachOut, OUTPUT);
|
||||
pinModeFast(pinIdle1, OUTPUT);
|
||||
pinModeFast(pinIdle2, OUTPUT);
|
||||
pinModeFast(pinFuelPump, OUTPUT);
|
||||
pinModeFast(pinIgnBypass, OUTPUT);
|
||||
pinModeFast(pinFan, OUTPUT);
|
||||
|
||||
inj1_pin_port = portOutputRegister(digitalPinToPort(pinInjector1));
|
||||
inj1_pin_mask = digitalPinToBitMask(pinInjector1);
|
||||
|
@ -351,25 +352,25 @@ void setPinMapping(byte boardID)
|
|||
ign5_pin_mask = digitalPinToBitMask(pinCoil5);
|
||||
|
||||
//And for inputs
|
||||
pinMode(pinMAP, INPUT);
|
||||
pinMode(pinO2, INPUT);
|
||||
pinMode(pinO2_2, INPUT);
|
||||
pinMode(pinTPS, INPUT);
|
||||
pinMode(pinIAT, INPUT);
|
||||
pinMode(pinCLT, INPUT);
|
||||
pinMode(pinBat, INPUT);
|
||||
pinMode(pinTrigger, INPUT);
|
||||
pinMode(pinTrigger2, INPUT);
|
||||
pinMode(pinTrigger3, INPUT);
|
||||
pinMode(pinFlex, INPUT_PULLUP); //Standard GM / Continental flex sensor requires pullup
|
||||
// pinMode(pinLaunch, INPUT_PULLUP); //This should work for both NO and NC grounding switches
|
||||
if (configPage3.lnchPullRes) { pinMode(pinLaunch, INPUT_PULLUP); }
|
||||
else { pinMode(pinLaunch, INPUT); } //If Launch Pull Resistor is not set make input float.
|
||||
pinModeFast(pinMAP, INPUT);
|
||||
pinModeFast(pinO2, INPUT);
|
||||
pinModeFast(pinO2_2, INPUT);
|
||||
pinModeFast(pinTPS, INPUT);
|
||||
pinModeFast(pinIAT, INPUT);
|
||||
pinModeFast(pinCLT, INPUT);
|
||||
pinModeFast(pinBat, INPUT);
|
||||
pinModeFast(pinTrigger, INPUT);
|
||||
pinModeFast(pinTrigger2, INPUT);
|
||||
pinModeFast(pinTrigger3, INPUT);
|
||||
pinModeFast(pinFlex, INPUT_PULLUP); //Standard GM / Continental flex sensor requires pullup
|
||||
// pinModeFast(pinLaunch, INPUT_PULLUP); //This should work for both NO and NC grounding switches
|
||||
if (configPage3.lnchPullRes) { pinModeFast(pinLaunch, INPUT_PULLUP); }
|
||||
else { pinModeFast(pinLaunch, INPUT); } //If Launch Pull Resistor is not set make input float.
|
||||
|
||||
//Set default values
|
||||
digitalWrite(pinMAP, HIGH);
|
||||
//digitalWrite(pinO2, LOW);
|
||||
digitalWrite(pinTPS, LOW);
|
||||
digitalWriteFast(pinMAP, HIGH);
|
||||
//digitalWriteFast(pinO2, LOW);
|
||||
digitalWriteFast(pinTPS, LOW);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue