Speeduino
Loading...
Searching...
No Matches
sensors.h
Go to the documentation of this file.
1#ifndef SENSORS_H
2#define SENSORS_H
3
4#include "timers.h"
5#include "config_pages.h"
6#include "statuses.h"
7#include "table2d.h"
8
9// The following are alpha values for the ADC filters.
10// Their values are from 0 to 240, with 0 being no filtering and 240 being maximum
11#define ADCFILTER_TPS_DEFAULT 50U
12#define ADCFILTER_CLT_DEFAULT 180U
13#define ADCFILTER_IAT_DEFAULT 180U
14#define ADCFILTER_O2_DEFAULT 128U
15#define ADCFILTER_BAT_DEFAULT 128U
16#define ADCFILTER_MAP_DEFAULT 20U //This is only used on Instantaneous MAP readings and is intentionally very weak to allow for faster response
17#define ADCFILTER_BARO_DEFAULT 64U
18
19#define ADCFILTER_PSI_DEFAULT 150U //not currently configurable at runtime, used for misc pressure sensors, oil, fuel, etc.
20
21#define FILTER_FLEX_DEFAULT 75U
22
23#define VSS_GEAR_HYSTERESIS 10U
24#define VSS_SAMPLES 4U //Must be a power of 2 and smaller than 255
25
26extern volatile uint8_t flexCounter;
27extern volatile uint32_t flexPulseWidth;
28
29#define BIT_SENSORS_UNUSED1 0
30#define BIT_SENSORS_BARO_SAVED 1
31#define BIT_SENSORS_UNUSED2 2
32#define BIT_SENSORS_UNUSED3 3
33#define BIT_SENSORS_UNUSED4 4
34#define BIT_SENSORS_UNUSED5 5
35#define BIT_SENSORS_UNUSED6 6
36#define BIT_SENSORS_UNUSED7 7
37
38void initialiseADC(void);
39void flexPulse(void);
41void knockPulse(void);
43void vssPulse(void);
44uint16_t readAnalogSensor(uint8_t pin);
45
47void initialiseTPS(void);
48
50void initialiseCLT(void);
51
52#define TPS_READ_FREQUENCY 30 //ONLY VALID VALUES ARE 15 or 30!!!
53
55#if TPS_READ_FREQUENCY==30
56#define TPS_READ_TIMER_BIT BIT_TIMER_30HZ
57#elif TPS_READ_FREQUENCY==15
58#define TPS_READ_TIMER_BIT BIT_TIMER_15HZ
59#else
60#error
61#endif
62
64#define CLT_READ_TIMER_BIT BIT_TIMER_4HZ
65
67#define IAT_READ_TIMER_BIT BIT_TIMER_4HZ
68
70#define O2_READ_TIMER_BIT BIT_TIMER_30HZ
71
73#define BAT_READ_TIMER_BIT BIT_TIMER_4HZ
74
76#define BARO_READ_TIMER_BIT BIT_TIMER_1HZ
77
79#define MAP_READ_TIMER_BIT BIT_TIMER_1KHZ
80
82void readPolledSensors(byte loopTimer);
83
85void initialiseMAPBaro(void);
86void resetMAPcycleAndEvent(void);
87
88uint8_t getAnalogKnock(void);
89
91int16_t getMAPDelta(void);
92
94uint32_t getMAPDeltaTime(void);
95
99
100#endif // SENSORS_H
The tune page structs and related defines.
const config2 & page2
Definition engineProtection.cpp:455
volatile unsigned int toothHistoryIndex
Current index to toothHistory array.
Definition globals.cpp:27
const config2 const config4 const config6 const config10 statuses & current
Definition scheduler_fuel_controller.cpp:913
void initialiseTPS(void)
Initial reading of the TPS sensor, primarily to detect flood clear state.
Definition sensors.cpp:554
uint16_t readAnalogSensor(uint8_t pin)
Definition sensors.cpp:143
void initialiseFlexSensor(config2 &page2, statuses &current, uint8_t pin)
Definition sensors.cpp:920
uint32_t vssGetPulseGap(byte toothHistoryIndex)
Returns the VSS pulse gap for a given history point.
Definition sensors.cpp:718
void initialiseMAPBaro(void)
Initialize the MAP calculation & Baro values.
Definition sensors.cpp:626
void vssPulse(void)
The ISR function for VSS pulses.
Definition sensors.cpp:953
uint32_t getMAPDeltaTime(void)
Get the time in µS between the last 2 MAP readings.
Definition sensors.cpp:512
int16_t getMAPDelta(void)
Get the MAP change between the last 2 readings.
Definition sensors.cpp:507
table2D_u16_u8_32 cltCalibrationTable
void readPolledSensors(byte loopTimer)
Read the sensors that are polled at every loop. This includes the TPS, MAP, CLT, IAT and O2 sensors.
void resetMAPcycleAndEvent(void)
Definition sensors.cpp:648
table2D_u16_u8_32 o2CalibrationTable
table2D_u16_u8_32 iatCalibrationTable
void flexPulse(void)
Definition sensors.cpp:906
uint8_t getAnalogKnock(void)
Definition sensors.cpp:888
void knockPulse(void)
Definition sensors.cpp:940
void initialiseADC(void)
Definition sensors.cpp:153
volatile uint8_t flexCounter
Definition sensors.cpp:37
volatile uint32_t flexPulseWidth
Definition sensors.cpp:39
void initialiseCLT(void)
Initial reading of the coolant sensor, primarily to make sure the priming pulsewidth is correct.
Definition sensors.cpp:564
The statuses struct and related defines.
Definition config_pages.h:179
The status struct with current values for all 'live' variables.
Definition statuses.h:131
A 2D table.
Definition table2d.h:137