2016-06-24 01:02:53 -07:00
|
|
|
#ifndef SENSORS_H
|
|
|
|
#define SENSORS_H
|
|
|
|
|
2016-03-08 21:40:11 -08:00
|
|
|
// The following are alpha values for the ADC filters.
|
|
|
|
// Their values are from 0 to 255 with 0 being no filtering and 255 being maximum
|
|
|
|
#define ADCFILTER_TPS 128
|
|
|
|
#define ADCFILTER_CLT 180
|
|
|
|
#define ADCFILTER_IAT 180
|
|
|
|
#define ADCFILTER_O2 128
|
|
|
|
#define ADCFILTER_BAT 128
|
|
|
|
|
2016-10-25 16:30:12 -07:00
|
|
|
#define BARO_MIN 87
|
|
|
|
#define BARO_MAX 108
|
|
|
|
|
2016-11-20 21:45:21 -08:00
|
|
|
#if defined(CORE_AVR)
|
|
|
|
#define ANALOG_ISR
|
|
|
|
#endif
|
2016-06-24 01:02:53 -07:00
|
|
|
|
2016-11-17 17:57:11 -08:00
|
|
|
volatile byte flexCounter = 0;
|
|
|
|
volatile int AnChannel[15];
|
2016-11-06 05:31:18 -08:00
|
|
|
|
2016-03-08 21:40:11 -08:00
|
|
|
/*
|
|
|
|
* Simple low pass IIR filter macro for the analog inputs
|
|
|
|
* This is effectively implementing the smooth filter from http://playground.arduino.cc/Main/Smooth
|
|
|
|
* But removes the use of floats and uses 8 bits of fixed precision.
|
|
|
|
*/
|
|
|
|
#define ADC_FILTER(input, alpha, prior) (((long)input * (256 - alpha) + ((long)prior * alpha))) >> 8
|
|
|
|
|
|
|
|
void instanteneousMAPReading();
|
|
|
|
void readMAP();
|
2016-10-25 07:04:37 -07:00
|
|
|
void flexPulse();
|
2016-06-24 01:02:53 -07:00
|
|
|
|
2016-10-25 06:33:19 -07:00
|
|
|
unsigned int tempReading;
|
|
|
|
|
2016-11-06 05:31:18 -08:00
|
|
|
#if defined(ANALOG_ISR)
|
|
|
|
//Analog ISR interrupt routine
|
|
|
|
ISR(ADC_vect)
|
|
|
|
{
|
|
|
|
byte nChannel;
|
|
|
|
int result = ADCL | (ADCH << 8);
|
2016-11-17 17:57:11 -08:00
|
|
|
|
|
|
|
//ADCSRA = 0x6E; // ADC disabled by clearing bit 7(ADEN)
|
|
|
|
//BIT_CLEAR(ADCSRA, ADIE);
|
2016-11-06 05:31:18 -08:00
|
|
|
|
|
|
|
nChannel = ADMUX & 0x07;
|
|
|
|
#if defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__)
|
|
|
|
if (nChannel==7) { ADMUX = 0x40; }
|
|
|
|
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
2016-11-17 18:42:51 -08:00
|
|
|
if(ADCSRB & 0x08) { nChannel += 8; } //8 to 15
|
|
|
|
if(nChannel == 15)
|
2016-11-06 05:31:18 -08:00
|
|
|
{
|
|
|
|
ADMUX = 0x40; //channel 0
|
|
|
|
ADCSRB = 0x00; //clear MUX5 bit
|
|
|
|
}
|
2016-11-17 18:42:51 -08:00
|
|
|
else if (nChannel == 7) //channel 7
|
2016-11-06 05:31:18 -08:00
|
|
|
{
|
|
|
|
ADMUX = 0x40;
|
|
|
|
ADCSRB = 0x08; //Set MUX5 bit
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else { ADMUX++; }
|
2016-11-17 17:57:11 -08:00
|
|
|
AnChannel[nChannel-1] = result;
|
|
|
|
|
|
|
|
//BIT_SET(ADCSRA, ADIE);
|
|
|
|
//ADCSRA = 0xEE; // ADC Interrupt Flag enabled
|
2016-11-06 05:31:18 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-06-24 01:02:53 -07:00
|
|
|
#endif // SENSORS_H
|