2016-06-24 01:02:53 -07:00
|
|
|
#ifndef SENSORS_H
|
|
|
|
#define SENSORS_H
|
|
|
|
|
2023-11-30 19:56:14 -08:00
|
|
|
#include "globals.h"
|
2017-02-13 20:21:38 -08:00
|
|
|
|
2017-02-08 19:17:20 -08:00
|
|
|
// The following are alpha values for the ADC filters.
|
2021-12-21 12:56:55 -08:00
|
|
|
// Their values are from 0 to 240, with 0 being no filtering and 240 being maximum
|
|
|
|
#define ADCFILTER_TPS_DEFAULT 50
|
|
|
|
#define ADCFILTER_CLT_DEFAULT 180
|
|
|
|
#define ADCFILTER_IAT_DEFAULT 180
|
|
|
|
#define ADCFILTER_O2_DEFAULT 128
|
|
|
|
#define ADCFILTER_BAT_DEFAULT 128
|
|
|
|
#define ADCFILTER_MAP_DEFAULT 20 //This is only used on Instantaneous MAP readings and is intentionally very weak to allow for faster response
|
|
|
|
#define ADCFILTER_BARO_DEFAULT 64
|
|
|
|
|
|
|
|
#define ADCFILTER_PSI_DEFAULT 150 //not currently configurable at runtime, used for misc pressure sensors, oil, fuel, etc.
|
|
|
|
|
|
|
|
#define FILTER_FLEX_DEFAULT 75
|
2016-03-08 21:40:11 -08:00
|
|
|
|
2020-12-01 16:06:24 -08:00
|
|
|
#define BARO_MIN 65
|
2016-10-25 16:30:12 -07:00
|
|
|
#define BARO_MAX 108
|
|
|
|
|
2018-08-13 19:47:15 -07:00
|
|
|
#define KNOCK_MODE_DIGITAL 1
|
|
|
|
#define KNOCK_MODE_ANALOG 2
|
|
|
|
|
2020-05-18 21:44:28 -07:00
|
|
|
#define VSS_GEAR_HYSTERESIS 10
|
2020-08-09 15:54:53 -07:00
|
|
|
#define VSS_SAMPLES 4 //Must be a power of 2 and smaller than 255
|
2020-04-20 06:43:02 -07:00
|
|
|
|
2022-01-01 00:30:21 -08:00
|
|
|
#define TPS_READ_FREQUENCY 30 //ONLY VALID VALUES ARE 15 or 30!!!
|
2021-01-21 21:31:14 -08:00
|
|
|
|
2023-10-06 00:10:20 -07:00
|
|
|
extern volatile byte flexCounter;
|
|
|
|
extern volatile unsigned long flexStartTime;
|
|
|
|
extern volatile unsigned long flexPulseWidth;
|
2020-08-17 19:34:56 -07:00
|
|
|
|
|
|
|
#if defined(CORE_AVR)
|
|
|
|
#define READ_FLEX() ((*flex_pin_port & flex_pin_mask) ? true : false)
|
|
|
|
#else
|
|
|
|
#define READ_FLEX() digitalRead(pinFlex)
|
|
|
|
#endif
|
|
|
|
|
2023-12-04 22:35:45 -08:00
|
|
|
#define ADMUX_DEFAULT_CONFIG 0x40 //AVCC reference, ADC0 input, right adjusted, ADC enabled
|
|
|
|
|
2023-10-06 00:10:20 -07:00
|
|
|
extern volatile byte knockCounter;
|
2016-11-06 05:31:18 -08:00
|
|
|
|
2023-10-06 00:10:20 -07:00
|
|
|
extern unsigned int MAPcount; //Number of samples taken in the current MAP cycle
|
|
|
|
extern uint32_t MAPcurRev; //Tracks which revolution we're sampling on
|
|
|
|
extern bool auxIsEnabled;
|
|
|
|
extern uint16_t MAPlast; /**< The previous MAP reading */
|
|
|
|
extern unsigned long MAP_time; //The time the MAP sample was taken
|
|
|
|
extern unsigned long MAPlast_time; //The time the previous MAP sample was taken
|
2017-01-17 22:37:55 -08:00
|
|
|
|
2019-04-16 00:33:56 -07:00
|
|
|
/**
|
|
|
|
* @brief Simple low pass IIR filter macro for the analog inputs
|
2019-10-21 18:49:07 -07:00
|
|
|
* This is effectively implementing the smooth filter from playground.arduino.cc/Main/Smooth
|
2017-02-08 19:17:20 -08:00
|
|
|
* But removes the use of floats and uses 8 bits of fixed precision.
|
2016-03-08 21:40:11 -08:00
|
|
|
*/
|
|
|
|
#define ADC_FILTER(input, alpha, prior) (((long)input * (256 - alpha) + ((long)prior * alpha))) >> 8
|
|
|
|
|
2022-11-05 15:43:29 -07:00
|
|
|
void initialiseADC(void);
|
|
|
|
void readTPS(bool useFilter=true); //Allows the option to override the use of the filter
|
|
|
|
void readO2_2(void);
|
|
|
|
void flexPulse(void);
|
|
|
|
uint32_t vssGetPulseGap(byte toothHistoryIndex);
|
|
|
|
void vssPulse(void);
|
|
|
|
uint16_t getSpeed(void);
|
|
|
|
byte getGear(void);
|
|
|
|
byte getFuelPressure(void);
|
|
|
|
byte getOilPressure(void);
|
2018-06-29 15:03:56 -07:00
|
|
|
uint16_t readAuxanalog(uint8_t analogPin);
|
|
|
|
uint16_t readAuxdigital(uint8_t digitalPin);
|
2022-11-05 15:43:29 -07:00
|
|
|
void readCLT(bool useFilter=true); //Allows the option to override the use of the filter
|
|
|
|
void readIAT(void);
|
|
|
|
void readO2(void);
|
|
|
|
void readBat(void);
|
|
|
|
void readBaro(void);
|
2023-10-06 00:10:20 -07:00
|
|
|
void readMAP(void);
|
|
|
|
void instanteneousMAPReading(void);
|
2017-11-07 03:05:23 -08:00
|
|
|
|
2016-06-24 01:02:53 -07:00
|
|
|
#endif // SENSORS_H
|