Cleanup of aux PR and add init routing for these channels
This commit is contained in:
parent
57a5791a05
commit
0bbed9f316
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
|
||||||
// The following are alpha values for the ADC filters.
|
// 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
|
// Their values are from 0 to 255 with 0 being no filtering and 255 being maximum
|
||||||
#define ADCFILTER_TPS 128
|
#define ADCFILTER_TPS 128
|
||||||
|
@ -30,6 +29,7 @@ unsigned long MAPrunningValue; //Used for tracking either the total of all MAP r
|
||||||
unsigned long EMAPrunningValue; //As above but for EMAP
|
unsigned long EMAPrunningValue; //As above but for EMAP
|
||||||
unsigned int MAPcount; //Number of samples taken in the current MAP cycle
|
unsigned int MAPcount; //Number of samples taken in the current MAP cycle
|
||||||
uint32_t MAPcurRev; //Tracks which revolution we're sampling on
|
uint32_t MAPcurRev; //Tracks which revolution we're sampling on
|
||||||
|
bool auxIsEnabled;
|
||||||
|
|
||||||
//These variables are used for tracking the number of running sensors values that appear to be errors. Once a threshold is reached, the sensor reading will go to default value and assume the sensor is faulty
|
//These variables are used for tracking the number of running sensors values that appear to be errors. Once a threshold is reached, the sensor reading will go to default value and assume the sensor is faulty
|
||||||
byte mapErrorCount = 0;
|
byte mapErrorCount = 0;
|
||||||
|
|
|
@ -50,6 +50,31 @@ void initialiseADC()
|
||||||
MAPcurRev = 0;
|
MAPcurRev = 0;
|
||||||
MAPcount = 0;
|
MAPcount = 0;
|
||||||
MAPrunningValue = 0;
|
MAPrunningValue = 0;
|
||||||
|
|
||||||
|
//The following checks the aux inputs and initialises pins if required
|
||||||
|
auxIsEnabled = false;
|
||||||
|
for (byte AuxinChan = 0; AuxinChan <16 ; AuxinChan++)
|
||||||
|
{
|
||||||
|
currentStatus.current_caninchannel = AuxinChan;
|
||||||
|
//currentStatus.canin[14] = ((configPage9.Auxinpinb[currentStatus.current_caninchannel]&127)+1);
|
||||||
|
//currentStatus.canin[13] = (configPage9.caninput_sel[currentStatus.current_caninchannel]&3);
|
||||||
|
if ( (configPage9.caninput_sel[currentStatus.current_caninchannel] == 1) && (configPage9.enable_candata_in > 0) && (configPage9.enable_canbus == 1)) //if current input channel is enabled as canbus
|
||||||
|
{
|
||||||
|
auxIsEnabled = true;
|
||||||
|
}
|
||||||
|
else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 2) //if current input channel is enabled as analog local pin
|
||||||
|
{
|
||||||
|
//Channel is active and analog
|
||||||
|
pinMode( (configPage9.Auxinpina[currentStatus.current_caninchannel]&127), INPUT);
|
||||||
|
auxIsEnabled = true;
|
||||||
|
}
|
||||||
|
else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 3) //if current input channel is enabled as digital local pin
|
||||||
|
{
|
||||||
|
//Channel is active and digital
|
||||||
|
pinMode( (configPage9.Auxinpinb[currentStatus.current_caninchannel]&127), INPUT);
|
||||||
|
auxIsEnabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void instanteneousMAPReading()
|
static inline void instanteneousMAPReading()
|
||||||
|
|
|
@ -997,7 +997,8 @@ void loop()
|
||||||
|
|
||||||
if(eepromWritesPending == true) { writeAllConfig(); } //Check for any outstanding EEPROM writes.
|
if(eepromWritesPending == true) { writeAllConfig(); } //Check for any outstanding EEPROM writes.
|
||||||
|
|
||||||
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //ATmega2561 does not have Serial3
|
if(auxIsEnabled == true)
|
||||||
|
{
|
||||||
//check through the Aux input channels if enabed for Can or local use
|
//check through the Aux input channels if enabed for Can or local use
|
||||||
for (byte AuxinChan = 0; AuxinChan <16 ; AuxinChan++)
|
for (byte AuxinChan = 0; AuxinChan <16 ; AuxinChan++)
|
||||||
{
|
{
|
||||||
|
@ -1013,37 +1014,12 @@ void loop()
|
||||||
sendCancommand(2,0,currentStatus.current_caninchannel,0,((configPage9.caninput_source_can_address[currentStatus.current_caninchannel]&2047)+0x100));
|
sendCancommand(2,0,currentStatus.current_caninchannel,0,((configPage9.caninput_source_can_address[currentStatus.current_caninchannel]&2047)+0x100));
|
||||||
//send an R command for data from caninput_source_address[currentStatus.current_caninchannel]
|
//send an R command for data from caninput_source_address[currentStatus.current_caninchannel]
|
||||||
}
|
}
|
||||||
}
|
#if defined(CORE_STM32) || defined(CORE_TEENSY)
|
||||||
}
|
|
||||||
else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 2) //if current input channel is enabled as analog local pin
|
|
||||||
{
|
|
||||||
//read analog channel specified
|
|
||||||
currentStatus.canin[currentStatus.current_caninchannel] = readAuxanalog(configPage9.Auxinpina[currentStatus.current_caninchannel]&127);
|
|
||||||
}
|
|
||||||
else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 3) //if current input channel is enabled as digital local pin
|
|
||||||
{
|
|
||||||
//read digital channel specified
|
|
||||||
currentStatus.canin[currentStatus.current_caninchannel] = readAuxdigital((configPage9.Auxinpinb[currentStatus.current_caninchannel]&127)+1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(CORE_STM32) || defined(CORE_TEENSY)
|
|
||||||
//check through the Aux input channels if enabed for Can or local use
|
|
||||||
for (byte AuxinChan = 0; AuxinChan <16 ; AuxinChan++)
|
|
||||||
{
|
|
||||||
currentStatus.current_caninchannel = AuxinChan;
|
|
||||||
if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 1) //if current input channel is enabled as canbus
|
|
||||||
{
|
|
||||||
if (configPage9.enable_candata_in)
|
|
||||||
{
|
|
||||||
if (configPage9.enable_canbus == 1) //can via secondary serial
|
|
||||||
{
|
|
||||||
sendCancommand(2,0,currentStatus.current_caninchannel,0,((configPage9.caninput_source_can_address[currentStatus.current_caninchannel]&2047)+0x100)); //send an R command for data from paramgroup[currentStatus.current_caninchannel]
|
|
||||||
}
|
|
||||||
else if (configPage9.enable_canbus == 2) // can via internal can module
|
else if (configPage9.enable_canbus == 2) // can via internal can module
|
||||||
{
|
{
|
||||||
sendCancommand(3,configPage9.speeduino_tsCanId,currentStatus.current_caninchannel,0,configPage9.caninput_source_can_address[currentStatus.current_caninchannel]); //send via localcanbus the command for data from paramgroup[currentStatus.current_caninchannel]
|
sendCancommand(3,configPage9.speeduino_tsCanId,currentStatus.current_caninchannel,0,configPage9.caninput_source_can_address[currentStatus.current_caninchannel]); //send via localcanbus the command for data from paramgroup[currentStatus.current_caninchannel]
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 2) //if current input channel is enabled as analog local pin
|
else if ((configPage9.caninput_sel[currentStatus.current_caninchannel]&3) == 2) //if current input channel is enabled as analog local pin
|
||||||
|
@ -1055,9 +1031,10 @@ void loop()
|
||||||
{
|
{
|
||||||
//read digital channel specified
|
//read digital channel specified
|
||||||
currentStatus.canin[currentStatus.current_caninchannel] = readAuxdigital((configPage9.Auxinpinb[currentStatus.current_caninchannel]&127)+1);
|
currentStatus.canin[currentStatus.current_caninchannel] = readAuxdigital((configPage9.Auxinpinb[currentStatus.current_caninchannel]&127)+1);
|
||||||
}
|
} //Channel type
|
||||||
}
|
} //For loop going through each channel
|
||||||
#endif
|
} //aux channels are enabled
|
||||||
|
|
||||||
vvtControl();
|
vvtControl();
|
||||||
idleControl(); //Perform any idle related actions. Even at higher frequencies, running 4x per second is sufficient.
|
idleControl(); //Perform any idle related actions. Even at higher frequencies, running 4x per second is sufficient.
|
||||||
} //4Hz timer
|
} //4Hz timer
|
||||||
|
|
Loading…
Reference in New Issue